From b0024cf2c48b30ab61ab7dc08315bd3465ecf347 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 28 Apr 2022 19:44:40 -0400 Subject: [PATCH 1/4] bump version --- ImportExcel.psd1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index c6c22be..1db1af9 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -6,7 +6,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '7.4.2' + ModuleVersion = '7.4.3' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' @@ -48,11 +48,13 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'ConvertTo-ExcelXlsx', 'Copy-ExcelWorksheet', 'DoChart', + 'Enable-ExcelAutoFilter', 'Expand-NumberFormat', 'Export-Excel', 'Export-ExcelSheet', 'Get-ExcelColumnName', - 'Get-ExcelFileSummary', + 'Get-ExcelFileSummary', + 'Get-ExcelSheetDimensionAddress', 'Get-ExcelSheetInfo', 'Get-ExcelWorkbookInfo', 'Get-HtmlTable', @@ -63,8 +65,9 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Import-UPS', 'Import-USPS', 'Invoke-AllTests', - 'Invoke-Sum', + 'Enable-ExcelAutofit', 'Invoke-ExcelQuery', + 'Invoke-Sum', 'Join-Worksheet', 'LineChart', 'Merge-MultipleSheets', From eb103647221af632827d8d7d4bddea39f7571e94 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 28 Apr 2022 19:44:49 -0400 Subject: [PATCH 2/4] Add helpers --- Public/Enable-ExcelAutoFilter.ps1 | 16 ++++++++++++++++ Public/Enable-ExcelAutofit.ps1 | 16 ++++++++++++++++ Public/Get-ExcelSheetDimensionAddress.ps1 | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 Public/Enable-ExcelAutoFilter.ps1 create mode 100644 Public/Enable-ExcelAutofit.ps1 create mode 100644 Public/Get-ExcelSheetDimensionAddress.ps1 diff --git a/Public/Enable-ExcelAutoFilter.ps1 b/Public/Enable-ExcelAutoFilter.ps1 new file mode 100644 index 0000000..0c4a3d5 --- /dev/null +++ b/Public/Enable-ExcelAutoFilter.ps1 @@ -0,0 +1,16 @@ +function Enable-ExcelAutoFilter { + <# + .SYNOPSIS + Enable the Excel AutoFilter + + .EXAMPLE + Enable-ExcelAutoFilter $targetSheet + #> + param( + [Parameter(Mandatory)] + [OfficeOpenXml.ExcelWorksheet]$Worksheet + ) + + $range = Get-ExcelSheetDimensionAddress $Worksheet + $Worksheet.Cells[$range].AutoFilter = $true +} \ No newline at end of file diff --git a/Public/Enable-ExcelAutofit.ps1 b/Public/Enable-ExcelAutofit.ps1 new file mode 100644 index 0000000..0d117d4 --- /dev/null +++ b/Public/Enable-ExcelAutofit.ps1 @@ -0,0 +1,16 @@ +function Enable-ExcelAutofit { + <# + .SYNOPSIS + Make all text fit the cells + + .EXAMPLE + Enable-ExcelAutofit $excel.Sheet1 + #> + param( + [Parameter(Mandatory)] + [OfficeOpenXml.ExcelWorksheet]$Worksheet + ) + + $range = Get-ExcelSheetDimensionAddress $Worksheet + $Worksheet.Cells[$range].AutoFitColumns() +} \ No newline at end of file diff --git a/Public/Get-ExcelSheetDimensionAddress.ps1 b/Public/Get-ExcelSheetDimensionAddress.ps1 new file mode 100644 index 0000000..993b7f9 --- /dev/null +++ b/Public/Get-ExcelSheetDimensionAddress.ps1 @@ -0,0 +1,15 @@ +function Get-ExcelSheetDimensionAddress { + <# + .SYNOPSIS + Get the Excel address of the dimension of a sheet + + .EXAMPLE + Get-ExcelSheetDimensionAddress $excel.Sheet1 + #> + param( + [Parameter(Mandatory)] + [OfficeOpenXml.ExcelWorksheet]$Worksheet + ) + + $Worksheet.Dimension.Address +} From f478e8a134239eaff8e1eb58881f533a17bf2c71 Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 29 Apr 2022 22:11:24 -0400 Subject: [PATCH 3/4] Add Enable-ExcelAutoFilter and Enable-ExcelAutofit example --- Examples/OpenExcelPackage/EnableFeatures.ps1 | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Examples/OpenExcelPackage/EnableFeatures.ps1 diff --git a/Examples/OpenExcelPackage/EnableFeatures.ps1 b/Examples/OpenExcelPackage/EnableFeatures.ps1 new file mode 100644 index 0000000..2d3d263 --- /dev/null +++ b/Examples/OpenExcelPackage/EnableFeatures.ps1 @@ -0,0 +1,28 @@ +# How to use Enable-ExcelAutoFilter and Enable-ExcelAutofit + +try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return } + +$data = ConvertFrom-Csv @" +RegionInfo,StateInfo,Units,Price +West,Texas,927,923.71 +North,Tennessee,466,770.67 +East,Florida,520,458.68 +East,Maine,828,661.24 +West,Virginia,465,053.58 +North,Missouri,436,235.67 +South,Kansas,214,992.47 +North,North Dakota,789,640.72 +South,Delaware,712,508.55 +"@ + +$xlfile = "$PSScriptRoot\enableFeatures.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$data | Export-Excel $xlfile + +$excel = Open-ExcelPackage $xlfile + +Enable-ExcelAutoFilter -Worksheet $excel.Sheet1 +Enable-ExcelAutofit -Worksheet $excel.Sheet1 + +Close-ExcelPackage $excel -Show \ No newline at end of file From ba145112548047d9b2bd9a5a091cce2ff1502a6a Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 30 Apr 2022 08:21:24 -0400 Subject: [PATCH 4/4] update changelog --- changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 8959cff..4d64cda 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,4 @@ # v7.5.0 - ## Fixes - Importing multiple files with Import-Excel by pipeline uses only the first file for the row count https://github.com/dfinke/ImportExcel/issues/1172 @@ -9,6 +8,10 @@ - Import-Excel now supports importing multiple sheets. It can either return a dictionary of all sheets, or as a single array of all sheets combined. - `Import-Excel $xlfile *` # reads all sheets, returns all data in a dictionary - `Import-Excel $xlfile * -NotAsDictionary` # reads all sheets, returns all data in a single array +- Added helper functions. Useful for working with an Excel package via `Open-ExcelPackage` or `-PassThru` + - `Enable-ExcelAutoFilter` + - `Enable-ExcelAutofit` + - `Get-ExcelSheetDimensionAddress` # v7.4.2