Added Filter, Freeze and Bold first row

This commit is contained in:
Doug Finke
2015-05-17 11:21:45 -04:00
parent a9566ff106
commit 51f6d4f8a2
2 changed files with 37 additions and 4 deletions

View File

@@ -82,7 +82,7 @@ function Export-ExcelSheet {
Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding
}
$xl.Dispose()
}
@@ -119,7 +119,10 @@ function Export-Excel {
[Switch]$IncludePivotChart,
[Switch]$AutoSize,
[Switch]$Show,
[Switch]$NoClobber
[Switch]$NoClobber,
[Switch]$FreezeTopRow,
[Switch]$AutoFilter,
[Switch]$BoldFirstRow
)
Begin {
@@ -230,9 +233,25 @@ function Export-Excel {
}
}
if($AutoSize) { $ws.Cells.AutoFitColumns() }
if($Password) { $ws.Protection.SetPassword($Password) }
if($AutoFilter) {
$startAddress=$ws.Dimension.Start.Address
$range="{0}:{1}" -f $startAddress, $ws.Dimension.End.Address
$ws.Cells[$range].AutoFilter=$true
}
if($FreezeTopRow) {
$ws.View.FreezePanes(2,1)
}
if($BoldFirstRow) {
$range=$ws.Dimension.Address -replace $ws.Dimension.Rows, "1"
$ws.Cells[$range].Style.Font.Bold=$true
}
if($AutoSize) { $ws.Cells.AutoFitColumns() }
$pkg.Save()
$pkg.Dispose()
@@ -291,7 +310,7 @@ function ConvertFrom-ExcelSheet {
Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding
}
$xl.Dispose()
}

View File

@@ -19,6 +19,20 @@ Know Issues
What's new
-
#### 5/17/2015
* Added three parameters:
* FreezeTopRow - Freezes the first row of the data
* AutoFilter - Enables filtering for the data in the sheet
* BoldFirstRow - Bolds the first row of data, the column headers
Example
Get-CimInstance win32_service |
select state, accept*, start*, caption |
Export-Excel test.xlsx -Show -BoldFirstRow -AutoFilter -FreezeTopRow -AutoSize
![image](https://raw.githubusercontent.com/dfinke/ImportExcel/master/images/FilterFreezeBold.gif)
#### 5/4/2015
* Published to PowerShell Gallery. In PowerShell v5 use `Find-Module importexcel` then `Find-Module importexcel | Install-Module`