diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 73c60e4..071e8de 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -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() } diff --git a/README.md b/README.md index 7de38ef..b72f464 100644 --- a/README.md +++ b/README.md @@ -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`