Export-Excel can now make a table or a named range.

This commit is contained in:
Justin Dearing
2015-06-14 06:24:51 -04:00
parent fdc2b8a9df
commit b83f4fe55b

View File

@@ -147,7 +147,8 @@ function Export-Excel {
[Switch]$FreezeTopRow,
[Switch]$AutoFilter,
[Switch]$BoldTopRow,
[string]$RangeName
[string]$RangeName,
[string]$TableName
)
Begin {
@@ -216,6 +217,13 @@ function Export-Excel {
$startAddress=$ws.Dimension.Start.Address
$dataRange="{0}:{1}" -f $startAddress, $ws.Dimension.End.Address
Write-Debug "Data Range $dataRange"
if (-not [string]::IsNullOrEmpty($RangeName)) {
$ws.Names.Add($RangeName, $ws.Cells[$dataRange]) | Out-Null
}
if (-not [string]::IsNullOrEmpty($TableName)) {
$ws.Tables.Add($ws.Cells[$dataRange], $TableName) | Out-Null
}
if($IncludePivotTable) {
$pivotTableName = $WorkSheetname + "PivotTable"
@@ -270,6 +278,8 @@ function Export-Excel {
if($AutoSize) { $ws.Cells.AutoFitColumns() }
#$pkg.Workbook.View.ActiveTab = $ws.SheetID
$pkg.Save()
$pkg.Dispose()