From eb103647221af632827d8d7d4bddea39f7571e94 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 28 Apr 2022 19:44:49 -0400 Subject: [PATCH] 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 +}