mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 15:53:32 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58ab93a6eb | ||
|
|
94d86927ba | ||
|
|
d31a262f37 | ||
|
|
2e8c69ea6b | ||
|
|
9261b49b56 | ||
|
|
bc80134560 | ||
|
|
6dfa5b1aac | ||
|
|
6f921e1a3d | ||
|
|
feb5868952 | ||
|
|
f48e4ad26c | ||
|
|
33d86cb3c9 | ||
|
|
4753568a39 | ||
|
|
af31bab499 | ||
|
|
3d76bec6c4 | ||
|
|
5dd73789a3 | ||
|
|
85a78dad7e | ||
|
|
13652bc4ed | ||
|
|
0540d221e0 | ||
|
|
243ba0bb3c | ||
|
|
b5177de50d | ||
|
|
695c986b78 | ||
|
|
c6dc928e11 | ||
|
|
066ab8f348 | ||
|
|
7dad54f6e9 | ||
|
|
81fc0742f0 | ||
|
|
f33afef2f0 | ||
|
|
97275a99de | ||
|
|
9e01d7fc0b | ||
|
|
593c586a24 | ||
|
|
4b23d8193b | ||
|
|
4408a04619 |
@@ -1,4 +1,93 @@
|
||||
function ConvertFrom-ExcelToSQLInsert {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generate SQL insert statements from Excel spreadsheet.
|
||||
|
||||
.DESCRIPTION
|
||||
Generate SQL insert statements from Excel spreadsheet.
|
||||
|
||||
.PARAMETER TableName
|
||||
Name of the target database table.
|
||||
|
||||
.PARAMETER Path
|
||||
Path to an existing .XLSX file
|
||||
|
||||
This parameter is passed to Import-Excel as is.
|
||||
|
||||
.PARAMETER WorkSheetname
|
||||
Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported.
|
||||
|
||||
This parameter is passed to Import-Excel as is.
|
||||
|
||||
.PARAMETER StartRow
|
||||
The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row.
|
||||
|
||||
When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data.
|
||||
|
||||
.PARAMETER Header
|
||||
Specifies custom property names to use, instead of the values defined in the column headers of the TopRow.
|
||||
|
||||
In case you provide less header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded.
|
||||
|
||||
In case you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blanc as there is no data for them.
|
||||
|
||||
.PARAMETER NoHeader
|
||||
Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow.
|
||||
|
||||
This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names.
|
||||
|
||||
.PARAMETER DataOnly
|
||||
Import only rows and columns that contain data, empty rows and empty columns are not imported.
|
||||
|
||||
|
||||
.PARAMETER ConvertEmptyStringsToNull
|
||||
If specified, cells without any data are replaced with NULL, instead of an empty string.
|
||||
|
||||
This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value.
|
||||
|
||||
.EXAMPLE
|
||||
Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings:
|
||||
|
||||
----------------------------------------------------------
|
||||
| File: Movies.xlsx - Sheet: Sheet1 |
|
||||
----------------------------------------------------------
|
||||
| A B C |
|
||||
|1 Movie Name Year Rating |
|
||||
|2 The Bodyguard 1992 9 |
|
||||
|3 The Matrix 1999 8 |
|
||||
|4 Skyfall 2012 9 |
|
||||
|5 The Avengers 2012 |
|
||||
----------------------------------------------------------
|
||||
|
||||
PS C:\> Import-Excel -TableName "Movies" -Path 'C:\Movies.xlsx'
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', '');
|
||||
|
||||
.EXAMPLE
|
||||
Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string.
|
||||
|
||||
----------------------------------------------------------
|
||||
| File: Movies.xlsx - Sheet: Sheet1 |
|
||||
----------------------------------------------------------
|
||||
| A B C |
|
||||
|1 Movie Name Year Rating |
|
||||
|2 The Bodyguard 1992 9 |
|
||||
|3 The Matrix 1999 8 |
|
||||
|4 Skyfall 2012 9 |
|
||||
|5 The Avengers 2012 |
|
||||
----------------------------------------------------------
|
||||
|
||||
PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path "C:\Movies.xlsx" -ConvertEmptyStringsToNull
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL);
|
||||
|
||||
.NOTES
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
$TableName,
|
||||
@@ -8,39 +97,34 @@ function ConvertFrom-ExcelToSQLInsert {
|
||||
$Path,
|
||||
[Alias("Sheet")]
|
||||
$WorkSheetname = 1,
|
||||
[int]$HeaderRow = 1,
|
||||
[Alias('HeaderRow', 'TopRow')]
|
||||
[ValidateRange(1, 9999)]
|
||||
[Int]$StartRow,
|
||||
[string[]]$Header,
|
||||
[switch]$NoHeader,
|
||||
[switch]$DataOnly
|
||||
[switch]$DataOnly,
|
||||
[switch]$ConvertEmptyStringsToNull
|
||||
)
|
||||
|
||||
$null = $PSBoundParameters.Remove('TableName')
|
||||
$null = $PSBoundParameters.Remove('ConvertEmptyStringsToNull')
|
||||
|
||||
$params = @{} + $PSBoundParameters
|
||||
|
||||
ConvertFrom-ExcelData @params {
|
||||
param($propertyNames, $record)
|
||||
|
||||
$ColumnNames = "'" + ($PropertyNames -join "', '") + "'"
|
||||
$values = foreach ($propertyName in $PropertyNames) { $record.$propertyName }
|
||||
$targetValues = "'" + ($values -join "', '") + "'"
|
||||
$values = foreach ($propertyName in $PropertyNames) {
|
||||
if ($ConvertEmptyStringsToNull.IsPresent -and [string]::IsNullOrEmpty($record.$propertyName)) {
|
||||
'NULL'
|
||||
}
|
||||
else {
|
||||
"'" + $record.$propertyName + "'"
|
||||
}
|
||||
}
|
||||
$targetValues = ($values -join ", ")
|
||||
|
||||
"INSERT INTO {0} ({1}) Values({2});" -f $TableName, $ColumnNames, $targetValues
|
||||
}
|
||||
# $data = Import-Excel @params
|
||||
|
||||
# $PropertyNames = $data[0].psobject.Properties |
|
||||
# Where-Object {$_.membertype -match 'property'} |
|
||||
# Select-Object -ExpandProperty name
|
||||
|
||||
# $ColumnNames = "'" + ($PropertyNames -join "', '") + "'"
|
||||
|
||||
# foreach ($record in $data) {
|
||||
# $values = $(foreach ($propertyName in $PropertyNames) {
|
||||
# $record.$propertyName
|
||||
# })
|
||||
|
||||
# $targetValues = "'" + ($values -join "', '") + "'"
|
||||
|
||||
# "INSERT INTO {0} ({1}) Values({2});" -f $TableName, $ColumnNames, $targetValues
|
||||
# }
|
||||
}
|
||||
34
ConvertFromExcelToSQLInsert.tests.ps1
Normal file
34
ConvertFromExcelToSQLInsert.tests.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
Import-Module .\ImportExcel.psd1 -Force
|
||||
|
||||
$xlFile = ".\testSQL.xlsx"
|
||||
|
||||
Describe "ConvertFrom-ExcelToSQLInsert" {
|
||||
|
||||
BeforeEach {
|
||||
|
||||
$([PSCustomObject]@{
|
||||
Name="John"
|
||||
Age=$null
|
||||
}) | Export-Excel $xlFile
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
Remove-Item $xlFile -Recurse -Force -ErrorAction Ignore
|
||||
}
|
||||
|
||||
It "Should be empty double single quotes" {
|
||||
$expected="INSERT INTO Sheet1 ('Name', 'Age') Values('John', '');"
|
||||
|
||||
$actual = ConvertFrom-ExcelToSQLInsert -Path $xlFile Sheet1
|
||||
|
||||
$actual | should be $expected
|
||||
}
|
||||
|
||||
It "Should have NULL" {
|
||||
$expected="INSERT INTO Sheet1 ('Name', 'Age') Values('John', NULL);"
|
||||
|
||||
$actual = ConvertFrom-ExcelToSQLInsert -Path $xlFile Sheet1 -ConvertEmptyStringsToNull
|
||||
|
||||
$actual | should be $expected
|
||||
}
|
||||
}
|
||||
72
Examples/CustomReporting/CustomReport.ps1
Normal file
72
Examples/CustomReporting/CustomReport.ps1
Normal file
@@ -0,0 +1,72 @@
|
||||
Import-Module ..\..\ImportExcel.psd1 -Force
|
||||
|
||||
$f = ".\dashboard.xlsx"
|
||||
Remove-Item $f -ErrorAction Ignore
|
||||
|
||||
$data = @"
|
||||
From,To,RDollars,RPercent,MDollars,MPercent,Revenue,Margin
|
||||
Atlanta,New York,3602000,.0809,955000,.09,245,65
|
||||
New York,Washington,4674000,.105,336000,.03,222,16
|
||||
Chicago,New York,4674000,.0804,1536000,.14,550,43
|
||||
New York,Philadelphia,12180000,.1427,-716000,-.07,321,-25
|
||||
New York,San Francisco,3221000,.0629,1088000,.04,436,21
|
||||
New York,Phoneix,2782000,.0723,467000,.10,674,33
|
||||
"@ | ConvertFrom-Csv
|
||||
|
||||
$data | Export-Excel $f -AutoSize
|
||||
|
||||
$excel = Open-ExcelPackage $f
|
||||
|
||||
$sheet1 = $excel.Workbook.Worksheets["sheet1"]
|
||||
|
||||
$sheet1.View.ShowGridLines = $false
|
||||
$sheet1.View.ShowHeaders = $false
|
||||
|
||||
Set-Format -Address $sheet1.Cells["C:C"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
|
||||
Set-Format -Address $sheet1.Cells["D:D"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
|
||||
|
||||
Set-Format -Address $sheet1.Cells["E:E"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
|
||||
Set-Format -Address $sheet1.Cells["F:F"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
|
||||
|
||||
Set-Format -Address $sheet1.Cells["G:H"] -WrapText -HorizontalAlignment Center
|
||||
|
||||
## Insert Rows/Columns
|
||||
$sheet1.InsertRow(1, 1)
|
||||
|
||||
foreach ($col in Write-Output 2 4 6 8 10 12 14) {
|
||||
$sheet1.InsertColumn($col, 1)
|
||||
$sheet1.Column($col).width = .75
|
||||
}
|
||||
|
||||
Set-Format -Address $sheet1.Cells["E:E"] -Width 12
|
||||
Set-Format -Address $sheet1.Cells["I:I"] -Width 12
|
||||
|
||||
$BorderBottom = "Thick"
|
||||
$BorderColor = "LightBlue"
|
||||
|
||||
Set-Format -Address $sheet1.Cells["A2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
|
||||
|
||||
Set-Format -Address $sheet1.Cells["C2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
|
||||
Set-Format -Address $sheet1.Cells["E2:G2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
|
||||
Set-Format -Address $sheet1.Cells["I2:K2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
|
||||
Set-Format -Address $sheet1.Cells["M2:O2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
|
||||
|
||||
Set-Format -Address $sheet1.Cells["A2:C8"] -FontColor GrayText
|
||||
|
||||
$HorizontalAlignment = "Center"
|
||||
Set-Format -Address $sheet1.Cells["F1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Revenue
|
||||
Set-Format -Address $sheet1.Cells["J1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Margin
|
||||
Set-Format -Address $sheet1.Cells["N1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Passenger
|
||||
|
||||
Set-Format -Address $sheet1.Cells["E2"] -Value '($)'
|
||||
Set-Format -Address $sheet1.Cells["G2"] -Value '%'
|
||||
Set-Format -Address $sheet1.Cells["I2"] -Value '($)'
|
||||
Set-Format -Address $sheet1.Cells["K2"] -Value '%'
|
||||
|
||||
Set-Format -Address $sheet1.Cells["C10"] -HorizontalAlignment Right -Bold -Value "Grand Total Calculation"
|
||||
Set-Format -Address $sheet1.Cells["E10"] -Formula "=Sum(E3:E8)" -Bold
|
||||
Set-Format -Address $sheet1.Cells["I10"] -Formula "=Sum(I3:I8)" -Bold
|
||||
Set-Format -Address $sheet1.Cells["M10"] -Formula "=Sum(M3:M8)" -Bold
|
||||
Set-Format -Address $sheet1.Cells["O10"] -Formula "=Sum(O3:O8)" -Bold
|
||||
|
||||
Close-ExcelPackage $excel -Show
|
||||
22
Examples/PivotTableFilters/testPivotFilter.ps1
Normal file
22
Examples/PivotTableFilters/testPivotFilter.ps1
Normal file
@@ -0,0 +1,22 @@
|
||||
Import-Module ..\..\ImportExcel.psd1 -Force
|
||||
|
||||
$xlFile=".\testPivot.xlsx"
|
||||
Remove-Item $xlFile -ErrorAction Ignore
|
||||
|
||||
|
||||
$data =@"
|
||||
Region,Area,Product,Units,Cost
|
||||
North,A1,Apple,100,.5
|
||||
South,A2,Pear,120,1.5
|
||||
East,A3,Grape,140,2.5
|
||||
West,A4,Banana,160,3.5
|
||||
North,A1,Pear,120,1.5
|
||||
North,A1,Grape,140,2.5
|
||||
"@ | ConvertFrom-Csv
|
||||
|
||||
$data |
|
||||
Export-Excel $xlFile -Show `
|
||||
-AutoSize -AutoFilter `
|
||||
-IncludePivotTable `
|
||||
-PivotRows Product `
|
||||
-PivotData @{"Units"="sum"} -PivotFilter Region, Area
|
||||
@@ -1,6 +1,6 @@
|
||||
# To ship, is to choose
|
||||
|
||||
ipmo .\ImportExcel.psd1 -Force
|
||||
#ipmo .\ImportExcel.psd1 -Force
|
||||
|
||||
$pt=[ordered]@{}
|
||||
|
||||
|
||||
@@ -342,6 +342,7 @@
|
||||
[String[]]$PivotRows,
|
||||
[String[]]$PivotColumns,
|
||||
$PivotData,
|
||||
[String[]]$PivotFilter,
|
||||
[Switch]$PivotDataToColumn,
|
||||
[Hashtable]$PivotTableDefinition,
|
||||
[Switch]$IncludePivotChart,
|
||||
@@ -399,7 +400,8 @@
|
||||
# [Parameter(ParameterSetName = 'TableNow')]
|
||||
[Switch]$Now,
|
||||
[Switch]$ReturnRange,
|
||||
[Switch]$NoTotalsInPivot
|
||||
[Switch]$NoTotalsInPivot,
|
||||
[Switch]$ReZip
|
||||
)
|
||||
|
||||
Begin {
|
||||
@@ -712,6 +714,9 @@
|
||||
$tbl.TableStyle = $TableStyle
|
||||
}
|
||||
|
||||
$PivotTableStartCell = "A1"
|
||||
if($PivotFilter) {$PivotTableStartCell = "A3"}
|
||||
|
||||
if ($PivotTableDefinition) {
|
||||
foreach ($item in $PivotTableDefinition.GetEnumerator()) {
|
||||
$targetName = $item.Key
|
||||
@@ -722,7 +727,7 @@
|
||||
$pivotTableDataName = $targetName + 'PivotTableData'
|
||||
|
||||
if (!$item.Value.SourceWorkSheet) {
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells['A1'], $ws.Cells[$dataRange], $pivotTableDataName)
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells[$PivotTableStartCell], $ws.Cells[$dataRange], $pivotTableDataName)
|
||||
}
|
||||
else {
|
||||
$workSheet = Find-WorkSheet $item.Value.SourceWorkSheet
|
||||
@@ -731,7 +736,7 @@
|
||||
$targetStartAddress = $workSheet.Dimension.Start.Address
|
||||
$targetDataRange = "{0}:{1}" -f $targetStartAddress, $workSheet.Dimension.End.Address
|
||||
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells['A1'], $workSheet.Cells[$targetDataRange], $pivotTableDataName)
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells[$PivotTableStartCell], $workSheet.Cells[$targetDataRange], $pivotTableDataName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,7 +808,7 @@
|
||||
|
||||
$pivotTableDataName = $WorkSheetname + 'PivotTableData'
|
||||
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells['A1'], $ws.Cells[$dataRange], $pivotTableDataName)
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells[$PivotTableStartCell], $ws.Cells[$dataRange], $pivotTableDataName)
|
||||
|
||||
if ($PivotRows) {
|
||||
foreach ($Row in $PivotRows) {
|
||||
@@ -843,7 +848,7 @@
|
||||
$chart = $wsPivot.Drawings.AddChart('PivotChart', $ChartType, $pivotTable)
|
||||
if ($chart.DataLabel) {
|
||||
$chart.DataLabel.ShowCategory = $ShowCategory
|
||||
$chart.DataLabel.ShowPercent = $ShowPercent
|
||||
$chart.DataLabel.ShowPercent = $ShowPercent
|
||||
}
|
||||
$chart.SetPosition(0, 26, 2, 26) # if Pivot table is rows+data only it will be 2 columns wide if has pivot columns we don't know how wide it will be
|
||||
if ($NoLegend) {
|
||||
@@ -853,6 +858,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
if($pivotTable -and $PivotFilter) {
|
||||
|
||||
foreach($pFilter in $PivotFilter) {
|
||||
$null = $pivotTable.PageFields.Add($pivotTable.Fields[$pFilter])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($Password) {
|
||||
$ws.Protection.SetPassword($Password)
|
||||
}
|
||||
@@ -988,7 +1001,26 @@
|
||||
$ws.Dimension.Address
|
||||
}
|
||||
|
||||
|
||||
|
||||
$pkg.Save()
|
||||
|
||||
if ($ReZip) {
|
||||
write-verbose "Re-Zipping $($pkg.file) using .NET ZIP library"
|
||||
$zipAssembly = "System.IO.Compression.Filesystem"
|
||||
try {
|
||||
Add-Type -assembly $zipAssembly -ErrorAction stop
|
||||
} catch {
|
||||
write-error "The -ReZip parameter requires .NET Framework 4.5 or later to be installed. Recommend to install Powershell v4+"
|
||||
continue
|
||||
}
|
||||
|
||||
$TempZipPath = Join-Path -path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName())
|
||||
[io.compression.zipfile]::ExtractToDirectory($pkg.File,$TempZipPath) | Out-Null
|
||||
Remove-Item $pkg.File -Force
|
||||
[io.compression.zipfile]::CreateFromDirectory($TempZipPath,$pkg.File) | Out-Null
|
||||
}
|
||||
|
||||
$pkg.Dispose()
|
||||
|
||||
if ($Show) {
|
||||
|
||||
@@ -2071,3 +2071,14 @@ Context 'special cases' {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context 'General Tests' {
|
||||
in $TestDrive {
|
||||
Describe 'Get Help' {
|
||||
it 'New-Plot' {
|
||||
#Get-Help : Unable to find type [PSPlot].
|
||||
{Help New-Plot} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
RootModule = 'ImportExcel.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '4.0.10'
|
||||
ModuleVersion = '4.0.13'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||
|
||||
@@ -39,7 +39,6 @@ if ($PSVersionTable.PSVersion.Major -ge 5) {
|
||||
. $PSScriptRoot\Plot.ps1
|
||||
|
||||
Function New-Plot {
|
||||
[OutputType([PSPlot])]
|
||||
Param()
|
||||
|
||||
[PSPlot]::new()
|
||||
|
||||
12
Install.ps1
12
Install.ps1
@@ -20,14 +20,19 @@ Begin {
|
||||
Write-Verbose "$ModuleName module installation started"
|
||||
|
||||
$Files = @(
|
||||
'AddConditionalFormatting.ps1',
|
||||
'Charting.ps1',
|
||||
'ColorCompletion.ps1',
|
||||
'ConvertFromExcelData.ps1',
|
||||
'ConvertFromExcelToSQLInsert.ps1',
|
||||
'ConvertExcelToImageFile.ps1',
|
||||
'ConvertToExcelXlsx.ps1',
|
||||
'Copy-ExcelWorkSheet.ps1',
|
||||
'EPPlus.dll',
|
||||
'Export-charts.ps1',
|
||||
'Export-Excel.ps1',
|
||||
'Export-ExcelSheet.ps1',
|
||||
'formatting.ps1',
|
||||
'Get-ExcelColumnName.ps1',
|
||||
'Get-ExcelSheetInfo.ps1',
|
||||
'Get-ExcelWorkbookInfo.ps1',
|
||||
@@ -43,9 +48,14 @@ Begin {
|
||||
'New-ConditionalText.ps1',
|
||||
'New-ExcelChart.ps1',
|
||||
'New-PSItem.ps1',
|
||||
'Open-ExcelPackage.ps1',
|
||||
'Pivot.ps1',
|
||||
'Plot.ps1',
|
||||
'plot.ps1',
|
||||
'Send-SqlDataToExcel.ps1',
|
||||
'Set-CellStyle.ps1',
|
||||
'Set-Column.ps1',
|
||||
'Set-Row.ps1',
|
||||
'SetFormat.ps1',
|
||||
'TrackingUtils.ps1',
|
||||
'Update-FirstObjectProperties.ps1'
|
||||
)
|
||||
|
||||
52
README.md
52
README.md
@@ -31,6 +31,58 @@ iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfi
|
||||
|
||||
# What's new
|
||||
|
||||
#### 4/22/2018
|
||||
Thanks to the community yet again
|
||||
- [ili101](https://github.com/ili101) for fixes and features
|
||||
- Removed `[PSPlot]` as OutputType. Fixes it throwing an error
|
||||
- [Nasir Zubair](https://github.com/nzubair) added `ConvertEmptyStringsToNull` to the function `ConvertFrom-ExcelToSQLInsert`
|
||||
- If specified, cells without any data are replaced with NULL, instead of an empty string. This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value.
|
||||
|
||||
|
||||
#### 4/10/2018
|
||||
-New parameter `-ReZip`. It ReZips the xlsx so it can be imported to PowerBI
|
||||
|
||||
Thanks to [Justin Grote](https://github.com/JustinGrote) for finding and fixing the error that Excel files created do not import to PowerBI online. Plus, thank you to [CrashM](https://github.com/CrashM) for confirming the fix.
|
||||
|
||||
Super helpful!
|
||||
|
||||
#### 3/31/2018
|
||||
- Updated `Set-Format`
|
||||
* Added parameters to set borders for cells, including top, bottm, left and right
|
||||
* Added parameters to set `value` and `formula`
|
||||
|
||||
```powershell
|
||||
$data = @"
|
||||
From,To,RDollars,RPercent,MDollars,MPercent,Revenue,Margin
|
||||
Atlanta,New York,3602000,.0809,955000,.09,245,65
|
||||
New York,Washington,4674000,.105,336000,.03,222,16
|
||||
Chicago,New York,4674000,.0804,1536000,.14,550,43
|
||||
New York,Philadelphia,12180000,.1427,-716000,-.07,321,-25
|
||||
New York,San Francisco,3221000,.0629,1088000,.04,436,21
|
||||
New York,Phoneix,2782000,.0723,467000,.10,674,33
|
||||
"@
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
- Added `-PivotFilter` parameter, allows you to set up a filter so you can drill down into a subset of the overall dataset.
|
||||
|
||||
```powershell
|
||||
$data =@"
|
||||
Region,Area,Product,Units,Cost
|
||||
North,A1,Apple,100,.5
|
||||
South,A2,Pear,120,1.5
|
||||
East,A3,Grape,140,2.5
|
||||
West,A4,Banana,160,3.5
|
||||
North,A1,Pear,120,1.5
|
||||
North,A1,Grape,140,2.5
|
||||
"@
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
#### 3/14/2018
|
||||
- Thank you to [James O'Neill](https://twitter.com/jamesoneill), fixed bugs with ChangeDatabase parameter which would prevent it working
|
||||
|
||||
|
||||
@@ -25,8 +25,17 @@
|
||||
$NumberFormat,
|
||||
#Style of border to draw around the range
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround,
|
||||
[System.Drawing.Color]$BorderColor=[System.Drawing.Color]::Black,
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom,
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop,
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft,
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight,
|
||||
#Colour for the text - if none specified it will be left as it it is
|
||||
[System.Drawing.Color]$FontColor,
|
||||
#Value for the cell
|
||||
$Value,
|
||||
#Formula for the cell
|
||||
$Formula,
|
||||
#Clear Bold, Italic, StrikeThrough and Underline and set colour to black
|
||||
[switch]$ResetFont,
|
||||
#Make text bold
|
||||
@@ -98,7 +107,31 @@
|
||||
if ($StrikeThru) {$Address.Style.Font.Strike = $true }
|
||||
if ($FontShift) {$Address.Style.Font.VerticalAlign = $FontShift }
|
||||
if ($FontColor) {$Address.Style.Font.Color.SetColor( $FontColor ) }
|
||||
if ($BorderAround) {$Address.Style.Border.BorderAround( $BorderAround ) }
|
||||
|
||||
if ($BorderAround) {
|
||||
$Address.Style.Border.BorderAround($BorderAround, $BorderColor)
|
||||
}
|
||||
|
||||
if ($BorderBottom) {
|
||||
$Address.Style.Border.Bottom.Style=$BorderBottom
|
||||
$Address.Style.Border.Bottom.Color.SetColor($BorderColor)
|
||||
}
|
||||
|
||||
if ($BorderTop) {
|
||||
$Address.Style.Border.Top.Style=$BorderTop
|
||||
$Address.Style.Border.Top.Color.SetColor($BorderColor)
|
||||
}
|
||||
|
||||
if ($BorderLeft) {
|
||||
$Address.Style.Border.Left.Style=$BorderLeft
|
||||
$Address.Style.Border.Left.Color.SetColor($BorderColor)
|
||||
}
|
||||
|
||||
if ($BorderRight) {
|
||||
$Address.Style.Border.Right.Style=$BorderRight
|
||||
$Address.Style.Border.Right.Color.SetColor($BorderColor)
|
||||
}
|
||||
|
||||
if ($NumberFormat) {$Address.Style.Numberformat.Format = $NumberFormat }
|
||||
if ($TextRotation) {$Address.Style.TextRotation = $TextRotation }
|
||||
if ($WrapText) {$Address.Style.WrapText = $true }
|
||||
@@ -123,15 +156,20 @@
|
||||
}
|
||||
if ($Autosize) {
|
||||
if ($Address -is [OfficeOpenXml.ExcelColumn]) {$Address.AutoFit() }
|
||||
elseif ($Address -is [OfficeOpenXml.ExcelRange] ) {$Address.AutoFitColumns() }
|
||||
elseif ($Address -is [OfficeOpenXml.ExcelRange] ) {
|
||||
$Address.AutoFitColumns()
|
||||
}
|
||||
else {Write-Warning -Message ("Can autofit a column or a range but not a {0} object" -f ($Address.GetType().name)) }
|
||||
|
||||
}
|
||||
elseif ($Width) {
|
||||
if ($Address -is [OfficeOpenXml.ExcelColumn]) {$Address.Width = $Width}
|
||||
elseif ($Address -is [OfficeOpenXml.ExcelRange] ) {
|
||||
($Address.Start.Column)..($Address.Start.Column + $Address.Columns) |
|
||||
ForEach-Object {$ws.Column($_).Width = $Width}
|
||||
($Address.Start.Column)..($Address.Start.Column + $Address.Columns - 1) |
|
||||
ForEach-Object {
|
||||
#$ws.Column($_).Width = $Width
|
||||
$Address.Worksheet.Column($_).Width = $Width
|
||||
}
|
||||
}
|
||||
else {Write-Warning -Message ("Can set the width of a column or a range but not a {0} object" -f ($Address.GetType().name)) }
|
||||
}
|
||||
@@ -140,6 +178,14 @@
|
||||
$Address -is [OfficeOpenXml.ExcelColumn] ) {$Address.Hidden = $True}
|
||||
else {Write-Warning -Message ("Can hide a row or a column but not a {0} object" -f ($Address.GetType().name)) }
|
||||
}
|
||||
|
||||
if ($Value) {
|
||||
$Address.Value = $Value
|
||||
}
|
||||
|
||||
if ($Formula) {
|
||||
$Address.Formula = $Formula
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
images/CustomReport.png
Normal file
BIN
images/CustomReport.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
images/PivotTableFilter.png
Normal file
BIN
images/PivotTableFilter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Reference in New Issue
Block a user