mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 13:23:29 +00:00
Set a title, the pattern, size and make it bold
This commit is contained in:
@@ -60,7 +60,13 @@ function Export-Excel {
|
|||||||
$Path,
|
$Path,
|
||||||
[Parameter(ValueFromPipeline)]
|
[Parameter(ValueFromPipeline)]
|
||||||
$TargetData,
|
$TargetData,
|
||||||
$WorkSheetname="Sheet1",
|
[string]$WorkSheetname="Sheet1",
|
||||||
|
[string]$Title,
|
||||||
|
[OfficeOpenXml.Style.ExcelFillStyle]$TitleFillPattern="None",
|
||||||
|
[bool]$TitleBold,
|
||||||
|
[int]$TitleSize=22,
|
||||||
|
#[System.Drawing.Color]$TitleBackgroundColor,
|
||||||
|
#[string]$TitleBackgroundColor,
|
||||||
[string[]]$PivotRows,
|
[string[]]$PivotRows,
|
||||||
[string[]]$PivotColumns,
|
[string[]]$PivotColumns,
|
||||||
[string[]]$PivotData,
|
[string[]]$PivotData,
|
||||||
@@ -88,12 +94,26 @@ function Export-Excel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ws = $pkg.Workbook.Worksheets.Add($WorkSheetname)
|
$ws = $pkg.Workbook.Worksheets.Add($WorkSheetname)
|
||||||
|
|
||||||
$Row = 1
|
$Row = 1
|
||||||
|
if($Title) {
|
||||||
|
$ws.Cells[$Row, 1].Value = $Title
|
||||||
|
|
||||||
|
$ws.Cells[$Row, 1].Style.Font.Size = $TitleSize
|
||||||
|
$ws.Cells[$Row, 1].Style.Font.Bold = $TitleBold
|
||||||
|
$ws.Cells[$Row, 1].Style.Fill.PatternType = $TitleFillPattern
|
||||||
|
#if($TitleBackgroundColor) {
|
||||||
|
# $ws.Cells[$Row, 1].Style.Fill.BackgroundColor.SetColor([System.Drawing.Color]::Blue)
|
||||||
|
#}
|
||||||
|
|
||||||
|
$Row = 2
|
||||||
|
}
|
||||||
|
|
||||||
} Catch {
|
} Catch {
|
||||||
if($AlreadyExists) {
|
if($AlreadyExists) {
|
||||||
throw "$WorkSheetname already exists."
|
throw "$WorkSheetname already exists."
|
||||||
} else {
|
} else {
|
||||||
throw $Error[0].Exception.InnerException
|
throw $Error[0].Exception.Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +150,11 @@ function Export-Excel {
|
|||||||
$wsPivot.View.TabSelected = $true
|
$wsPivot.View.TabSelected = $true
|
||||||
|
|
||||||
$pivotTableDataName=$WorkSheetname + "PivotTableData"
|
$pivotTableDataName=$WorkSheetname + "PivotTableData"
|
||||||
$range="{0}:{1}" -f $ws.Dimension.Start.Address, $ws.Dimension.End.Address
|
|
||||||
|
$startAddress=$ws.Dimension.Start.Address
|
||||||
|
if($Title) {$startAddress="A2"}
|
||||||
|
|
||||||
|
$range="{0}:{1}" -f $startAddress, $ws.Dimension.End.Address
|
||||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells["A1"], $ws.Cells[$range], $pivotTableDataName)
|
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells["A1"], $ws.Cells[$range], $pivotTableDataName)
|
||||||
|
|
||||||
if($PivotRows) {
|
if($PivotRows) {
|
||||||
|
|||||||
28
README.md
28
README.md
@@ -9,6 +9,11 @@ Know Issues
|
|||||||
What's new
|
What's new
|
||||||
-
|
-
|
||||||
|
|
||||||
|
#### 4/13/2015
|
||||||
|
* You can add a title to the Excel "Report" `Title`, `TitleFillPattern`, `TitleBold`, `TitleSize`, `TitleBackgroundColor`
|
||||||
|
* Thanks to [Irwin Strachan](http://pshirwin.wordpress.com) for this and other great suggestions, testing and more
|
||||||
|
|
||||||
|
|
||||||
#### 4/10/2015
|
#### 4/10/2015
|
||||||
* Renamed `AutoFitColumns` to `AutoSize`
|
* Renamed `AutoFitColumns` to `AutoSize`
|
||||||
* Implemented `Export-MultipleExcelSheets`
|
* Implemented `Export-MultipleExcelSheets`
|
||||||
@@ -20,13 +25,34 @@ What's new
|
|||||||
#### 4/8/2015
|
#### 4/8/2015
|
||||||
* Implemented exporting data to **named sheets** via the -WorkSheename parameter.
|
* Implemented exporting data to **named sheets** via the -WorkSheename parameter.
|
||||||
|
|
||||||
#### Examples
|
Examples
|
||||||
|
-
|
||||||
`gsv | Export-Excel .\test.xlsx -WorkSheetname Services`
|
`gsv | Export-Excel .\test.xlsx -WorkSheetname Services`
|
||||||
|
|
||||||
`dir -file | Export-Excel .\test.xlsx -WorkSheetname Files`
|
`dir -file | Export-Excel .\test.xlsx -WorkSheetname Files`
|
||||||
|
|
||||||
`ps | Export-Excel .\test.xlsx -WorkSheetname Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM`
|
`ps | Export-Excel .\test.xlsx -WorkSheetname Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM`
|
||||||
|
|
||||||
|
#### Example Adding a Title
|
||||||
|
You can set the pattern, size and of if the title is bold.
|
||||||
|
|
||||||
|
$p=@{
|
||||||
|
Title = "Process Report as of $(Get-Date)"
|
||||||
|
TitleFillPattern = "LightTrellis"
|
||||||
|
TitleSize = 18
|
||||||
|
TitleBold = $true
|
||||||
|
|
||||||
|
Path = "$pwd\testExport.xlsx"
|
||||||
|
Show = $true
|
||||||
|
AutoSize = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-Process |
|
||||||
|
Where Company | Select Company, PM |
|
||||||
|
Export-Excel @p
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
#### Example Export-MultipleExcelSheets
|
#### Example Export-MultipleExcelSheets
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user