mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merge pull request #1171 from dfinke/add-helper-functions
Add helper functions `Enable-ExcelAutoFilter`, `Enable-ExcelAutofit`, `Get-ExcelSheetDimensionAddress`
This commit is contained in:
28
Examples/OpenExcelPackage/EnableFeatures.ps1
Normal file
28
Examples/OpenExcelPackage/EnableFeatures.ps1
Normal file
@@ -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
|
||||
@@ -48,11 +48,14 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
|
||||
'ConvertTo-ExcelXlsx',
|
||||
'Copy-ExcelWorksheet',
|
||||
'DoChart',
|
||||
'Enable-ExcelAutoFilter',
|
||||
'Enable-ExcelAutofit',
|
||||
'Expand-NumberFormat',
|
||||
'Export-Excel',
|
||||
'Export-ExcelSheet',
|
||||
'Get-ExcelColumnName',
|
||||
'Get-ExcelFileSummary',
|
||||
'Get-ExcelFileSummary',
|
||||
'Get-ExcelSheetDimensionAddress',
|
||||
'Get-ExcelSheetInfo',
|
||||
'Get-ExcelWorkbookInfo',
|
||||
'Get-HtmlTable',
|
||||
@@ -63,8 +66,8 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
|
||||
'Import-UPS',
|
||||
'Import-USPS',
|
||||
'Invoke-AllTests',
|
||||
'Invoke-Sum',
|
||||
'Invoke-ExcelQuery',
|
||||
'Invoke-Sum',
|
||||
'Join-Worksheet',
|
||||
'LineChart',
|
||||
'Merge-MultipleSheets',
|
||||
@@ -80,8 +83,8 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
|
||||
'PieChart',
|
||||
'Pivot',
|
||||
'Read-Clipboard',
|
||||
'ReadClipboardImpl',
|
||||
'Read-OleDbData',
|
||||
'ReadClipboardImpl',
|
||||
'Remove-Worksheet',
|
||||
'Select-Worksheet',
|
||||
'Send-SQLDataToExcel',
|
||||
|
||||
16
Public/Enable-ExcelAutoFilter.ps1
Normal file
16
Public/Enable-ExcelAutoFilter.ps1
Normal file
@@ -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
|
||||
}
|
||||
16
Public/Enable-ExcelAutofit.ps1
Normal file
16
Public/Enable-ExcelAutofit.ps1
Normal file
@@ -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()
|
||||
}
|
||||
15
Public/Get-ExcelSheetDimensionAddress.ps1
Normal file
15
Public/Get-ExcelSheetDimensionAddress.ps1
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user