Merge branch 'master' into master

This commit is contained in:
jhoneill
2018-10-24 17:27:23 +01:00
committed by GitHub
12 changed files with 171 additions and 112 deletions

View File

@@ -1,4 +1,8 @@
Function ConvertTo-ExcelXlsx {
<#
.SYNOPSIS
Converts an Excel xls to a xlsx using -ComObject
#>
[CmdletBinding()]
Param
(
@@ -7,8 +11,7 @@ Function ConvertTo-ExcelXlsx {
[parameter(Mandatory = $false)]
[switch]$Force
)
Process
{
Process {
if (-Not ($Path | Test-Path) ) {
throw "File not found"
}
@@ -28,18 +31,21 @@ Function ConvertTo-ExcelXlsx {
if ($Force) {
try {
Remove-Item $xlsxPath -Force
} catch {
}
catch {
throw "{0} already exists and cannot be removed. The file may be locked by another application." -f $xlsxPath
}
Write-Verbose $("Removed {0}" -f $xlsxPath)
} else {
}
else {
throw "{0} already exists!" -f $xlsxPath
}
}
try {
$Excel = New-Object -ComObject "Excel.Application"
} catch {
}
catch {
throw "Could not create Excel.Application ComObject. Please verify that Excel is installed."
}

View File

@@ -1,3 +1,7 @@
param(
[Switch]$DontCreateZip
)
##
# Used in Appveyor.yml
##
@@ -8,10 +12,12 @@ $PSVersionTable.PSVersion
## Otherwise the EPPlus.dll is in use after the Pester run
$ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | ForEach-Object ModuleVersion
if (!$DontCreateZip) {
$dest = "ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")
Compress-Archive -Path . -DestinationPath .\$dest
}
if ((Get-Module -ListAvailable pester) -eq $null) {
if ($null -eq (Get-Module -ListAvailable pester)) {
Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser
}

View File

@@ -15,7 +15,7 @@ Apple, New York, 1200,700
#Add a pivot table, specify its address to put it on the same sheet, use the data that was just exported set the table style and number format.
#Use the "City" for the row names, and "Product" for the columnnames, and sum both the gross and net values for each City/Product combination; add grand totals to rows and columns.
# activate the sheet and add a pivot chart (defined in a hash table)
Add-PivotTable -Address $excel.Sheet1.Cells["F1"] -SourceWorkSheet $Excel.Sheet1 -SourceRange $Excel.Sheet1.Dimension.Address -PivotTableName "Sales" -PivotTableSyle "Medium12" -PivotNumberFormat "$#,##0.00" `
Add-PivotTable -Address $excel.Sheet1.Cells["F1"] -SourceWorkSheet $Excel.Sheet1 -SourceRange $Excel.Sheet1.Dimension.Address -PivotTableName "Sales" -PivotTableStyle "Medium12" -PivotNumberFormat "$#,##0.00" `
-PivotRows "City" -PivotColumns "Product" -PivotData @{Gross="Sum";Net="Sum"}-PivotTotals "Both" -Activate -PivotChartDefinition @{
Title="Gross and net by city and product";
ChartType="ColumnClustered";

View File

@@ -402,7 +402,17 @@
.EXAMPLE
0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | Export-Excel -now -LineChart -AutoNameRange
Creates a line chart showing the value of Sine(x) for values of x between 0 and 360 degrees.
Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees.
.EXAMPLE
>
PS> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows |
Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables
Runs a query against a SQL Server database and outputs the resulting rows DataRows using the -OutputAs parameter.
The results are then piped to the Export-Excel function.
NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet.
.LINK
https://github.com/dfinke/ImportExcel
#>

View File

@@ -4,7 +4,7 @@
RootModule = 'ImportExcel.psm1'
# Version number of this module.
ModuleVersion = '5.3.2'
ModuleVersion = '5.3.4'
# ID used to uniquely identify this module
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'

View File

@@ -63,7 +63,7 @@ function Import-Excel {
.DESCRIPTION
The Import-Excel cmdlet creates custom objects from the rows in an Excel worksheet. Each row represents one object. All of this is possible without installing Microsoft Excel and by using the .NET library EPPLus.dll.
By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blanc property name, only columns with column headers will be imported.
By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blank property name, only columns with column headers will be imported.
If the default behavior is not desired and you want to import the complete worksheet as is, the parameter -NoHeader can be used. In case you want to provide your own property names, you can use the parameter -HeaderName.
@@ -241,6 +241,16 @@ function Import-Excel {
Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with Chuck Norris has not been imported, because we started the import from row 2 with the parameter -StartRow 2.
.EXAMPLE
>
PS> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) |
Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force
Imports data from an Excel file and pipe the data to the Write-SqlTableData to be INSERTed into a table in a SQL Server database.
The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows.
The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in.
NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet.
.LINK
https://github.com/dfinke/ImportExcel

View File

@@ -29,7 +29,7 @@
Add-PivotTable -PivotTableName Sales -Address $excel.Workbook.Worksheets[1].Cells["F1"] `
-SourceWorkSheet $excel.Workbook.Worksheets[1] -PivotRows City -PivotColumns Product -PivotData @{Gross="Sum";Net="Sum"} `
-PivotNumberFormat "$#,##0.00" -PivotTotals Both -PivotTableSyle Medium12 -PivotChartDefinition $chartdef
-PivotNumberFormat "$#,##0.00" -PivotTotals Both -PivotTableStyle Medium12 -PivotChartDefinition $chartdef
Close-ExcelPackage -show $excel
@@ -74,7 +74,7 @@
#Number format to apply to the data cells in the PivotTable.
[string]$PivotNumberFormat,
#Apply a table style to the PivotTable.
[OfficeOpenXml.Table.TableStyles]$PivotTableSyle,
[OfficeOpenXml.Table.TableStyles]$PivotTableStyle,
#Use a chart definition instead of specifying chart settings one by one.
[Parameter(ParameterSetName='ChartbyDef', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
$PivotChartDefinition,
@@ -198,7 +198,7 @@
if ($PivotTotals -eq "None" -or $PivotTotals -eq "Rows") { $pivotTable.ColumGrandTotals = $false } # Epplus spelling mistake, not mine!
elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Columns") { $pivotTable.ColumGrandTotals = $true }
if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false }
if ($PivotTableSyle) { $pivotTable.TableStyle = $PivotTableSyle}
if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle}
}
catch {Write-Warning -Message "Failed adding PivotTable '$pivotTableName': $_"}
}
@@ -274,7 +274,7 @@ function New-PivotTableDefinition {
#Number format to apply to the data cells in the PivotTable
[string]$PivotNumberFormat,
#Apply a table style to the PivotTable
[OfficeOpenXml.Table.TableStyles]$PivotTableSyle,
[OfficeOpenXml.Table.TableStyles]$PivotTableStyle,
#Use a chart definition instead of specifying chart settings one by one
[Parameter(ParameterSetName='ChartbyDef', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
$PivotChartDefinition,

View File

@@ -53,17 +53,27 @@ Install-Module ImportExcel -scope CurrentUser
Install-Module ImportExcel
```
# What's new
# What's new 5.3.4
- HotFix for parameter PivotTableSyle should be PivotTableStyle https://github.com/dfinke/ImportExcel/issues/453
# What's new 5.3.3
- Thank you to (lazywinadmin)[https://github.com/lazywinadmin] - Expand aliases in examples and elsewhere
- In Export-Excel fixed a bug where -AutoNameRange on pre-existing data included the header in the range.
- In Export-Excel fixed a bug which caused a zero, null, or empty string in a list of simple objects to be skipped.
- In Export-Excel improved the behaviour when a new worksheet is created without data, and Tables etc are added to it.
- In Join-Worksheet: added argument completer to -TitleBackgroundColor and set default for -TitleBackgroundStyle to 'Solid'.
- In Add-Excel chart fixed mis-spelling of "Position"
- In Add-Excel chart, New-ExcelChart, tests and Examples fixed mis-spelling of "Position"
- In Send-SqlDataToExcel: improved robustness of check for no data returned.
- In Set-ExcelColumn: -column can come from the pipeline (supporting an array introduces complications for supporting script blocks); -AutoNameRange no longer requires heading to specified (so you can do 1..10 | Set-ExcelColumn -AutoNameRange ); In Set-ExcelRow: -Row can come from the pipeline
- Improved test coverage (back over 80%).
- Help and example improvements. In "Index - music.ps1" the module for querying the index can be downloaded from PowerShell gallery #requires set to demand it. In SQL+FillColumns+Pivot\example2.ps1 the GetSQL module can be downloaded and #Requires has been set. The F1 results spreadsheet is available from one drive and a link is provided.
- Added Azure DevOps continuous integration and badges <a href="https://dougfinke.visualstudio.com/ImportExcel/_build?definitionId=10"><img src="https://dougfinke.visualstudio.com/ImportExcel/_apis/build/status/ImportExcel-CI?branchName=master"></a>
# What's new in Release 5.3
- Help improvements and tidying up of examples and extra examples

View File

@@ -10,8 +10,10 @@ Banana, London , 300, 200
Orange, Paris, 600, 500
Banana, Paris, 300, 200
Apple, New York, 1200,700
"@ | Export-Excel -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor=([System.Drawing.Color]::Green)} -ExcelChartDefinition @{ChartType="Doughnut";XRange="A2:B7"; YRange="C2:C7"; width=800; } -PivotTableDefinition @{Sales=@{
PivotRows="City"; PivotColumns="Product"; PivotData=@{Gross="Sum";Net="Sum"}; PivotNumberFormat="$#,##0.00"; PivotTotals="Both"; PivotTableSyle="Medium12"; Activate=$true
"@ | Export-Excel -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor="Green"} -ExcelChartDefinition @{ChartType="Doughnut";XRange="A2:B7"; YRange="C2:C7"; width=800; } -PivotTableDefinition @{Sales=@{
PivotRows="City"; PivotColumns="Product"; PivotData=@{Gross="Sum";Net="Sum"}; PivotNumberFormat="$#,##0.00"; PivotTotals="Both"; PivotTableStyle="Medium12"; Activate=$true
PivotChartDefinition=@{Title="Gross and net by city and product"; ChartType="ColumnClustered"; Column=6; Width=600; Height=360; YMajorUnit=500; YMinorUnit=100; YAxisNumberformat="$#,##0"; LegendPosition="Bottom"}}}
$excel = Open-ExcelPackage $path

View File

@@ -328,7 +328,7 @@ Describe "Table Formatting" {
#test expnading named number formats
Set-ExcelColumn -Worksheet $ws -Column 4 -NumberFormat 'Currency'
Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency'
$PtDef =New-PivotTableDefinition -PivotTableName Totals -PivotRows Product -PivotData @{"Total"="Sum"} -PivotNumberFormat Currency -PivotTotals None -PivotTableSyle Dark2
$PtDef =New-PivotTableDefinition -PivotTableName Totals -PivotRows Product -PivotData @{"Total"="Sum"} -PivotNumberFormat Currency -PivotTotals None -PivotTableStyle Dark2
Export-excel -ExcelPackage $excel -WorksheetName Hardware -PivotTableDefinition $PtDef
$excel= Open-ExcelPackage -Path $path
$ws1 = $excel.Workbook.Worksheets["Hardware"]

Binary file not shown.

15
azure-pipelines.yml Normal file
View File

@@ -0,0 +1,15 @@
resources:
- repo: self
queue:
name: Hosted VS2017
steps:
- powershell: ./ '.\DoTests.ps1'
displayName: 'PowerShell Script'
- task: ArchiveFiles@2
displayName: 'Archive $(Build.BinariesDirectory)'
trigger:
paths:
exclude:
- README.md