diff --git a/AddDataValidation.ps1 b/AddDataValidation.ps1 deleted file mode 100644 index 5328089..0000000 --- a/AddDataValidation.ps1 +++ /dev/null @@ -1,99 +0,0 @@ -Function Add-ExcelDataValidationRule { - <# - .Synopsis - Adds data validation to a range of cells - .Example - > - >Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'E2:E1001' -ValidationType Integer -Operator between -Value 0 -Value2 100 ` - -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'Percentage must be a whole number between 0 and 100' - - This defines a validation rule on cells E2-E1001; it is an integer rule and requires a number between 0 and 100 - If a value is input with a fraction, negative number, or positive number > 100 a stop dialog box appears. - .Example - > - >Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'B2:B1001' -ValidationType List -Formula 'values!$a$2:$a$1000' - -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'You must select an item from the list' - This defines a list rule on Cells B2:1001, and the posible values are in a sheet named "values" at cells A2 to A1000 - Blank cells in this range are ignored. If $ signs are left out of the fomrmula B2 would be checked against A2-A1000 - B3, against A3-A1001, B4 against A4-A1002 up to B1001 beng checked against A1001-A1999 - .Example - > - >Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'I2:N1001' -ValidationType List -ValueSet @('yes','YES','Yes') - -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody "Select Yes or leave blank for no" - Similar to the previous example but this time provides a value set; Excel comparisons are case sesnsitive, hence 3 versions of Yes. - #> - - [CmdletBinding()] - Param( - #The range of cells to be validate, e.g. "B2:C100" - [Parameter(ValueFromPipeline = $true,Position=0)] - [Alias("Address")] - $Range , - #The worksheet where the cells should be validated - [OfficeOpenXml.ExcelWorksheet]$WorkSheet , - #An option corresponding to a choice from the 'Allow' pull down on the settings page in the Excel dialog. Any means "any allowed" i.e. no Validation - [ValidateSet('Any','Custom','DateTime','Decimal','Integer','List','TextLength','Time')] - $ValidationType, - #The operator to apply to Decimal, Integer, TextLength, DateTime and time fields, e.g. equal, between - [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]$Operator = [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]::equal , - #For Decimal, Integer, TextLength, DateTime the [first] data value - $Value, - #When using the between operator, the second data value - $Value2, - #The [first] data value as a formula. Use absolute formulas $A$1 if (e.g.) you want all cells to check against the same list - $Formula, - #When using the between operator, the second data value as a formula - $Formula2, - #When using the list validation type, a set of values (rather than refering to Sheet!B$2:B$100 ) - $ValueSet, - #Corresponds to the the 'Show Error alert ...' check box on error alert page in the Excel dialog - [switch]$ShowErrorMessage, - #Stop, Warning, or Infomation, corresponding to to the style setting in the Excel dialog - [OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle]$ErrorStyle, - #The title for the message box corresponding to to the title setting in the Excel dialog - [String]$ErrorTitle, - #The error message corresponding to to the Error message setting in the Excel dialog - [String]$ErrorBody, - #Corresponds to the the 'Show Input message ...' check box on input message page in the Excel dialog - [switch]$ShowPromptMessage, - #The prompt message corresponding to to the Input message setting in the Excel dialog - [String]$PromptBody, - #The title for the message box corresponding to to the title setting in the Excel dialog - [String]$PromptTitle, - #By default the 'Ignore blank' option will be selected, unless NoBlank is sepcified. - [String]$NoBlank - ) - if ($Range -is [Array]) { - $null = $PSBoundParameters.Remove("Range") - $Range | Add-ExcelDataValidationRule @PSBoundParameters - } - else { - #We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ] - if (-not $WorkSheet -and $Range.worksheet) {$WorkSheet = $Range.worksheet} - if ($Range.Address) {$Range = $Range.Address} - - if ($Range -isnot [string] -or -not $WorkSheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return} - #else we assume Range is a range. - - $validation = $WorkSheet.DataValidations."Add$ValidationType`Validation"($Range) - if ($validation.AllowsOperator) {$validation.Operator = $Operator} - if ($PSBoundParameters.ContainsKey('value')) { - $validation.Formula.Value = $Value - } - elseif ($Formula) {$validation.Formula.ExcelFormula = $Formula} - elseif ($ValueSet) {Foreach ($v in $ValueSet) {$validation.Formula.Values.Add($V)}} - if ($PSBoundParameters.ContainsKey('Value2')) { - $validation.Formula2.Value = $Value2 - } - elseif ($Formula2) {$validation.Formula2.ExcelFormula = $Formula} - $validation.ShowErrorMessage = [bool]$ShowErrorMessage - $validation.ShowInputMessage = [bool]$ShowPromptMessage - $validation.AllowBlank = -not $NoBlank - - if ($PromptTitle) {$validation.PromptTitle = $PromptTitle} - if ($ErrorTitle) {$validation.ErrorTitle = $ErrorTitle} - if ($PromptBody) {$validation.Prompt = $PromptBody} - if ($ErrorBody) {$validation.Error = $ErrorBody} - if ($ErrorStyle) {$validation.ErrorStyle = $ErrorStyle} - } - } diff --git a/ArgumentCompletion.ps1 b/ArgumentCompletion.ps1 new file mode 100644 index 0000000..55823e0 --- /dev/null +++ b/ArgumentCompletion.ps1 @@ -0,0 +1,131 @@ +function ColorCompletion { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + [System.Drawing.KnownColor].GetFields() | Where-Object {$_.IsStatic -and $_.name -like "$wordToComplete*" } | + Sort-Object name | ForEach-Object {New-CompletionResult $_.name $_.name + } +} + +function ListFonts { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + if (-not $script:FontFamilies) { + $script:FontFamilies = @("","") + try { + $script:FontFamilies = (New-Object System.Drawing.Text.InstalledFontCollection).Families.Name + } + catch {} + } + $script:FontFamilies.where({$_ -Gt "" -and $_ -like "$wordToComplete*"} ) | ForEach-Object { + New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'" , $_ , + ([System.Management.Automation.CompletionResultType]::ParameterValue) , $_ + } +} + +function NumberFormatCompletion { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $numformats = [ordered]@{ + "General" = "General" # format ID 0 + "Number" = "0.00" # format ID 2 + "Percentage" = "0.00%" # format ID 10 + "Scientific" = "0.00E+00" # format ID 11 + "Fraction" = "# ?/?" # format ID 12 + "Short Date" = "Localized" # format ID 14 - will be translated to "mm-dd-yy" which is localized on load by Excel. + "Short Time" = "Localized" # format ID 20 - will be translated to "h:mm" which is localized on load by Excel. + "Long Time" = "Localized" # format ID 21 - will be translated to "h:mm:ss" which is localized on load by Excel. + "Date-Time" = "Localized" # format ID 22 - will be translated to "m/d/yy h:mm" which is localized on load by Excel. + "Currency" = [cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol + "#,##0.00" + "Text" = "@" # format ID 49 + "h:mm AM/PM" = "h:mm AM/PM" # format ID 18 + "h:mm:ss AM/PM" = "h:mm:ss AM/PM" # format ID 19 + "mm:ss" = "mm:ss" # format ID 45 + "[h]:mm:ss" = "Elapsed hours" # format ID 46 + "mm:ss.0" = "mm:ss.0" # format ID 47 + "d-mmm-yy" = "Localized" # format ID 15 which is localized on load by Excel. + "d-mmm" = "Localized" # format ID 16 which is localized on load by Excel. + "mmm-yy" = "mmm-yy" # format ID 17 which is localized on load by Excel. + "0" = "Whole number" # format ID 1 + "0.00" = "Number, 2 decimals" # format ID 2 or "number" + "#,##0" = "Thousand separators" # format ID 3 + "#,##0.00" = "Thousand separators and 2 decimals" # format ID 4 + "#," = "Whole thousands" + "#.0,," = "Millions, 1 Decimal" + "0%" = "Nearest whole percentage" # format ID 9 + "0.00%" = "Percentage with decimals" # format ID 10 or "Percentage" + "00E+00" = "Scientific" # format ID 11 or "Scientific" + "# ?/?" = "One Digit fraction" # format ID 12 or "Fraction" + "# ??/??" = "Two Digit fraction" # format ID 13 + "@" = "Text" # format ID 49 or "Text" + } + $numformats.keys.where({$_ -like "$wordToComplete*"} ) | ForEach-Object { + New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'" , $_ , + ([System.Management.Automation.CompletionResultType]::ParameterValue) , $numformats[$_] + } +} + +function WorksheetArgumentCompleter { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $xlPath = $fakeBoundParameter['Path'] + if (Test-Path -Path $xlPath) { + $xlpkg = Open-ExcelPackage -ReadOnly -Path $xlPath + $WorksheetNames = $xlPkg.Workbook.Worksheets.Name + Close-ExcelPackage -nosave -ExcelPackage $xlpkg + $WorksheetNames.where( { $_ -like "*$wordToComplete*" }) | foreach-object { + New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'", + $_ , ([System.Management.Automation.CompletionResultType]::ParameterValue) , $_ + } + } +} + +If (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { + Register-ArgumentCompleter -CommandName Export-Excel -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName DataBarColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName ForeGroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName AllDataBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName TabColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Join-Worksheet -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-Worksheet -ParameterName AddBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-Worksheet -ParameterName ChangeBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-Worksheet ` -ParameterName DeleteBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName KeyFontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName AddBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName ChangeBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-MulipleSheets ` -ParameterName DeleteBackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName KeyFontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName ConditionalTextColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName BorderColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName BorderColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName FontName -ScriptBlock $Function:ListFonts + Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName FontName -ScriptBlock $Function:ListFonts + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName FontName -ScriptBlock $Function:ListFonts + Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName FontName -ScriptBlock $Function:ListFonts + Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Export-Excel -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Add-PivotTable -ParameterName PivotNumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName New-PivotTableDefinition -ParameterName PivotNumberFormat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName New-ExcelChartDefinition -ParameterName XAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName New-ExcelChartDefinition -ParameterName YAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Add-ExcelChart -ParameterName XAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Add-ExcelChart -ParameterName YAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion + Register-ArgumentCompleter -CommandName Import-Excel -ParameterName WorksheetName -ScriptBlock $Function:WorksheetArgumentCompleter +} diff --git a/Charting/BarChart.md b/Charting/BarChart.md new file mode 100644 index 0000000..0c73fa6 --- /dev/null +++ b/Charting/BarChart.md @@ -0,0 +1,137 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# BarChart + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +BarChart [[-targetData] ] [[-title] ] [[-ChartType] ] [-NoLegend] [-ShowCategory] + [-ShowPercent] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +{{ Fill NoLegend Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +{{ Fill ShowCategory Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +{{ Fill ShowPercent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -title +{{ Fill title Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Charting.ps1 b/Charting/Charting.ps1 similarity index 100% rename from Charting.ps1 rename to Charting/Charting.ps1 diff --git a/Charting/ColumnChart.md b/Charting/ColumnChart.md new file mode 100644 index 0000000..0e57227 --- /dev/null +++ b/Charting/ColumnChart.md @@ -0,0 +1,137 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# ColumnChart + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +ColumnChart [[-targetData] ] [[-title] ] [[-ChartType] ] [-NoLegend] + [-ShowCategory] [-ShowPercent] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +{{ Fill NoLegend Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +{{ Fill ShowCategory Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +{{ Fill ShowPercent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -title +{{ Fill title Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Charting/LineChart.md b/Charting/LineChart.md new file mode 100644 index 0000000..e45ea45 --- /dev/null +++ b/Charting/LineChart.md @@ -0,0 +1,137 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# LineChart + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +LineChart [[-targetData] ] [[-title] ] [[-ChartType] ] [-NoLegend] [-ShowCategory] + [-ShowPercent] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +{{ Fill NoLegend Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +{{ Fill ShowCategory Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +{{ Fill ShowPercent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -title +{{ Fill title Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Charting/PieChart.md b/Charting/PieChart.md new file mode 100644 index 0000000..93c7fdd --- /dev/null +++ b/Charting/PieChart.md @@ -0,0 +1,137 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# PieChart + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +PieChart [[-targetData] ] [[-title] ] [[-ChartType] ] [-NoLegend] [-ShowCategory] + [-ShowPercent] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +{{ Fill NoLegend Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +{{ Fill ShowCategory Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +{{ Fill ShowPercent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -title +{{ Fill title Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Charting/doChart.md b/Charting/doChart.md new file mode 100644 index 0000000..414559f --- /dev/null +++ b/Charting/doChart.md @@ -0,0 +1,134 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# DoChart + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +DoChart [[-targetData] ] [[-title] ] [[-ChartType] ] [-NoLegend] [-ShowCategory] + [-ShowPercent] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +{{ Fill NoLegend Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +{{ Fill ShowCategory Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +{{ Fill ShowPercent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -title +{{ Fill title Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/ColorCompletion.ps1 b/ColorCompletion.ps1 deleted file mode 100644 index 50d03fd..0000000 --- a/ColorCompletion.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -Function ColorCompletion { - param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) - [System.Drawing.KnownColor].GetFields() | Where-Object {$_.IsStatic -and $_.name -like "$wordToComplete*" } | - Sort-Object name | ForEach-Object {New-CompletionResult $_.name $_.name - } -} - -if (Get-Command -Name register-argumentCompleter -ErrorAction SilentlyContinue) { - Register-ArgumentCompleter -CommandName Export-Excel -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName DataBarColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName ForeGroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName AllDataBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName FontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Compare-Worksheet -ParameterName TabColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Join-Worksheet -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-Worksheet -ParameterName AddBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-Worksheet -ParameterName ChangeBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-Worksheet ` -ParameterName DeleteBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName KeyFontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName AddBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName ChangeBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-MulipleSheets ` -ParameterName DeleteBackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Merge-MulipleSheets -ParameterName KeyFontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName ConditionalTextColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName FontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName BorderColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName FontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName BorderColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName FontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName FontColor -ScriptBlock $Function:ColorCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion -} \ No newline at end of file diff --git a/ConvertFromExcelToSQLInsert.ps1 b/ConvertFromExcelToSQLInsert.ps1 deleted file mode 100644 index 7a3f00c..0000000 --- a/ConvertFromExcelToSQLInsert.ps1 +++ /dev/null @@ -1,118 +0,0 @@ -function ConvertFrom-ExcelToSQLInsert { - <# - .SYNOPSIS - Generate SQL insert statements from Excel spreadsheet. - .DESCRIPTION - Generate SQL insert statements from Excel spreadsheet. - .PARAMETER TableName - Name of the target database table. - .PARAMETER Path - Path to an existing .XLSX file - This parameter is passed to Import-Excel as is. - .PARAMETER WorkSheetname - Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. - This parameter is passed to Import-Excel as is. - .PARAMETER StartRow - The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. - When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. - .PARAMETER Header - Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. - If you provide fewr header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded. - If you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blank as there is no data for them. - .PARAMETER NoHeader - Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. - This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names. - .PARAMETER DataOnly - Import only rows and columns that contain data, empty rows and empty columns are not imported. - .PARAMETER ConvertEmptyStringsToNull - If specified, cells without any data are replaced with NULL, instead of an empty string. - This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value. - - .EXAMPLE - Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings: - - ---------------------------------------------------------- - | File: Movies.xlsx - Sheet: Sheet1 | - ---------------------------------------------------------- - | A B C | - |1 Movie Name Year Rating | - |2 The Bodyguard 1992 9 | - |3 The Matrix 1999 8 | - |4 Skyfall 2012 9 | - |5 The Avengers 2012 | - ---------------------------------------------------------- - - PS C:\> Import-Excel -TableName "Movies" -Path 'C:\Movies.xlsx' - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', ''); - - .EXAMPLE - Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string. - - ---------------------------------------------------------- - | File: Movies.xlsx - Sheet: Sheet1 | - ---------------------------------------------------------- - | A B C | - |1 Movie Name Year Rating | - |2 The Bodyguard 1992 9 | - |3 The Matrix 1999 8 | - |4 Skyfall 2012 9 | - |5 The Avengers 2012 | - ---------------------------------------------------------- - - PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path "C:\Movies.xlsx" -ConvertEmptyStringsToNull - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); - INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL); - - #> - [CmdletBinding()] - param( - [Parameter(Mandatory = $true)] - $TableName, - [Alias("FullName")] - [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true, Mandatory = $true)] - [ValidateScript( { Test-Path $_ -PathType Leaf })] - $Path, - [Alias("Sheet")] - $WorkSheetname = 1, - [Alias('HeaderRow', 'TopRow')] - [ValidateRange(1, 9999)] - [Int]$StartRow, - [string[]]$Header, - [switch]$NoHeader, - [switch]$DataOnly, - [switch]$ConvertEmptyStringsToNull, - [switch]$UseMSSQLSyntax - ) - - $null = $PSBoundParameters.Remove('TableName') - $null = $PSBoundParameters.Remove('ConvertEmptyStringsToNull') - $null = $PSBoundParameters.Remove('UseMSSQLSyntax') - - $params = @{} + $PSBoundParameters - - ConvertFrom-ExcelData @params { - param($propertyNames, $record) - - $ColumnNames = "'" + ($PropertyNames -join "', '") + "'" - if($UseMSSQLSyntax) { - $ColumnNames = "[" + ($PropertyNames -join "], [") + "]" - } - - $values = foreach ($propertyName in $PropertyNames) { - if ($ConvertEmptyStringsToNull.IsPresent -and [string]::IsNullOrEmpty($record.$propertyName)) { - 'NULL' - } - else { - "'" + $record.$propertyName + "'" - } - } - $targetValues = ($values -join ", ") - - "INSERT INTO {0} ({1}) Values({2});" -f $TableName, $ColumnNames, $targetValues - } -} \ No newline at end of file diff --git a/Examples/XlRangeToImage/XlRangeToImage.ps1 b/Examples/XlRangeToImage/XlRangeToImage.ps1 index fdfe98a..be7cfa2 100644 --- a/Examples/XlRangeToImage/XlRangeToImage.ps1 +++ b/Examples/XlRangeToImage/XlRangeToImage.ps1 @@ -21,4 +21,4 @@ West,Berry,4 Export-Excel $xlFileName -ReturnRange ` -ConditionalText (New-ConditionalText Apple), (New-ConditionalText Berry -ConditionalTextColor White -BackgroundColor Purple) -Convert-XlRangeToImage -Path $xlFileName -workSheetname sheet1 -range $range -Show +Convert-ExcelXlRangeToImage -Path $xlFileName -workSheetname sheet1 -range $range -Show diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 deleted file mode 100644 index 4459690..0000000 --- a/Export-Excel.ps1 +++ /dev/null @@ -1,1399 +0,0 @@ -function Export-Excel { - <# - .SYNOPSIS - Exports data to an Excel worksheet. - .DESCRIPTION - Exports data to an Excel file and where possible tries to convert numbers - in text fields so Excel recognizes them as numbers instead of text. - After all: Excel is a spreadsheet program used for number manipulation - and calculations. If number conversion is not desired, use the - parameter -NoNumberConversion *. - .PARAMETER Path - Path to a new or existing .XLSX file. - .PARAMETER ExcelPackage - An object representing an Excel Package - usually this is returned by specifying -PassThru allowing multiple commands to work on the same workbook without saving and reloading each time. - .PARAMETER WorksheetName - The name of a sheet within the workbook - "Sheet1" by default. - .PARAMETER ClearSheet - If specified Export-Excel will remove any existing worksheet with the selected name. The Default behaviour is to overwrite cells in this sheet as needed (but leaving non-overwritten ones in place). - .PARAMETER Append - If specified data will be added to the end of an existing sheet, using the same column headings. - .PARAMETER TargetData - Data to insert onto the worksheet - this is usually provided from the pipeline. - .PARAMETER DisplayPropertySet - Many (but not all) objects have a hidden property named psStandardmembers with a child property DefaultDisplayPropertySet ; this parameter reduces the properties exported to those in this set. - .PARAMETER NoAliasOrScriptPropeties - Some objects duplicate existing properties by adding aliases, or have Script properties which take a long time to return a value and slow the export down, if specified this removes these properties - .PARAMETER ExcludeProperty - Specifies properties which may exist in the target data but should not be placed on the worksheet. - .PARAMETER Calculate - If specified a recalculation of the worksheet will be requested before saving. - .PARAMETER Title - Text of a title to be placed in the top left cell. - .PARAMETER TitleBold - Sets the title in boldface type. - .PARAMETER TitleSize - Sets the point size for the title. - .PARAMETER TitleBackgroundColor - Sets the cell background color for the title cell. - .PARAMETER TitleFillPattern - Sets the fill pattern for the title cell. - .PARAMETER Password - Sets password protection on the workbook. - .PARAMETER IncludePivotTable - Adds a PivotTable using the data in the worksheet. - .PARAMETER PivotTableName - If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". - .PARAMETER PivotRows - Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. - .PARAMETER PivotColumns - Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. - .PARAMETER PivotFilter - Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. - .PARAMETER PivotData - In a PivotTable created from command line parameters, the fields to use in the table body are given as a Hash table in the form ColumnName = Average|Count|CountNums|Max|Min|Product|None|StdDev|StdDevP|Sum|Var|VarP. - .PARAMETER PivotDataToColumn - If there are multiple datasets in a PivotTable, by default they are shown as separate rows under the given row heading; this switch makes them separate columns. - .PARAMETER NoTotalsInPivot - In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. - .PARAMETER PivotTotals - By default, PivotTables have totals for each row (on the right) and for each column at the bottom. This allows just one or neither to be selected. - .PARAMETER PivotTableDefinition - Instead of describing a single PivotTable with multiple command-line parameters; you can use a HashTable in the form PivotTableName = Definition; - Definition is itself a Hashtable with Sheet, PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values. - .PARAMETER IncludePivotChart - Include a chart with the PivotTable - implies -IncludePivotTable. - .PARAMETER ChartType - The type for PivotChart (one of Excel's defined chart types). - .PARAMETER NoLegend - Exclude the legend from the PivotChart. - .PARAMETER ShowCategory - Add category labels to the PivotChart. - .PARAMETER ShowPercent - Add percentage labels to the PivotChart. - .PARAMETER ConditionalFormat - One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. - .PARAMETER ConditionalText - Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. - .PARAMETER NoNumberConversion - By default we convert all values to numbers if possible, but this isn't always desirable. NoNumberConversion allows you to add exceptions for the conversion. The only Wildcard allowed is * for all properties - .PARAMETER BoldTopRow - Makes the top row boldface. - .PARAMETER NoHeader - Does not put field names at the top of columns. - .PARAMETER RangeName - Makes the data in the worksheet a named range. - .PARAMETER TableName - Makes the data in the worksheet a table with a name, and applies a style to it. The name must not contain spaces. If a style is specified without a name, table1, table2 etc. will be used. - .PARAMETER TableStyle - Selects the style for the named table - if a name is specified without a style, 'Medium6' is used as a default. - .PARAMETER BarChart - Creates a "quick" bar chart using the first text column as labels and the first numeric column as values - .PARAMETER ColumnChart - Creates a "quick" column chart using the first text column as labels and the first numeric column as values - .PARAMETER LineChart - Creates a "quick" line chart using the first text column as labels and the first numeric column as values - .PARAMETER PieChart - Creates a "quick" pie chart using the first text column as labels and the first numeric column as values - .PARAMETER ExcelChartDefinition - A hash table containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-Pivot] charts. - .PARAMETER HideSheet - Name(s) of Sheet(s) to hide in the workbook, supports wildcards. If the selection would cause all sheets to be hidden, the sheet being worked on will be revealed. - .PARAMETER UnHideSheet - Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. - .PARAMETER MoveToStart - If specified, the worksheet will be moved to the start of the workbook. - -MoveToStart takes precedence over -MoveToEnd, -Movebefore and -MoveAfter if more than one is specified. - .PARAMETER MoveToEnd - If specified, the worksheet will be moved to the end of the workbook. - (This is the default position for newly created sheets, but this can be used to move existing sheets.) - .PARAMETER MoveBefore - If specified, the worksheet will be moved before the nominated one (which can be a position starting from 1, or a name). - -MoveBefore takes precedence over -MoveAfter if both are specified. - .PARAMETER MoveAfter - If specified, the worksheet will be moved after the nominated one (which can be a position starting from 1, or a name or *). - If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. - .PARAMETER KillExcel - Closes Excel - prevents errors writing to the file because Excel has it open. - .PARAMETER AutoNameRange - Makes each column a named range. - .PARAMETER StartRow - Row to start adding data. 1 by default. Row 1 will contain the title if any. Then headers will appear (Unless -No header is specified) then the data appears. - .PARAMETER StartColumn - Column to start adding data - 1 by default. - .PARAMETER FreezeTopRow - Freezes headers etc. in the top row. - .PARAMETER FreezeFirstColumn - Freezes titles etc. in the left column. - .PARAMETER FreezeTopRowFirstColumn - Freezes top row and left column (equivalent to Freeze pane 2,2 ). - .PARAMETER FreezePane - Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). - .PARAMETER AutoFilter - Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. - .PARAMETER AutoSize - Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. - .PARAMETER MaxAutoSizeRows - Autosizing can be time consuming, so this sets a maximum number of rows to look at for the Autosize operation. Default is 1000; If 0 is specified ALL rows will be checked - .PARAMETER Activate - If there is already content in the workbook, a new sheet will not be active UNLESS Activate is specified; if a PivotTable is included it will be the active sheet - .PARAMETER Now - The -Now switch is a shortcut that automatically creates a temporary file, enables "AutoSize", "TableName" and "Show", and opens the file immediately. - .PARAMETER NumberFormat - Formats all values that can be converted to a number to the format specified. - - Examples: - # integer (not really needed unless you need to round numbers, Excel will use default cell properties). - '0' - - # integer without displaying the number 0 in the cell. - '#' - - # number with 1 decimal place. - '0.0' - - # number with 2 decimal places. - '0.00' - - # number with 2 decimal places and thousand-separator. - '#,##0.00' - - # number with 2 decimal places and thousand-separator and money-symbol. - '€#,##0.00' - - # percentage (1 = 100%, 0.01 = 1%) - '0%' - - # Blue color for positive numbers and a red color for negative numbers. All numbers will be proceeded by a dollar sign '$'. - '[Blue]$#,##0.00;[Red]-$#,##0.00' - - .PARAMETER ReZip - If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. - .PARAMETER NoClobber - Not used. Left in to avoid problems with older scripts, it may be removed in future versions. - .PARAMETER CellStyleSB - A script block which is run at the end of the export to apply styles to cells (although it can be used for other purposes). - The script block is given three paramaters; an object containing the current worksheet, the Total number of Rows and the number of the last column. - .PARAMETER Show - Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. - .PARAMETER ReturnRange - If specified, Export-Excel returns the range of added cells in the format "A1:Z100". - .PARAMETER PassThru - If specified, Export-Excel returns an object representing the Excel package without saving the package first. - To save, you need to call Close-ExcelPackage or send the object back to Export-Excel, or use its .Save() or SaveAs() method. - .EXAMPLE - Get-Process | Export-Excel .\Test.xlsx -show - Export all the processes to the Excel file 'Test.xlsx' and open the file immediately. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - Write-Output -1 668 34 777 860 -0.5 119 -0.1 234 788 | - Export-Excel @ExcelParams -NumberFormat '[Blue]$#,##0.00;[Red]-$#,##0.00' - - Exports all data to the Excel file 'Excel.xslx' and colors the negative values - in Red and the positive values in Blue. It will also add a dollar sign in front - of the numbers which use a thousand seperator and display to two decimal places. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - [PSCustOmobject][Ordered]@{ - Date = Get-Date - Formula1 = '=SUM(F2:G2)' - String1 = 'My String' - String2 = 'a' - IPAddress = '10.10.25.5' - Number1 = '07670' - Number2 = '0,26' - Number3 = '1.555,83' - Number4 = '1.2' - Number5 = '-31' - PhoneNr1 = '+32 44' - PhoneNr2 = '+32 4 4444 444' - PhoneNr3 = '+3244444444' - } | Export-Excel @ExcelParams -NoNumberConversion IPAddress, Number1 - - Exports all data to the Excel file "Excel.xlsx" and tries to convert all values - to numbers where possible except for "IPAddress" and "Number1", which are - stored in the sheet 'as is', without being converted to a number. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - [PSCustOmobject][Ordered]@{ - Date = Get-Date - Formula1 = '=SUM(F2:G2)' - String1 = 'My String' - String2 = 'a' - IPAddress = '10.10.25.5' - Number1 = '07670' - Number2 = '0,26' - Number3 = '1.555,83' - Number4 = '1.2' - Number5 = '-31' - PhoneNr1 = '+32 44' - PhoneNr2 = '+32 4 4444 444' - PhoneNr3 = '+3244444444' - } | Export-Excel @ExcelParams -NoNumberConversion * - - Exports all data to the Excel file 'Excel.xslx' as is, no number conversion - will take place. This means that Excel will show the exact same data that - you handed over to the 'Export-Excel' function. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - Write-Output 489 668 299 777 860 151 119 497 234 788 | - Export-Excel @ExcelParams -ConditionalText $( - New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink - ) - - Exports data that will have a Conditional Formatting rule in Excel - that will show cells with a value is greater than 525, whith a - background fill color of "LightPink" and the text in "DarkRed". - Where condition is not met the color willbe the default, black - text on a white background. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - Get-Service | Select-Object -Property Name, Status, DisplayName, ServiceName | - Export-Excel @ExcelParams -ConditionalText $( - New-ConditionalText Stop DarkRed LightPink - New-ConditionalText Running Blue Cyan - ) - - Exports all services to an Excel sheet, setting a Conditional formatting rule - that will set the background fill color to "LightPink" and the text color - to "DarkRed" when the value contains the word "Stop". - If the value contains the word "Running" it will have a background fill - color of "Cyan" and text colored 'Blue'. If neither condition is met, the - color will be the default, black text on a white background. - - .EXAMPLE - > - PS> $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - - $Array = @() - - $Obj1 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - } - - $Obj2 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - } - - $Obj3 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - Member4 = 'Fourth' - } - - $Array = $Obj1, $Obj2, $Obj3 - $Array | Out-GridView -Title 'Not showing Member3 and Member4' - $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorksheetName Numbers - - Updates the first object of the array by adding property 'Member3' and 'Member4'. - Afterwards. all objects are exported to an Excel file and all column headers are visible. - - .EXAMPLE - Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM - - .EXAMPLE - Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PM - - .EXAMPLE - Get-Service | Export-Excel 'c:\temp\test.xlsx' -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} - - .EXAMPLE - > - PS> $pt = [ordered]@{} - $pt.pt1=@{ SourceWorkSheet = 'Sheet1'; - PivotRows = 'Status' - PivotData = @{'Status'='count'} - IncludePivotChart = $true - ChartType = 'BarClustered3D' - } - $pt.pt2=@{ SourceWorkSheet = 'Sheet2'; - PivotRows = 'Company' - PivotData = @{'Company'='count'} - IncludePivotChart = $true - ChartType = 'PieExploded3D' - } - Remove-Item -Path .\test.xlsx - Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize - Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' - Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show - - This example defines two PivotTables. Then it puts Service data on Sheet1 - with one call to Export-Excel and Process Data on sheet2 with a second - call to Export-Excel. The third and final call adds the two PivotTables - and opens the spreadsheet in Excel. - .EXAMPLE - > - PS> Remove-Item -Path .\test.xlsx - $excel = Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -PassThru - $excel.Workbook.Worksheets["Sheet1"].Row(1).style.font.bold = $true - $excel.Workbook.Worksheets["Sheet1"].Column(3 ).width = 29 - $excel.Workbook.Worksheets["Sheet1"].Column(3 ).Style.wraptext = $true - $excel.Save() - $excel.Dispose() - Start-Process .\test.xlsx - - This example uses -PassThru. It puts service information into sheet1 of the - workbook and saves the ExcelPackage object in $Excel. It then uses the package - object to apply formatting, and then saves the workbook and disposes of the object - before loading the document in Excel. Other commands in the module remove the need - to work directly with the package object in this way. - - .EXAMPLE - > - PS> Remove-Item -Path .\test.xlsx -ErrorAction Ignore - $excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | Export-Excel -Path .\test.xlsx -ClearSheet -WorksheetName "Processes" -PassThru - $sheet = $excel.Workbook.Worksheets["Processes"] - $sheet.Column(1) | Set-ExcelRange -Bold -AutoFit - $sheet.Column(2) | Set-ExcelRange -Width 29 -WrapText - $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NFormat "#,###" - Set-ExcelRange -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###" - Set-ExcelRange -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold - Set-ExcelRange -Address $sheet.Row(1) -Bold -HorizontalAlignment Center - Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red - Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red - foreach ($c in 5..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit } - Export-Excel -ExcelPackage $excel -WorksheetName "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show - - This a more sophisticated version of the previous example showing different - ways of using Set-ExcelRange, and also adding conditional formatting. - In the final command a PivotChart is added and the workbook is opened in Excel. - .EXAMPLE - 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | Export-Excel -now -LineChart -AutoNameRange - - Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees. - - .EXAMPLE - > - PS> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | - Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables - - Runs a query against a SQL Server database and outputs the resulting rows DataRows using the -OutputAs parameter. - The results are then piped to the Export-Excel function. - NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. - - .LINK - https://github.com/dfinke/ImportExcel - #> - [CmdletBinding(DefaultParameterSetName = 'Default')] - [OutputType([OfficeOpenXml.ExcelPackage])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] - Param( - [Parameter(ParameterSetName = 'Default', Position = 0)] - [String]$Path, - [Parameter(Mandatory = $true, ParameterSetName = "Package")] - [OfficeOpenXml.ExcelPackage]$ExcelPackage, - [Parameter(ValueFromPipeline = $true)] - [Alias('TargetData')] - $InputObject, - [Switch]$Calculate, - [Switch]$Show, - [String]$WorksheetName = 'Sheet1', - [String]$Password, - [switch]$ClearSheet, - [switch]$Append, - [String]$Title, - [OfficeOpenXml.Style.ExcelFillStyle]$TitleFillPattern = 'Solid', - [Switch]$TitleBold, - [Int]$TitleSize = 22, - $TitleBackgroundColor, - [Switch]$IncludePivotTable, - [String]$PivotTableName, - [String[]]$PivotRows, - [String[]]$PivotColumns, - $PivotData, - [String[]]$PivotFilter, - [Switch]$PivotDataToColumn, - [Hashtable]$PivotTableDefinition, - [Switch]$IncludePivotChart, - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', - [Switch]$NoLegend, - [Switch]$ShowCategory, - [Switch]$ShowPercent, - [Switch]$AutoSize, - $MaxAutoSizeRows = 1000, - [Switch]$NoClobber, - [Switch]$FreezeTopRow, - [Switch]$FreezeFirstColumn, - [Switch]$FreezeTopRowFirstColumn, - [Int[]]$FreezePane, - [Switch]$AutoFilter, - [Switch]$BoldTopRow, - [Switch]$NoHeader, - [ValidateScript( { - if (-not $_) { throw 'RangeName is null or empty.' } - elseif ($_[0] -notmatch '[a-z]') { throw 'RangeName starts with an invalid character.' } - else { $true } - })] - [String]$RangeName, - [Alias('Table')] - $TableName, - [OfficeOpenXml.Table.TableStyles]$TableStyle = [OfficeOpenXml.Table.TableStyles]::Medium6, - [Switch]$Barchart, - [Switch]$PieChart, - [Switch]$LineChart , - [Switch]$ColumnChart , - [Object[]]$ExcelChartDefinition, - [String[]]$HideSheet, - [String[]]$UnHideSheet, - [Switch]$MoveToStart, - [Switch]$MoveToEnd, - $MoveBefore , - $MoveAfter , - [Switch]$KillExcel, - [Switch]$AutoNameRange, - [Int]$StartRow = 1, - [Int]$StartColumn = 1, - [alias('PT')] - [Switch]$PassThru, - [String]$Numberformat = 'General', - [string[]]$ExcludeProperty, - [Switch]$NoAliasOrScriptPropeties, - [Switch]$DisplayPropertySet, - [String[]]$NoNumberConversion, - [Object[]]$ConditionalFormat, - [Object[]]$ConditionalText, - [Object[]]$Style, - [ScriptBlock]$CellStyleSB, - #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified - [switch]$Activate, - [Parameter(ParameterSetName = 'Default')] - [Switch]$Now, - [Switch]$ReturnRange, - #By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. - [ValidateSet("Both","Columns","Rows","None")] - [String]$PivotTotals = "Both", - #Included for compatibility - equivalent to -PivotTotals "None" - [Switch]$NoTotalsInPivot, - [Switch]$ReZip - ) - - begin { - $numberRegex = [Regex]'\d' - $isDataTypeValueType = $false - if ($NoClobber) {Write-Warning -Message "-NoClobber parameter is no longer used" } - #Open the file, get the worksheet, and decide where in the sheet we are writing, and if there is a number format to apply. - try { - $script:Header = $null - if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet." ; return} - #To force -Now not to format as a table, allow $false in -TableName to be "No table" - $TableName = if ($null -eq $TableName -or ($TableName -is [bool] -and $false -eq $TableName)) { $null } else {[String]$TableName} - if ($Now -or (-not $Path -and -not $ExcelPackage) ) { - if (-not $PSBoundParameters.ContainsKey("Path")) { $Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx' } - if (-not $PSBoundParameters.ContainsKey("Show")) { $Show = $true } - if (-not $PSBoundParameters.ContainsKey("AutoSize")) { $AutoSize = $true } - #"Now" option will create a table, unless something passed in TableName/Table Style. False in TableName will block autocreation - if (-not $PSBoundParameters.ContainsKey("TableName") -and - -not $PSBoundParameters.ContainsKey("TableStyle") -and - -not $AutoFilter) { - $TableName = 'Table1' - } - } - if ($ExcelPackage) { - $pkg = $ExcelPackage - $Path = $pkg.File - } - Else { $pkg = Open-ExcelPackage -Path $Path -Create -KillExcel:$KillExcel -Password:$Password} - } - catch {throw "Could not open Excel Package $path"} - try { - $params = @{WorksheetName=$WorksheetName} - foreach ($p in @("ClearSheet", "MoveToStart", "MoveToEnd", "MoveBefore", "MoveAfter", "Activate")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} - $ws = $pkg | Add-WorkSheet @params - if ($ws.Name -ne $WorksheetName) { - Write-Warning -Message "The Worksheet name has been changed from $WorksheetName to $($ws.Name), this may cause errors later." - $WorksheetName = $ws.Name - } - } - catch {throw "Could not get worksheet $worksheetname"} - try { - if ($Append -and $ws.Dimension) { - #if there is a title or anything else above the header row, append needs to be combined wih a suitable startrow parameter - $headerRange = $ws.Dimension.Address -replace "\d+$", $StartRow - #using a slightly odd syntax otherwise header ends up as a 2D array - $ws.Cells[$headerRange].Value | ForEach-Object -Begin {$Script:header = @()} -Process {$Script:header += $_ } - #if we did not get AutoNameRange, but headers have ranges of the same name make autoNameRange True, otherwise make it false - if (-not $AutoNameRange) { - $AutoNameRange = $true ; foreach ($h in $header) {if ($ws.names.name -notcontains $h) {$AutoNameRange = $false} } - } - #if we did not get a Rangename but there is a Range which covers the active part of the sheet, set Rangename to that. - if (-not $RangeName -and $ws.names.where({$_.name[0] -match '[a-z]'})) { - $theRange = $ws.names.where({ - ($_.Name[0] -match '[a-z]' ) -and - ($_.Start.Row -eq $StartRow) -and - ($_.Start.Column -eq $StartColumn) -and - ($_.End.Row -eq $ws.Dimension.End.Row) -and - ($_.End.Column -eq $ws.Dimension.End.column) } , 'First', 1) - if ($theRange) {$rangename = $theRange.name} - } - - #if we did not get a table name but there is a table which covers the active part of the sheet, set table name to that, and don't do anything with autofilter - if ($null -eq $TableName -and $ws.Tables.Where({$_.address.address -eq $ws.dimension.address})) { - $TableName = $ws.Tables.Where({$_.address.address -eq $ws.dimension.address},'First', 1).Name - $AutoFilter = $false - } - #if we did not get $autofilter but a filter range is set and it covers the right area, set autofilter to true - elseif (-not $AutoFilter -and $ws.Names['_xlnm._FilterDatabase']) { - if ( ($ws.Names['_xlnm._FilterDatabase'].Start.Row -eq $StartRow) -and - ($ws.Names['_xlnm._FilterDatabase'].Start.Column -eq $StartColumn) -and - ($ws.Names['_xlnm._FilterDatabase'].End.Row -eq $ws.Dimension.End.Row) -and - ($ws.Names['_xlnm._FilterDatabase'].End.Column -eq $ws.Dimension.End.Column) ) {$AutoFilter = $true} - } - - $row = $ws.Dimension.End.Row - Write-Debug -Message ("Appending: headers are " + ($script:Header -join ", ") + " Start row is $row") - if ($Title) {Write-Warning -Message "-Title Parameter is ignored when appending."} - } - elseif ($Title) { - #Can only add a title if not appending! - $Row = $StartRow - $ws.Cells[$Row, $StartColumn].Value = $Title - $ws.Cells[$Row, $StartColumn].Style.Font.Size = $TitleSize - - if ($PSBoundParameters.ContainsKey("TitleBold")) { - #Set title to Bold face font if -TitleBold was specified. - #Otherwise the default will be unbolded. - $ws.Cells[$Row, $StartColumn].Style.Font.Bold = [boolean]$TitleBold - } - if ($TitleBackgroundColor ) { - if ($TitleBackgroundColor -is [string]) {$TitleBackgroundColor = [System.Drawing.Color]::$TitleBackgroundColor } - $ws.Cells[$Row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern - $ws.Cells[$Row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor) - } - $Row ++ ; $startRow ++ - } - else { $Row = $StartRow } - $ColumnIndex = $StartColumn - $Numberformat = Expand-NumberFormat -NumberFormat $Numberformat - if ((-not $ws.Dimension) -and ($Numberformat -ne $ws.Cells.Style.Numberformat.Format)) { - $ws.Cells.Style.Numberformat.Format = $Numberformat - $setNumformat = $false - } - else { $setNumformat = ($Numberformat -ne $ws.Cells.Style.Numberformat.Format) } - } - catch {throw "Failed preparing to export to worksheet '$WorksheetName' to '$Path': $_"} - #region Special case -inputobject passed a dataTable object - <# If inputObject was passed via the pipeline it won't be visible until the process block, we will only see it here if it was passed as a parameter - if it is a data table don't do foreach on it (slow) - put the whole table in and set dates on date columns, - set things up for the end block, and skip the process block #> - if ($InputObject -is [System.Data.DataTable]) { - #don't leave caller with a renamed table, save the name and set it back later - $orginalTableName = $InputObject.TableName - if ($TableName) { - $InputObject.TableName = $TableName - } - while ($InputObject.TableName -in $pkg.Workbook.Worksheets.Tables.name) { - Write-Warning "Table name $($InputObject.TableName) is not unique, adding '_' to it " - $InputObject.TableName += "_" - } - if ($TableName -or $PSBoundParameters.ContainsKey("TableStyle")) { - $TableName = $null - $null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader),$TableStyle ) - } - else { - $null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader) ) - } - $InputObject.TableName = $orginalTableName - foreach ($c in $InputObject.Columns.where({$_.datatype -eq [datetime]})) { - Set-ExcelColumn -Worksheet $ws -Column ($c.Ordinal + $StartColumn) -NumberFormat 'Date-Time' - } - foreach ($c in $InputObject.Columns.where({$_.datatype -eq [timespan]})) { - Set-ExcelColumn -Worksheet $ws -Column ($c.Ordinal + $StartColumn) -NumberFormat '[h]:mm:ss' - } - $ColumnIndex += $InputObject.Columns.Count - 1 - if ($noHeader) {$row += $InputObject.Rows.Count -1 } - else {$row += $InputObject.Rows.Count } - $null = $PSBoundParameters.Remove('InputObject') - $firstTimeThru = $false - } - #endregion - else {$firstTimeThru = $true} - } - - process { if ($PSBoundParameters.ContainsKey("InputObject")) { - try { - if ($null -eq $InputObject) {$row += 1} - foreach ($TargetData in $InputObject) { - if ($firstTimeThru) { - $firstTimeThru = $false - $isDataTypeValueType = ($null -eq $TargetData) -or ($TargetData.GetType().name -match 'string|timespan|datetime|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort|URI|ExcelHyperLink') - if ($isDataTypeValueType ) { - $script:Header = @(".") # dummy value to make sure we go through the "for each name in $header" - if (-not $Append) {$row -= 1} # By default row will be 1, it is incremented before inserting values (so it ends pointing at final row.); si first data row is 2 - move back up 1 if there is no header . - } - if ($null -ne $TargetData) {Write-Debug "DataTypeName is '$($TargetData.GetType().name)' isDataTypeValueType '$isDataTypeValueType'" } - } - #region Add headers - if we are appending, or we have been through here once already we will have the headers - if (-not $script:Header) { - if ($DisplayPropertySet -and $TargetData.psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames) { - $script:Header = $TargetData.psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames.Where( {$_ -notin $ExcludeProperty}) - } - else { - if ($NoAliasOrScriptPropeties) {$propType = "Property"} else {$propType = "*"} - $script:Header = $TargetData.PSObject.Properties.where( {$_.MemberType -like $propType}).Name - } - foreach ($exclusion in $ExcludeProperty) {$script:Header = $script:Header -notlike $exclusion} - if ($NoHeader) { - # Don't push the headers to the spreadsheet - $Row -= 1 - } - else { - $ColumnIndex = $StartColumn - foreach ($Name in $script:Header) { - $ws.Cells[$Row, $ColumnIndex].Value = $Name - Write-Verbose "Cell '$Row`:$ColumnIndex' add header '$Name'" - $ColumnIndex += 1 - } - } - } - #endregion - #region Add non header values - $Row += 1 - $ColumnIndex = $StartColumn - <# - For each item in the header OR for the Data item if this is a simple Type or data table : - If it is a date insert with one of Excel's built in formats - recognized as "Date and time to be localized" - if it is a timespan insert with a built in format for elapsed hours, minutes and seconds - if its any other numeric insert as is , setting format if need be. - Preserve URI, Insert a data table, convert non string objects to string. - For strings, check for fomula, URI or Number, before inserting as a string (ignore nulls) #> - foreach ($Name in $script:Header) { - if ($isDataTypeValueType) {$v = $TargetData} - else {$v = $TargetData.$Name} - try { - if ($v -is [DateTime]) { - $ws.Cells[$Row, $ColumnIndex].Value = $v - $ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized. - } - elseif ($v -is [TimeSpan]) { - $ws.Cells[$Row, $ColumnIndex].Value = $v - $ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = '[h]:mm:ss' - } - elseif ($v -is [System.ValueType]) { - $ws.Cells[$Row, $ColumnIndex].Value = $v - if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } - } - elseif ($v -is [uri] ) { - $ws.Cells[$Row, $ColumnIndex].HyperLink = $v - $ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) - $ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true - } - elseif ($v -isnot [String] ) { #Other objects or null. - if ($null -ne $v) { $ws.Cells[$Row, $ColumnIndex].Value = $v.toString()} - } - elseif ($v[0] -eq '=') { - $ws.Cells[$Row, $ColumnIndex].Formula = ($v -replace '^=','') - if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } - } - elseif ( [System.Uri]::IsWellFormedUriString($v , [System.UriKind]::Absolute) ) { - if ($v -match "^xl://internal/") { - $referenceAddress = $v -replace "^xl://internal/" , "" - $display = $referenceAddress -replace "!A1$" , "" - $h = New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList $referenceAddress , $display - $ws.Cells[$Row, $ColumnIndex].HyperLink = $h - } - else {$ws.Cells[$Row, $ColumnIndex].HyperLink = $v } #$ws.Cells[$Row, $ColumnIndex].Value = $v.AbsoluteUri - $ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) - $ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true - } - else { - $number = $null - if ( $numberRegex.IsMatch($v) -and # if it contains digit(s) - this syntax is quicker than -match for many items and cuts out slow checks for non numbers - $NoNumberConversion -ne '*' -and # and NoNumberConversion isn't specified - $NoNumberConversion -notcontains $Name -and - [Double]::TryParse($v, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) - ) { - $ws.Cells[$Row, $ColumnIndex].Value = $number - if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } - } - else { - $ws.Cells[$Row, $ColumnIndex].Value = $v - } - - } - } - catch {Write-Warning -Message "Could not insert the '$Name' property at Row $Row, Column $ColumnIndex"} - $ColumnIndex += 1 - } - $ColumnIndex -= 1 # column index will be the last column whether isDataTypeValueType was true or false - #endregion - } - } - catch {throw "Failed exporting data to worksheet '$WorksheetName' to '$Path': $_" } - - }} - - end { - if ($firstTimeThru -and $ws.Dimension) { - $LastRow = $ws.Dimension.End.Row - $LastCol = $ws.Dimension.End.Column - $endAddress = $ws.Dimension.End.Address - } - else { - $LastRow = $Row - $LastCol = $ColumnIndex - $endAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($LastRow , $LastCol) - } - $startAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($StartRow, $StartColumn) - $dataRange = "{0}:{1}" -f $startAddress, $endAddress - - Write-Debug "Data Range '$dataRange'" - if ($AutoNameRange) { - try { - if (-not $script:header) { - # if there aren't any headers, use the the first row of data to name the ranges: this is the last point that headers will be used. - $headerRange = $ws.Dimension.Address -replace "\d+$", $StartRow - #using a slightly odd syntax otherwise header ends up as a 2D array - $ws.Cells[$headerRange].Value | ForEach-Object -Begin {$Script:header = @()} -Process {$Script:header += $_ } - if ($PSBoundParameters.ContainsKey($TargetData)) { #if Export was called with data that writes no header start the range at $startRow ($startRow is data) - $targetRow = $StartRow - } - else { $targetRow = $StartRow + 1 } #if Export was called without data to add names (assume $startRow is a header) or... - } # ... called with data that writes a header, then start the range at $startRow + 1 - else { $targetRow = $StartRow + 1 } - - #Dimension.start.row always seems to be one so we work out the target row - #, but start.column is the first populated one and .Columns is the count of populated ones. - # if we have 5 columns from 3 to 8, headers are numbered 0..4, so that is in the for loop and used for getting the name... - # but we have to add the start column on when referencing positions - foreach ($c in 0..($LastCol - $StartColumn)) { - $targetRangeName = @($script:Header)[$c] #Let Add-ExcelName fix (and warn about) bad names - Add-ExcelName -RangeName $targetRangeName -Range $ws.Cells[$targetRow, ($StartColumn + $c ), $LastRow, ($StartColumn + $c )] - try {#this test can throw with some names, surpress any error - if ([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress(($targetRangeName -replace '\W' , '_' ))) { - Write-Warning -Message "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property." - } - } - Catch { - Write-Warning -Message "AutoNameRange: Testing '$targetRangeName' caused an error. This should be harmless, but a change of property name may be needed.." - } - } - } - catch {Write-Warning -Message "Failed adding named ranges to worksheet '$WorksheetName': $_" } - } - #Empty string is not allowed as a name for ranges or tables. - if ($RangeName) { Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $RangeName} - - #Allow table to be inserted by specifying Name, or Style or both; only process autoFilter if there is no table (they clash). - if ($null -ne $TableName) { - Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $PSBoundParameters['TableName'] -TableStyle $TableStyle - } - elseif ($PSBoundParameters.ContainsKey('TableStyle')) { - Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName "" -TableStyle $TableStyle - } - elseif ($AutoFilter) { - try { - $ws.Cells[$dataRange].AutoFilter = $true - Write-Verbose -Message "Enabled autofilter. " - } - catch {Write-Warning -Message "Failed adding autofilter to worksheet '$WorksheetName': $_"} - } - - if ($PivotTableDefinition) { - foreach ($item in $PivotTableDefinition.GetEnumerator()) { - $params = $item.value - if ($Activate) {$params.Activate = $true } - if ($params.keys -notcontains 'SourceRange' -and - ($params.Keys -notcontains 'SourceWorkSheet' -or $params.SourceWorkSheet -eq $WorksheetName)) {$params.SourceRange = $dataRange} - if ($params.Keys -notcontains 'SourceWorkSheet') {$params.SourceWorkSheet = $ws } - if ($params.Keys -notcontains 'NoTotalsInPivot' -and $NoTotalsInPivot ) {$params.PivotTotals = 'None'} - if ($params.Keys -notcontains 'PivotTotals' -and $PivotTotals ) {$params.PivotTotals = $PivotTotals} - if ($params.Keys -notcontains 'PivotDataToColumn' -and $PivotDataToColumn) {$params.PivotDataToColumn = $true} - - Add-PivotTable -ExcelPackage $pkg -PivotTableName $item.key @Params - } - } - if ($IncludePivotTable -or $IncludePivotChart) { - $params = @{ - 'SourceRange' = $dataRange - } - if ($PivotTableName -and ($pkg.workbook.worksheets.tables.name -contains $PivotTableName)) { - Write-Warning -Message "The selected PivotTable name '$PivotTableName' is already used as a table name. Adding a suffix of 'Pivot'." - $PivotTableName += 'Pivot' - } - - if ($PivotTableName) {$params.PivotTableName = $PivotTableName} - else {$params.PivotTableName = $WorksheetName + 'PivotTable'} - if ($Activate) {$params.Activate = $true } - if ($PivotFilter) {$params.PivotFilter = $PivotFilter} - if ($PivotRows) {$params.PivotRows = $PivotRows} - if ($PivotColumns) {$Params.PivotColumns = $PivotColumns} - if ($PivotData) {$Params.PivotData = $PivotData} - if ($NoTotalsInPivot) {$params.PivotTotals = "None" } - Elseif ($PivotTotals) {$params.PivotTotals = $PivotTotals} - if ($PivotDataToColumn) {$params.PivotDataToColumn = $true} - if ($IncludePivotChart) { - $params.IncludePivotChart = $true - $Params.ChartType = $ChartType - if ($ShowCategory) {$params.ShowCategory = $true} - if ($ShowPercent) {$params.ShowPercent = $true} - if ($NoLegend) {$params.NoLegend = $true} - } - Add-PivotTable -ExcelPackage $pkg -SourceWorkSheet $ws @params - } - - try { - #Allow single switch or two seperate ones. - if ($FreezeTopRowFirstColumn -or ($FreezeTopRow -and $FreezeFirstColumn)) { - $ws.View.FreezePanes(2, 2) - Write-Verbose -Message "Froze top row and first column" - } - elseif ($FreezeTopRow) { - $ws.View.FreezePanes(2, 1) - Write-Verbose -Message "Froze top row" - } - elseif ($FreezeFirstColumn) { - $ws.View.FreezePanes(1, 2) - Write-Verbose -Message "Froze first column" - } - #Must be 1..maxrows or and array of 1..maxRows,1..MaxCols - if ($FreezePane) { - $freezeRow, $freezeColumn = $FreezePane - if (-not $freezeColumn -or $freezeColumn -eq 0) { - $freezeColumn = 1 - } - - if ($freezeRow -ge 1) { - $ws.View.FreezePanes($freezeRow, $freezeColumn) - Write-Verbose -Message "Froze panes at row $freezeRow and column $FreezeColumn" - } - } - } - catch {Write-Warning -Message "Failed adding Freezing the panes in worksheet '$WorksheetName': $_"} - - if ($PSBoundParameters.ContainsKey("BoldTopRow")) { #it sets bold as far as there are populated cells: for whole row could do $ws.row($x).style.font.bold = $true - try { - if ($Title) { - $range = $ws.Dimension.Address -replace '\d+', ($StartRow + 1) - } - else { - $range = $ws.Dimension.Address -replace '\d+', $StartRow - } - $ws.Cells[$range].Style.Font.Bold = [boolean]$BoldTopRow - Write-Verbose -Message "Set $range font style to bold." - } - catch {Write-Warning -Message "Failed setting the top row to bold in worksheet '$WorksheetName': $_"} - } - if ($AutoSize -and -not $env:NoAutoSize) { - try { - #Don't fit the all the columns in the sheet; if we are adding cells beside things with hidden columns, that unhides them - if ($MaxAutoSizeRows -and $MaxAutoSizeRows -lt $LastRow ) { - $AutosizeRange = [OfficeOpenXml.ExcelAddress]::GetAddress($startRow,$StartColumn, $MaxAutoSizeRows , $LastCol) - $ws.Cells[$AutosizeRange].AutoFitColumns() - } - else {$ws.Cells[$dataRange].AutoFitColumns() } - Write-Verbose -Message "Auto-sized columns" - } - catch { Write-Warning -Message "Failed autosizing columns of worksheet '$WorksheetName': $_"} - } - elseif ($AutoSize) {Write-Warning -Message "Auto-fitting columns is not available with this OS configuration." } - - foreach ($Sheet in $HideSheet) { - try { - $pkg.Workbook.WorkSheets.Where({$_.Name -like $sheet}) | ForEach-Object { - $_.Hidden = 'Hidden' - Write-verbose -Message "Sheet '$($_.Name)' Hidden." - } - } - catch {Write-Warning -Message "Failed hiding worksheet '$sheet': $_"} - } - foreach ($Sheet in $UnHideSheet) { - try { - $pkg.Workbook.WorkSheets.Where({$_.Name -like $sheet}) | ForEach-Object { - $_.Hidden = 'Visible' - Write-verbose -Message "Sheet '$($_.Name)' shown" - } - } - catch {Write-Warning -Message "Failed showing worksheet '$sheet': $_"} - } - if (-not $pkg.Workbook.Worksheets.Where({$_.Hidden -eq 'visible'})) { - Write-Verbose -Message "No Sheets were left visible, making $WorksheetName visible" - $ws.Hidden = 'Visible' - } - - foreach ($chartDef in $ExcelChartDefinition) { - if ($chartDef -is [System.Management.Automation.PSCustomObject]) { - $params = @{} - $chartDef.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}} - Add-ExcelChart -Worksheet $ws @params - } - elseif ($chartDef -is [hashtable] -or $chartDef -is[System.Collections.Specialized.OrderedDictionary]) { - Add-ExcelChart -Worksheet $ws @chartDef - } - } - - if ($Calculate) { - try { [OfficeOpenXml.CalculationExtension]::Calculate($ws) } - catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook. $_"} - } - - if ($Barchart -or $PieChart -or $LineChart -or $ColumnChart) { - if ($NoHeader) {$FirstDataRow = $startRow} - else {$FirstDataRow = $startRow + 1 } - $range = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $startColumn, $FirstDataRow, $lastCol ) - $xCol = $ws.cells[$range] | Where-Object {$_.value -is [string] } | ForEach-Object {$_.start.column} | Sort-Object | Select-Object -first 1 - if (-not $xcol) { - $xcol = $StartColumn - $range = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, ($startColumn +1), $FirstDataRow, $lastCol ) - } - $yCol = $ws.cells[$range] | Where-Object {$_.value -is [valueType] -or $_.Formula } | ForEach-Object {$_.start.column} | Sort-Object | Select-Object -first 1 - if (-not ($xCol -and $ycol)) { Write-Warning -Message "Can't identify a string column and a number column to use as chart labels and data. "} - else { - $params = @{ - XRange = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $xcol , $lastrow, $xcol) - YRange = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $ycol , $lastrow, $ycol) - Title = '' - Column = ($lastCol +1) - Width = 800 - } - if ($ShowPercent) {$params["ShowPercent"] = $true} - if ($ShowCategory) {$params["ShowCategory"] = $true} - if ($NoLegend) {$params["NoLegend"] = $true} - if (-not $NoHeader) {$params["SeriesHeader"] = $ws.Cells[$startRow, $YCol].Value} - if ($ColumnChart) {$Params["chartType"] = "ColumnStacked" } - elseif ($Barchart) {$Params["chartType"] = "BarStacked" } - elseif ($PieChart) {$Params["chartType"] = "PieExploded3D" } - elseif ($LineChart) {$Params["chartType"] = "Line" } - - Add-ExcelChart -Worksheet $ws @params - } - } - - # It now doesn't matter if the conditional formating rules are passed in $conditionalText or $conditional format. - # Just one with an alias for compatiblity it will break things for people who are using both at once - foreach ($c in (@() + $ConditionalText + $ConditionalFormat) ) { - try { - #we can take an object with a .ConditionalType property made by New-ConditionalText or with a .Formatter Property made by New-ConditionalFormattingIconSet or a hash table - if ($c.ConditionalType) { - $cfParams = @{RuleType = $c.ConditionalType; ConditionValue = $c.Text ; - BackgroundColor = $c.BackgroundColor; BackgroundPattern = $c.PatternType ; - ForeGroundColor = $c.ConditionalTextColor} - if ($c.Range) {$cfParams.Range = $c.Range} - else {$cfParams.Range = $ws.Dimension.Address } - Add-ConditionalFormatting -WorkSheet $ws @cfParams - Write-Verbose -Message "Added conditional formatting to range $($c.range)" - } - elseif ($c.formatter) { - switch ($c.formatter) { - "ThreeIconSet" {Add-ConditionalFormatting -WorkSheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse } - "FourIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse } - "FiveIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse } - } - Write-Verbose -Message "Added conditional formatting to range $($c.range)" - } - elseif ($c -is [hashtable] -or $c -is[System.Collections.Specialized.OrderedDictionary]) { - if (-not $c.Range -or $c.Address) {$c.Address = $ws.Dimension.Address } - Add-ConditionalFormatting -WorkSheet $ws @c - } - } - catch {throw "Error applying conditional formatting to worksheet $_"} - } - foreach ($s in $Style) { - if (-not $s.Range) {$s["Range"] = $ws.Dimension.Address } - Set-ExcelRange -WorkSheet $ws @s - } - if ($CellStyleSB) { - try { - $TotalRows = $ws.Dimension.Rows - $LastColumn = $ws.Dimension.Address -replace "^.*:(\w*)\d+$" , '$1' - & $CellStyleSB $ws $TotalRows $LastColumn - } - catch {Write-Warning -Message "Failed processing CellStyleSB in worksheet '$WorksheetName': $_"} - } - - #Can only add password, may want to support -password $Null removing password. - if ($Password) { - try { - $ws.Protection.SetPassword($Password) - Write-Verbose -Message 'Set password on workbook' - } - - catch {throw "Failed setting password for worksheet '$WorksheetName': $_"} - } - - if ($PassThru) { $pkg } - else { - if ($ReturnRange) {$dataRange } - - if ($Password) { $pkg.Save($Password) } - else { $pkg.Save() } - Write-Verbose -Message "Saved workbook $($pkg.File)" - if ($ReZip) { - Write-Verbose -Message "Re-Zipping $($pkg.file) using .NET ZIP library" - try { - Add-Type -AssemblyName 'System.IO.Compression.Filesystem' -ErrorAction stop - } - catch { - Write-Error "The -ReZip parameter requires .NET Framework 4.5 or later to be installed. Recommend to install Powershell v4+" - continue - } - try { - $TempZipPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName()) - $null = [io.compression.zipfile]::ExtractToDirectory($pkg.File, $TempZipPath) - Remove-Item $pkg.File -Force - $null = [io.compression.zipfile]::CreateFromDirectory($TempZipPath, $pkg.File) - } - catch {throw "Error resizipping $path : $_"} - } - - $pkg.Dispose() - - if ($Show) { Invoke-Item $Path } - } - - } -} - -function Add-WorkSheet { - <# - .Synopsis - Adds a worksheet to an existing workbook. - .Description - If the named worksheet already exists, the -Clearsheet parameter decides whether it should be deleted and a new one returned, - or if not specified the existing sheet will be returned. By default the sheet is created at the end of the work book, the - -MoveXXXX switches allow the sheet to be [re]positioned at the start or before or after another sheet. A new sheet will only be - made the default sheet when excel opens if -Activate is specified. - .Example - $WorksheetActors = $ExcelPackage | Add-WorkSheet -WorkSheetname Actors - - $ExcelPackage holds an Excel package object (returned by Open-ExcelPackage, or Export-Excel -passthru). - This command will add a sheet named 'Actors', or return the sheet if it exists, and the result is stored in $WorkSheetActors. - .Example - $WorksheetActors = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname "Actors" -ClearSheet -MoveToStart - - This time the Excel package object is passed as a parameter instead of piped. If the 'Actors' sheet already exists it is deleted - and re-created. The new sheet will be created last in the workbook, and -MoveToStart Moves it to the start. - .Example - $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationName -CopySource $sourceWs -Activate - This time a workbook is used instead of a package, and a worksheet is copied - $SourceWs is a worksheet object, which can come - from the same workbook or a different one. Here the new copy of the data is made the active sheet when the workbook is opened. - #> - [cmdletBinding()] - [OutputType([OfficeOpenXml.ExcelWorksheet])] - param( - #An object representing an Excel Package. - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = "Package", Position = 0)] - [OfficeOpenXml.ExcelPackage]$ExcelPackage, - #An Excel Workbook to which the Worksheet will be added - a Package contains one Workbook, so you can use whichever fits at the time. - [Parameter(Mandatory = $true, ParameterSetName = "WorkBook")] - [OfficeOpenXml.ExcelWorkbook]$ExcelWorkbook, - #The name of the worksheet, 'Sheet1' by default. - [string]$WorksheetName , - #If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. - [switch]$ClearSheet, - #If specified, the worksheet will be moved to the start of the workbook. - #MoveToStart takes precedence over MoveToEnd, Movebefore and MoveAfter if more than one is specified. - [Switch]$MoveToStart, - #If specified, the worksheet will be moved to the end of the workbook. - #(This is the default position for newly created sheets, but this can be used to move existing sheets.) - [Switch]$MoveToEnd, - #If specified, the worksheet will be moved before the nominated one (which can be an index starting from 1, or a name). - #MoveBefore takes precedence over MoveAfter if both are specified. - $MoveBefore , - # If specified, the worksheet will be moved after the nominated one (which can be an index starting from 1, or a name or *). - # If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. - $MoveAfter , - #If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. - [switch]$Activate, - #If worksheet is provided as a copy source the new worksheet will be a copy of it. The source can be in the same workbook, or in a different file. - [OfficeOpenXml.ExcelWorksheet]$CopySource, - #Ignored but retained for backwards compatibility. - [Switch] $NoClobber - ) - #if we were given a workbook use it, if we were given a package, use its workbook - if ($ExcelPackage -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelPackage.Workbook} - - # If WorksheetName was given, try to use that worksheet. If it wasn't, and we are copying an existing sheet, try to use the sheet name - # If we are not copying a sheet, and have no name, use the name "SheetX" where X is the number of the new sheet - if (-not $WorksheetName -and $CopySource -and -not $ExcelWorkbook[$CopySource.Name]) {$WorksheetName = $CopySource.Name} - elseif (-not $WorksheetName) {$WorksheetName = "Sheet" + (1 + $ExcelWorkbook.Worksheets.Count)} - else {$ws = $ExcelWorkbook.Worksheets[$WorksheetName]} - - #If -clearsheet was specified and the named sheet exists, delete it - if ($ws -and $ClearSheet) { $ExcelWorkbook.Worksheets.Delete($WorksheetName) ; $ws = $null } - - #Copy or create new sheet as needed - if (-not $ws -and $CopySource) { - Write-Verbose -Message "Copying into worksheet '$WorksheetName'." - $ws = $ExcelWorkbook.Worksheets.Add($WorksheetName, $CopySource) - } - elseif (-not $ws) { - $ws = $ExcelWorkbook.Worksheets.Add($WorksheetName) - Write-Verbose -Message "Adding worksheet '$WorksheetName'." - } - else {Write-Verbose -Message "Worksheet '$WorksheetName' already existed."} - #region Move sheet if needed - if ($MoveToStart) {$ExcelWorkbook.Worksheets.MoveToStart($WorksheetName) } - elseif ($MoveToEnd ) {$ExcelWorkbook.Worksheets.MoveToEnd($WorksheetName) } - elseif ($MoveBefore ) { - if ($ExcelWorkbook.Worksheets[$MoveBefore]) { - if ($MoveBefore -is [int]) { - $ExcelWorkbook.Worksheets.MoveBefore($ws.Index, $MoveBefore) - } - else {$ExcelWorkbook.Worksheets.MoveBefore($WorksheetName, $MoveBefore)} - } - else {Write-Warning "Can't find worksheet '$MoveBefore'; worsheet '$WorksheetName' will not be moved."} - } - elseif ($MoveAfter ) { - if ($MoveAfter -eq "*") { - if ($WorksheetName -lt $ExcelWorkbook.Worksheets[1].Name) {$ExcelWorkbook.Worksheets.MoveToStart($WorksheetName)} - else { - $i = 1 - While ($i -lt $ExcelWorkbook.Worksheets.Count -and ($ExcelWorkbook.Worksheets[$i + 1].Name -le $WorksheetName) ) { $i++} - $ExcelWorkbook.Worksheets.MoveAfter($ws.Index, $i) - } - } - elseif ($ExcelWorkbook.Worksheets[$MoveAfter]) { - if ($MoveAfter -is [int]) { - $ExcelWorkbook.Worksheets.MoveAfter($ws.Index, $MoveAfter) - } - else { - $ExcelWorkbook.Worksheets.MoveAfter($WorksheetName, $MoveAfter) - } - } - else {Write-Warning "Can't find worksheet '$MoveAfter'; worsheet '$WorksheetName' will not be moved."} - } - #endregion - if ($Activate) {Select-Worksheet -ExcelWorksheet $ws } - if ($ExcelPackage -and -not (Get-Member -InputObject $ExcelPackage -Name $ws.Name)) { - $sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $ws.name)) - Add-Member -InputObject $ExcelPackage -MemberType ScriptProperty -Name $ws.name -Value $sb - } - return $ws -} - -function Select-Worksheet { - <# - .SYNOPSIS - Sets the selected tab in an Excel workbook to be the chosen sheet and unselects all the others. - .DESCRIPTION - Sometimes when a sheet is added we want it to be the active sheet, sometimes we want the active sheet to be left as it was. - Select-Worksheet exists to change which sheet is the selected tab when Excel opens the file. - .EXAMPLE - Select-Worksheet -ExcelWorkbook $ExcelWorkbook -WorksheetName "NewSheet" - $ExcelWorkbook holds a workbook object containing a sheet named "NewSheet"; - This sheet will become the [only] active sheet in the workbook - .EXAMPLE - Select-Worksheet -ExcelPackage $Pkg -WorksheetName "NewSheet2" - $pkg holds an Excel Package, whose workbook contains a sheet named "NewSheet2" - This sheet will become the [only] active sheet in the workbook. - .EXAMPLE - Select-Worksheet -ExcelWorksheet $ws - $ws holds an Excel worksheet which will become the [only] active sheet - in its workbook. - #> - param ( - #An object representing an ExcelPackage. - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Package', Position = 0)] - [OfficeOpenXml.ExcelPackage]$ExcelPackage, - #An Excel workbook to which the Worksheet will be added - a package contains one Workbook so you can use workbook or package as it suits. - [Parameter(Mandatory = $true, ParameterSetName = 'WorkBook')] - [OfficeOpenXml.ExcelWorkbook]$ExcelWorkbook, - [Parameter(ParameterSetName='Package')] - [Parameter(ParameterSetName='Workbook')] - #The name of the worksheet "Sheet1" by default. - [string]$WorksheetName, - #An object representing an Excel worksheet. - [Parameter(ParameterSetName='Sheet',Mandatory=$true)] - [OfficeOpenXml.ExcelWorksheet]$ExcelWorksheet - ) - #if we were given a package, use its workbook - if ($ExcelPackage -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelPackage.Workbook} - #if we now have workbook, get the worksheet; if we were given a sheet get the workbook - if ($ExcelWorkbook -and $WorksheetName) {$ExcelWorksheet = $ExcelWorkbook.Worksheets[$WorksheetName]} - elseif ($ExcelWorksheet -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelWorksheet.Workbook ; } - #if we didn't get to a worksheet give up. If we did set all works sheets to not selected and then the one we want to selected. - if (-not $ExcelWorksheet) {Write-Warning -Message "The worksheet $WorksheetName was not found." ; return } - else { - foreach ($w in $ExcelWorkbook.Worksheets) {$w.View.TabSelected = $false} - $ExcelWorksheet.View.TabSelected = $true - } -} - -function Add-ExcelName { - <# - .SYNOPSIS - Adds a named-range to an existing Excel worksheet. - .DESCRIPTION - It is often helpful to be able to refer to sets of cells with a name rather than using their co-ordinates; Add-ExcelName sets up these names. - .EXAMPLE - Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $rangeName - $WS is a worksheet, and $dataRange is a string describing a range of cells - e.g. "A1:Z10" - which will become a named range, using the name in $rangeName. - #> - [CmdletBinding()] - param( - #The range of cells to assign as a name. - [Parameter(Mandatory=$true)] - [OfficeOpenXml.ExcelRange]$Range, - #The name to assign to the range. If the name exists it will be updated to the new range. If no name is specified, the first cell in the range will be used as the name. - [String]$RangeName - ) - try { - $ws = $Range.Worksheet - if (-not $RangeName) { - $RangeName = $ws.Cells[$Range.Start.Address].Value - $Range = ($Range.Worksheet.cells[($range.start.row +1), $range.start.Column , $range.end.row, $range.end.column]) - } - if ($RangeName -match '\W') { - Write-Warning -Message "Range name '$RangeName' contains illegal characters, they will be replaced with '_'." - $RangeName = $RangeName -replace '\W','_' - } - if ($ws.names[$RangeName]) { - Write-verbose -Message "Updating Named range '$RangeName' to $($Range.FullAddressAbsolute)." - $ws.Names[$RangeName].Address = $Range.FullAddressAbsolute - } - else { - Write-verbose -Message "Creating Named range '$RangeName' as $($Range.FullAddressAbsolute)." - $null = $ws.Names.Add($RangeName, $Range) - } - } - catch {Write-Warning -Message "Failed adding named range '$RangeName' to worksheet '$($ws.Name)': $_" } -} - -function Add-ExcelTable { - <# - .SYNOPSIS - Adds Tables to Excel workbooks. - .DESCRIPTION - Unlike named ranges, where the name only needs to be unique within a sheet, Table names must be unique in the workbook - Tables carry formatting by default have a filter. The filter, header, Totals, first and last column highlights - .EXAMPLE - Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName - - $WS is a worksheet, and $dataRange is a string describing a range of cells - e.g. "A1:Z10" - this range which will become a table, named $TableName - .EXAMPLE - Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName Musictable -ShowFilter:$false -ShowTotal -ShowFirstColumn - Again $ws is a worksheet, range here is the whole of the active part of the worksheet. The table style and name are set, - the filter is turned off, and a "Totals" row added, and first column is set in bold. - #> - [CmdletBinding()] - [OutputType([OfficeOpenXml.Table.ExcelTable])] - param ( - #The range of cells to assign to a table. - [Parameter(Mandatory=$true)] - [OfficeOpenXml.ExcelRange]$Range, - #The name for the Table - this should be unqiue in the Workbook - auto generated names will be used if this is left empty. - [String]$TableName = "", - #The Style for the table, by default "Medium6" is used - [OfficeOpenXml.Table.TableStyles]$TableStyle = 'Medium6', - #By default the header row is shown - it can be turned off with -ShowHeader:$false. - [Switch]$ShowHeader , - #By default the filter is enabled - it can be turned off with -ShowFilter:$false. - [Switch]$ShowFilter, - #Show total adds a totals row. This does not automatically sum the columns but provides a drop-down in each to select sum, average etc - [Switch]$ShowTotal, - #A HashTable in the form ColumnName = "Average"|"Count"|"CountNums"|"Max"|"Min"|"None"|"StdDev"|"Sum"|"Var" - if specified, -ShowTotal is not needed. - [hashtable]$TotalSettings, - #Highlights the first column in bold. - [Switch]$ShowFirstColumn, - #Highlights the last column in bold. - [Switch]$ShowLastColumn, - #By default the table formats show striped rows, the can be turned off with -ShowRowStripes:$false - [Switch]$ShowRowStripes, - #Turns on column stripes. - [Switch]$ShowColumnStripes, - #If -PassThru is specified, the table object will be returned to allow additional changes to be made. - [Switch]$PassThru - ) - try { - if ($TableName -eq "" -or $null -eq $TableName) { - $tbl = $Range.Worksheet.Tables.Add($Range, "") - } - else { - if ([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress($TableName)) { - Write-Warning -Message "$TableName reads as an Excel address, and so is not allowed as a table name." - return - } - if ($TableName -notMatch '^[A-Z]') { - Write-Warning -Message "$TableName is not allowed as a table name because it does not begin with a letter." - return - } - if ($TableName -match "\W") { - Write-Warning -Message "At least one character in $TableName is illegal in a table name and will be replaced with '_' . " - $TableName = $TableName -replace '\W', '_' - } - $ws = $Range.Worksheet - #if the table exists in this worksheet, update it. - if ($ws.Tables[$TableName]) { - $tbl =$ws.Tables[$TableName] - $tbl.TableXml.table.ref = $Range.Address - Write-Verbose -Message "Re-defined table '$TableName', now at $($Range.Address)." - } - elseif ($ws.Workbook.Worksheets.Tables.Name -contains $TableName) { - Write-Warning -Message "The Table name '$TableName' is already used on a different worksheet." - return - } - else { - $tbl = $ws.Tables.Add($Range, $TableName) - Write-Verbose -Message "Defined table '$($tbl.Name)' at $($Range.Address)" - } - } - #it seems that show total changes some of the others, so the sequence matters. - if ($PSBoundParameters.ContainsKey('ShowHeader')) {$tbl.ShowHeader = [bool]$ShowHeader} - if ($PSBoundParameters.ContainsKey('TotalSettings')) { - $tbl.ShowTotal = $true - foreach ($k in $TotalSettings.keys) { - if (-not $tbl.Columns[$k]) {Write-Warning -Message "Table does not have a Column '$k'."} - elseif ($TotalSettings[$k] -notin @("Average", "Count", "CountNums", "Max", "Min", "None", "StdDev", "Sum", "Var") ) { - Write-Warning -Message "'$($TotalSettings[$k])' is not a valid total function." - } - else {$tbl.Columns[$k].TotalsRowFunction = $TotalSettings[$k]} - } - } - elseif ($PSBoundParameters.ContainsKey('ShowTotal')) {$tbl.ShowTotal = [bool]$ShowTotal} - if ($PSBoundParameters.ContainsKey('ShowFilter')) {$tbl.ShowFilter = [bool]$ShowFilter} - if ($PSBoundParameters.ContainsKey('ShowFirstColumn')) {$tbl.ShowFirstColumn = [bool]$ShowFirstColumn} - if ($PSBoundParameters.ContainsKey('ShowLastColumn')) {$tbl.ShowLastColumn = [bool]$ShowLastColumn} - if ($PSBoundParameters.ContainsKey('ShowRowStripes')) {$tbl.ShowRowStripes = [bool]$ShowRowStripes} - if ($PSBoundParameters.ContainsKey('ShowColumnStripes')) {$tbl.ShowColumnStripes = [bool]$ShowColumnStripes} - $tbl.TableStyle = $TableStyle - - if ($PassThru) {return $tbl} - } - catch {Write-Warning -Message "Failed adding table '$TableName' to worksheet '$WorksheetName': $_"} -} diff --git a/AddConditionalFormatting.ps1 b/ExportedCommands/Add-ConditionalFormatting.ps1 similarity index 58% rename from AddConditionalFormatting.ps1 rename to ExportedCommands/Add-ConditionalFormatting.ps1 index d1f3d71..cf204b8 100644 --- a/AddConditionalFormatting.ps1 +++ b/ExportedCommands/Add-ConditionalFormatting.ps1 @@ -1,172 +1,51 @@ -try { - #ensure that color and font lookups are available - [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") -} -catch {} -Function Add-ConditionalFormatting { - <# - .Synopsis - Adds conditional formatting to all or part of a worksheet. - .Description - Conditional formatting allows Excel to: - * Mark cells with icons depending on their value - * Show a databar whose length indicates the value or a two or three color scale where the color indicates the relative value - * Change the color, font, or number format of cells which meet given criteria - Add-ConditionalFormatting allows these parameters to be set; for fine tuning of - the rules, the -PassThru switch will return the rule so that you can modify - things which are specific to that type of rule, example, the values which - correspond to each icon in an Icon-Set. - .Example - > - $excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru - Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "b2:b1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "2003" - Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "i2:i1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "Disabled" - $excel.Workbook.Worksheets[1].Cells["D1:G1048576"].Style.Numberformat.Format = [cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern - $excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true - $excel.Save() ; $excel.Dispose() - - Here Export-Excel is called with the -PassThru parameter so the ExcelPackage object - representing Machines.XLSX is stored in $Excel.The desired worksheet is selected - and then columns" B" and "I" are conditionally formatted (excluding the top row) - to show red text if they contain "2003" or "Disabled" respectively. - A fixed date format is then applied to columns D to G, and the top row is formatted. - Finally the workbook is saved and the Excel package object is closed. - .Example - > - $r = Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Range "B1:B100" -ThreeIconsSet Flags -Passthru - $r.Reverse = $true ; $r.Icon1.Type = "Num"; $r.Icon2.Type = "Num" ; $r.Icon2.value = 100 ; $r.Icon3.type = "Num" ;$r.Icon3.value = 1000 - - Again Export-Excel has been called with -PassThru leaving a package object - in $Excel. This time B1:B100 has been conditionally formatted with 3 icons, - using the "Flags" Icon-Set. Add-ConditionalFormatting does not provide access - to every option in the formatting rule, so -PassThru has been used and the - rule is modified to apply the flags in reverse order, and transitions - between flags are set to 100 and 1000. - .Example - Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red - - This time $sheet holds an ExcelWorkshseet object and databars are added to - column D, excluding the top row. - .Example - Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue - - In this example a named range is used to select the cells where the condition - should apply, and instead of specifying a sheet and range within the sheet as - separate parameters, the cells where the format should apply are specified - directly. If a cell in the "FinishPosition" range is 1, then the text is - turned to Bold & Purple. This rule is moved to first in the priority list, - and where cells have a value of 1, no other rules will be processed. - .Example - > - $excel = Get-ChildItem | Select-Object -Property Name,Length,LastWriteTime,CreationTime | Export-Excel "$env:temp\test43.xlsx" -PassThru -AutoSize - $ws = $excel.Workbook.Worksheets["Sheet1"] - $ws.Cells["E1"].Value = "SavedAt" - $ws.Cells["F1"].Value = [datetime]::Now - $ws.Cells["F1"].Style.Numberformat.Format = (Expand-NumberFormat -NumberFormat 'Date-Time') - $lastRow = $ws.Dimension.End.Row - - Add-ConditionalFormatting -WorkSheet $ws -address "A2:A$Lastrow" -RuleType LessThan -ConditionValue "A" -ForeGroundColor Gray - Add-ConditionalFormatting -WorkSheet $ws -address "B2:B$Lastrow" -RuleType GreaterThan -ConditionValue 1000000 -NumberFormat '#,###,,.00"M"' - Add-ConditionalFormatting -WorkSheet $ws -address "C2:C$Lastrow" -RuleType GreaterThan -ConditionValue "=INT($F$1-7)" -ForeGroundColor Green -StopIfTrue - Add-ConditionalFormatting -WorkSheet $ws -address "D2:D$Lastrow" -RuleType Equal -ConditionValue "=C2" -ForeGroundColor Blue -StopIfTrue - - Close-ExcelPackage -Show $excel - - The first few lines of code export a list of file and directory names, sizes - and dates to a spreadsheet. It puts the date of the export in cell F1. - The first Conditional format changes the color of files and folders that begin - with a ".", "_" or anything else which sorts before "A". - The second Conditional format changes the Number format of numbers bigger than - 1 million, for example 1,234,567,890 will dispay as "1,234.57M" - The third highlights datestamps of files less than a week old when the export - was run; the = is necessary in the condition value otherwise the rule will - look for the the text INT($F$1-7), and the cell address for the date is fixed - using the standard Excel $ notation. - The final Conditional format looks for files which have not changed since they - were created. Here the condition value is "=C2". The = sign means C2 is treated - as a formula, not literal text. Unlike the file age, we want the cell used to - change for each cell where the conditional format applies. The first cell in - the conditional format range is D2, which is compared against C2, then D3 is - compared against C3 and so on. A common mistake is to include the title row in - the range and accidentally apply conditional formatting to it, or to begin the - range at row 2 but use row 1 as the starting point for comparisons. - .Example - Add-ConditionalFormatting $ws.Cells["B:B"] GreaterThan 10000000 -Fore Red -Stop -Pri 1 - - This version shows the shortest syntax - the Address, Ruletype, and - Conditionvalue can be identified from their position, and ForegroundColor, - StopIfTrue and Priority can all be shortend. - - #> +Function Add-ConditionalFormatting { Param ( - #A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] [Parameter(Mandatory = $true, Position = 0)] [Alias("Range")] $Address , - #The worksheet where the format is to be applied [OfficeOpenXml.ExcelWorksheet]$WorkSheet , - #A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc. [Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 1)] [OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType , - #Text color for matching objects [Parameter(ParameterSetName = "NamedRule")] [Alias("ForegroundColour","FontColor")] $ForegroundColor, - #Color for databar type charts [Parameter(Mandatory = $true, ParameterSetName = "DataBar")] [Alias("DataBarColour")] $DataBarColor, - #One of the three-icon set types (e.g. Traffic Lights) [Parameter(Mandatory = $true, ParameterSetName = "ThreeIconSet")] [OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting3IconsSetType]$ThreeIconsSet, - #A four-icon set name [Parameter(Mandatory = $true, ParameterSetName = "FourIconSet")] [OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting4IconsSetType]$FourIconsSet, - #A five-icon set name [Parameter(Mandatory = $true, ParameterSetName = "FiveIconSet")] [OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting5IconsSetType]$FiveIconsSet, - #Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales [Parameter(ParameterSetName = "NamedRule")] [Parameter(ParameterSetName = "ThreeIconSet")] [Parameter(ParameterSetName = "FourIconSet")] [Parameter(ParameterSetName = "FiveIconSet")] [switch]$Reverse, - #A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" ) [Parameter(ParameterSetName = "NamedRule",Position = 2)] $ConditionValue, - #A second value for the conditions like "Between X and Y" [Parameter(ParameterSetName = "NamedRule",Position = 3)] $ConditionValue2, - #Background color for matching items [Parameter(ParameterSetName = "NamedRule")] $BackgroundColor, - #Background pattern for matching items [Parameter(ParameterSetName = "NamedRule")] [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::None , - #Secondary color when a background pattern requires it [Parameter(ParameterSetName = "NamedRule")] $PatternColor, - #Sets the numeric format for matching items [Parameter(ParameterSetName = "NamedRule")] $NumberFormat, - #Put matching items in bold face [Parameter(ParameterSetName = "NamedRule")] [switch]$Bold, - #Put matching items in italic [Parameter(ParameterSetName = "NamedRule")] [switch]$Italic, - #Underline matching items [Parameter(ParameterSetName = "NamedRule")] [switch]$Underline, - #Strikethrough text of matching items [Parameter(ParameterSetName = "NamedRule")] [switch]$StrikeThru, - #Prevent the processing of subsequent rules [Parameter(ParameterSetName = "NamedRule")] [switch]$StopIfTrue, - #Set the sequence for rule processing [int]$Priority, - #If specified pass the rule back to the caller to allow additional customization. [switch]$PassThru ) diff --git a/ExportedCommands/Add-ExcelChart.ps1 b/ExportedCommands/Add-ExcelChart.ps1 new file mode 100644 index 0000000..6f77258 --- /dev/null +++ b/ExportedCommands/Add-ExcelChart.ps1 @@ -0,0 +1,142 @@ + +function Add-ExcelChart { + [cmdletbinding(DefaultParameterSetName = 'Worksheet')] + [OutputType([OfficeOpenXml.Drawing.Chart.ExcelChart])] + param( + [Parameter(ParameterSetName = 'Worksheet', Mandatory = $true)] + [OfficeOpenXml.ExcelWorksheet]$Worksheet, + [Parameter(ParameterSetName = 'PivotTable', Mandatory = $true)] + [OfficeOpenXml.Table.PivotTable.ExcelPivotTable]$PivotTable , + [String]$Title, + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked", + [OfficeOpenXml.Drawing.Chart.eTrendLine[]]$ChartTrendLine, + $XRange, + $YRange, + [int]$Width = 500, + [int]$Height = 350, + [int]$Row = 0, + [int]$RowOffSetPixels = 10, + [int]$Column = 6, + [int]$ColumnOffSetPixels = 5, + [OfficeOpenXml.Drawing.Chart.eLegendPosition]$LegendPosition, + $LegendSize, + [Switch]$LegendBold, + [Switch]$NoLegend, + [Switch]$ShowCategory, + [Switch]$ShowPercent, + [String[]]$SeriesHeader, + [Switch]$TitleBold, + [Int]$TitleSize , + [String]$XAxisTitleText, + [Switch]$XAxisTitleBold, + $XAxisTitleSize , + [string]$XAxisNumberformat, + $XMajorUnit, + $XMinorUnit, + $XMaxValue, + $XMinValue, + [OfficeOpenXml.Drawing.Chart.eAxisPosition]$XAxisPosition , + [String]$YAxisTitleText, + [Switch]$YAxisTitleBold, + $YAxisTitleSize, + [string]$YAxisNumberformat, + $YMajorUnit, + $YMinorUnit, + $YMaxValue, + $YMinValue, + [OfficeOpenXml.Drawing.Chart.eAxisPosition]$YAxisPosition, + [Switch]$PassThru + ) + try { + if ($PivotTable) { + $Worksheet = $PivotTable.WorkSheet + $chart = $Worksheet.Drawings.AddChart(("Chart" + $PivotTable.Name ), $ChartType, $PivotTable) + } + else { + $ChartName = 'Chart' + (Split-Path -Leaf ([System.IO.path]::GetTempFileName())) -replace 'tmp|\.', '' + $chart = $Worksheet.Drawings.AddChart($ChartName, $ChartType) + $chartDefCount = @($YRange).Count + if ($chartDefCount -eq 1) { + $Series = $chart.Series.Add($YRange, $XRange) + if ($ChartTrendLine) { + if ($ChartType -notmatch "stacked|3D$|pie|Doughnut|Cone|Cylinder|Pyramid") { + foreach ($trendLine in $ChartTrendLine) { + $null = $Series.TrendLines.Add($trendLine) + } + } + else { + Write-Warning "Chart trend line is not supported for chart type: $ChartType" + } + } + if ($SeriesHeader) { $Series.Header = $SeriesHeader } + else { $Series.Header = 'Series 1' } + } + else { + for ($idx = 0; $idx -lt $chartDefCount; $idx += 1) { + if ($Yrange.count -eq $xrange.count) { + $Series = $chart.Series.Add($YRange[$idx], $XRange[$idx]) + } + else { + $Series = $chart.Series.Add($YRange[$idx], $XRange) + } + if ($SeriesHeader.Count -gt 0) { + if ($SeriesHeader[$idx] -match '^=') { $Series.HeaderAddress = $SeriesHeader[$idx] -replace '^=', '' } + else { $Series.Header = $SeriesHeader[$idx] } + } + else { $Series.Header = "Series $($idx)" } + } + } + } + if ($Title) { + $chart.Title.Text = $Title + if ($TitleBold) { $chart.Title.Font.Bold = $true } + if ($TitleSize) { $chart.Title.Font.Size = $TitleSize } + } + if ($NoLegend) { $chart.Legend.Remove() } + else { + if ($PSBoundParameters.ContainsKey('LegendPosition')) { $chart.Legend.Position = $LegendPosition } + if ($PSBoundParameters.ContainsKey('LegendBold')) { $chart.Legend.Font.Bold = [boolean]$LegendBold } + if ($LegendSize) { $chart.Legend.Font.Size = $LegendSize } + } + + if ($XAxisTitleText) { + $chart.XAxis.Title.Text = $XAxisTitleText + if ($PSBoundParameters.ContainsKey('XAxisTitleBold')) { + $chart.XAxis.Title.Font.Bold = [boolean]$XAxisTitleBold + } + if ($XAxisTitleSize) { $chart.XAxis.Title.Font.Size = $XAxisTitleSize } + } + if ($XAxisPosition) { Write-Warning "X-axis position is not being set propertly at the moment, parameter ignored" } + #$chart.ChartXml.chartSpace.chart.plotArea.catAx.axPos.val = $XAxisPosition.ToString().substring(0,1)} + if ($XMajorUnit) { $chart.XAxis.MajorUnit = $XMajorUnit } + if ($XMinorUnit) { $chart.XAxis.MinorUnit = $XMinorUnit } + if ($null -ne $XMinValue) { $chart.XAxis.MinValue = $XMinValue } + if ($null -ne $XMaxValue) { $chart.XAxis.MaxValue = $XMaxValue } + if ($XAxisNumberformat) { $chart.XAxis.Format = (Expand-NumberFormat $XAxisNumberformat) } + + if ($YAxisTitleText) { + $chart.YAxis.Title.Text = $YAxisTitleText + if ($PSBoundParameters.ContainsKey('YAxisTitleBold')) { + $chart.YAxis.Title.Font.Bold = [boolean]$YAxisTitleBold + } + if ($YAxisTitleSize) { $chart.YAxis.Title.Font.Size = $YAxisTitleSize } + } + if ($YAxisPosition) { Write-Warning "Y-axis position is not being set propertly at the moment, parameter ignored" } + #$chart.ChartXml.chartSpace.chart.plotArea.valAx.axPos.val= $YAxisPosition.ToString().substring(0,1)} + if ($YMajorUnit) { $chart.YAxis.MajorUnit = $YMajorUnit } + if ($YMinorUnit) { $chart.YAxis.MinorUnit = $YMinorUnit } + if ($null -ne $YMinValue) { $chart.YAxis.MinValue = $YMinValue } + if ($null -ne $YMaxValue) { $chart.YAxis.MaxValue = $YMaxValue } + if ($YAxisNumberformat) { $chart.YAxis.Format = (Expand-NumberFormat $YAxisNumberformat) } + if ($null -ne $chart.Datalabel) { + $chart.Datalabel.ShowCategory = [boolean]$ShowCategory + $chart.Datalabel.ShowPercent = [boolean]$ShowPercent + } + + $chart.SetPosition($Row, $RowOffsetPixels, $Column, $ColumnOffsetPixels) + $chart.SetSize($Width, $Height) + + if ($PassThru) { return $chart } + } + catch { Write-Warning -Message "Failed adding Chart to worksheet '$($WorkSheet).name': $_" } +} diff --git a/ExportedCommands/Add-ExcelDataValidationRule.ps1 b/ExportedCommands/Add-ExcelDataValidationRule.ps1 new file mode 100644 index 0000000..a98ba8f --- /dev/null +++ b/ExportedCommands/Add-ExcelDataValidationRule.ps1 @@ -0,0 +1,58 @@ +Function Add-ExcelDataValidationRule { + [CmdletBinding()] + Param( + [Parameter(ValueFromPipeline = $true,Position=0)] + [Alias("Address")] + $Range , + [OfficeOpenXml.ExcelWorksheet]$WorkSheet , + [ValidateSet('Any','Custom','DateTime','Decimal','Integer','List','TextLength','Time')] + $ValidationType, + [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]$Operator = [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]::equal , + $Value, + $Value2, + $Formula, + $Formula2, + $ValueSet, + [switch]$ShowErrorMessage, + [OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle]$ErrorStyle, + [String]$ErrorTitle, + [String]$ErrorBody, + [switch]$ShowPromptMessage, + [String]$PromptBody, + [String]$PromptTitle, + [String]$NoBlank + ) + if ($Range -is [Array]) { + $null = $PSBoundParameters.Remove("Range") + $Range | Add-ExcelDataValidationRule @PSBoundParameters + } + else { + #We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ] + if (-not $WorkSheet -and $Range.worksheet) {$WorkSheet = $Range.worksheet} + if ($Range.Address) {$Range = $Range.Address} + + if ($Range -isnot [string] -or -not $WorkSheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return} + #else we assume Range is a range. + + $validation = $WorkSheet.DataValidations."Add$ValidationType`Validation"($Range) + if ($validation.AllowsOperator) {$validation.Operator = $Operator} + if ($PSBoundParameters.ContainsKey('value')) { + $validation.Formula.Value = $Value + } + elseif ($Formula) {$validation.Formula.ExcelFormula = $Formula} + elseif ($ValueSet) {Foreach ($v in $ValueSet) {$validation.Formula.Values.Add($V)}} + if ($PSBoundParameters.ContainsKey('Value2')) { + $validation.Formula2.Value = $Value2 + } + elseif ($Formula2) {$validation.Formula2.ExcelFormula = $Formula} + $validation.ShowErrorMessage = [bool]$ShowErrorMessage + $validation.ShowInputMessage = [bool]$ShowPromptMessage + $validation.AllowBlank = -not $NoBlank + + if ($PromptTitle) {$validation.PromptTitle = $PromptTitle} + if ($ErrorTitle) {$validation.ErrorTitle = $ErrorTitle} + if ($PromptBody) {$validation.Prompt = $PromptBody} + if ($ErrorBody) {$validation.Error = $ErrorBody} + if ($ErrorStyle) {$validation.ErrorStyle = $ErrorStyle} + } + } diff --git a/ExportedCommands/Add-ExcelName.ps1 b/ExportedCommands/Add-ExcelName.ps1 new file mode 100644 index 0000000..93b8378 --- /dev/null +++ b/ExportedCommands/Add-ExcelName.ps1 @@ -0,0 +1,30 @@ +function Add-ExcelName { + [CmdletBinding()] + param( + #The range of cells to assign as a name. + [Parameter(Mandatory=$true)] + [OfficeOpenXml.ExcelRange]$Range, + #The name to assign to the range. If the name exists it will be updated to the new range. If no name is specified, the first cell in the range will be used as the name. + [String]$RangeName + ) + try { + $ws = $Range.Worksheet + if (-not $RangeName) { + $RangeName = $ws.Cells[$Range.Start.Address].Value + $Range = ($Range.Worksheet.cells[($range.start.row +1), $range.start.Column , $range.end.row, $range.end.column]) + } + if ($RangeName -match '\W') { + Write-Warning -Message "Range name '$RangeName' contains illegal characters, they will be replaced with '_'." + $RangeName = $RangeName -replace '\W','_' + } + if ($ws.names[$RangeName]) { + Write-verbose -Message "Updating Named range '$RangeName' to $($Range.FullAddressAbsolute)." + $ws.Names[$RangeName].Address = $Range.FullAddressAbsolute + } + else { + Write-verbose -Message "Creating Named range '$RangeName' as $($Range.FullAddressAbsolute)." + $null = $ws.Names.Add($RangeName, $Range) + } + } + catch {Write-Warning -Message "Failed adding named range '$RangeName' to worksheet '$($ws.Name)': $_" } +} diff --git a/ExportedCommands/Add-ExcelTable.ps1 b/ExportedCommands/Add-ExcelTable.ps1 new file mode 100644 index 0000000..5cb25ec --- /dev/null +++ b/ExportedCommands/Add-ExcelTable.ps1 @@ -0,0 +1,75 @@ +function Add-ExcelTable { + [CmdletBinding()] + [OutputType([OfficeOpenXml.Table.ExcelTable])] + param ( + [Parameter(Mandatory=$true)] + [OfficeOpenXml.ExcelRange]$Range, + [String]$TableName = "", + [OfficeOpenXml.Table.TableStyles]$TableStyle = 'Medium6', + [Switch]$ShowHeader , + [Switch]$ShowFilter, + [Switch]$ShowTotal, + [hashtable]$TotalSettings, + [Switch]$ShowFirstColumn, + [Switch]$ShowLastColumn, + [Switch]$ShowRowStripes, + [Switch]$ShowColumnStripes, + [Switch]$PassThru + ) + try { + if ($TableName -eq "" -or $null -eq $TableName) { + $tbl = $Range.Worksheet.Tables.Add($Range, "") + } + else { + if ([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress($TableName)) { + Write-Warning -Message "$TableName reads as an Excel address, and so is not allowed as a table name." + return + } + if ($TableName -notMatch '^[A-Z]') { + Write-Warning -Message "$TableName is not allowed as a table name because it does not begin with a letter." + return + } + if ($TableName -match "\W") { + Write-Warning -Message "At least one character in $TableName is illegal in a table name and will be replaced with '_' . " + $TableName = $TableName -replace '\W', '_' + } + $ws = $Range.Worksheet + #if the table exists in this worksheet, update it. + if ($ws.Tables[$TableName]) { + $tbl =$ws.Tables[$TableName] + $tbl.TableXml.table.ref = $Range.Address + Write-Verbose -Message "Re-defined table '$TableName', now at $($Range.Address)." + } + elseif ($ws.Workbook.Worksheets.Tables.Name -contains $TableName) { + Write-Warning -Message "The Table name '$TableName' is already used on a different worksheet." + return + } + else { + $tbl = $ws.Tables.Add($Range, $TableName) + Write-Verbose -Message "Defined table '$($tbl.Name)' at $($Range.Address)" + } + } + #it seems that show total changes some of the others, so the sequence matters. + if ($PSBoundParameters.ContainsKey('ShowHeader')) {$tbl.ShowHeader = [bool]$ShowHeader} + if ($PSBoundParameters.ContainsKey('TotalSettings')) { + $tbl.ShowTotal = $true + foreach ($k in $TotalSettings.keys) { + if (-not $tbl.Columns[$k]) {Write-Warning -Message "Table does not have a Column '$k'."} + elseif ($TotalSettings[$k] -notin @("Average", "Count", "CountNums", "Max", "Min", "None", "StdDev", "Sum", "Var") ) { + Write-Warning -Message "'$($TotalSettings[$k])' is not a valid total function." + } + else {$tbl.Columns[$k].TotalsRowFunction = $TotalSettings[$k]} + } + } + elseif ($PSBoundParameters.ContainsKey('ShowTotal')) {$tbl.ShowTotal = [bool]$ShowTotal} + if ($PSBoundParameters.ContainsKey('ShowFilter')) {$tbl.ShowFilter = [bool]$ShowFilter} + if ($PSBoundParameters.ContainsKey('ShowFirstColumn')) {$tbl.ShowFirstColumn = [bool]$ShowFirstColumn} + if ($PSBoundParameters.ContainsKey('ShowLastColumn')) {$tbl.ShowLastColumn = [bool]$ShowLastColumn} + if ($PSBoundParameters.ContainsKey('ShowRowStripes')) {$tbl.ShowRowStripes = [bool]$ShowRowStripes} + if ($PSBoundParameters.ContainsKey('ShowColumnStripes')) {$tbl.ShowColumnStripes = [bool]$ShowColumnStripes} + $tbl.TableStyle = $TableStyle + + if ($PassThru) {return $tbl} + } + catch {Write-Warning -Message "Failed adding table '$TableName' to worksheet '$WorksheetName': $_"} +} diff --git a/ExportedCommands/Add-PivotTable.ps1 b/ExportedCommands/Add-PivotTable.ps1 new file mode 100644 index 0000000..cd7fc46 --- /dev/null +++ b/ExportedCommands/Add-PivotTable.ps1 @@ -0,0 +1,176 @@ +function Add-PivotTable { + [cmdletbinding(defaultParameterSetName = 'ChartbyParams')] + [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] + param ( + [Parameter(Mandatory = $true)] + [string]$PivotTableName, + [OfficeOpenXml.ExcelAddressBase] + $Address, + $ExcelPackage, + $SourceWorkSheet, + $SourceRange, + $PivotRows, + $PivotData, + $PivotColumns, + $PivotFilter, + [Switch]$PivotDataToColumn, + [ValidateSet("Both", "Columns", "Rows", "None")] + [String]$PivotTotals = "Both", + [Switch]$NoTotalsInPivot, + [String]$GroupDateRow, + [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, + [String]$GroupNumericRow, + [double]$GroupNumericMin = 0 , + [double]$GroupNumericMax = [Double]::MaxValue , + [double]$GroupNumericInterval = 100 , + [string]$PivotNumberFormat, + [OfficeOpenXml.Table.TableStyles]$PivotTableStyle, + [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + $PivotChartDefinition, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$IncludePivotChart, + [Parameter(ParameterSetName = 'ChartbyParams')] + [String]$ChartTitle = "", + [Parameter(ParameterSetName = 'ChartbyParams')] + [int]$ChartHeight = 400 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [int]$ChartWidth = 600, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartRow = 0 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartColumn = 4, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartRowOffSetPixels = 0 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartColumnOffSetPixels = 0, + [Parameter(ParameterSetName = 'ChartbyParams')] + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$NoLegend, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$ShowCategory, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$ShowPercent, + [switch]$Activate, + [Switch]$PassThru + ) + if ($PivotTableName.length -gt 250) { + Write-warning -Message "PivotTable name will be truncated" + $PivotTableName = $PivotTableName.Substring(0, 250) + } + if ($Address) { + [OfficeOpenXml.ExcelWorksheet]$wsPivot = $address.Worksheet + } + else { + try { + if (-not $ExcelPackage) {Write-Warning -message "This combination of Parameters needs to include the ExcelPackage." ; return } + [OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-WorkSheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate + if ($wsPivot.Name -ne $PivotTableName) {Write-Warning -Message "The Worksheet name for the PivotTable does not match the table name '$PivotTableName'; probably because excess or illegal characters were removed." } + if ($PivotFilter) {$Address = $wsPivot.Cells["A3"]} else { $Address = $wsPivot.Cells["A1"]} + } + catch {throw "Could not create the sheet for the PivotTable. $_" } + } + #if the pivot doesn't exist, create it. + if (-not $wsPivot) {throw "There was a problem getting the worksheet for the PivotTable"} + if (-not $wsPivot.PivotTables[$pivotTableName] ) { + try { + #Accept a string or a worksheet object as $SourceWorksheet - we don't need a worksheet if we have a Rangebase . + if ( $SourceWorkSheet -is [string]) { + $SourceWorkSheet = $ExcelPackage.Workbook.Worksheets.where( {$_.name -Like $SourceWorkSheet})[0] + } + elseif ( $SourceWorkSheet -is [int] ) { + $SourceWorkSheet = $ExcelPackage.Workbook.Worksheets[$SourceWorkSheet] + } + if ( $SourceRange -is [OfficeOpenXml.Table.ExcelTable]) {$SourceRange = $SourceRange.Address } + if ( $sourceRange -is [OfficeOpenXml.ExcelRange] -or + $SourceRange -is [OfficeOpenXml.ExcelAddress]) { + $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceRange, $pivotTableName) + } + elseif (-not $SourceRange) { + $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.cells[$SourceWorkSheet.Dimension.Address], $pivotTableName) + } + elseif ($SourceWorkSheet -isnot [OfficeOpenXml.ExcelWorksheet] ) { + Write-Warning -Message "Could not find source Worksheet for pivot-table '$pivotTableName'." ; return + } + elseif ( $SourceRange -is [String] -or $SourceRange -is [OfficeOpenXml.ExcelAddress]) { + $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.Cells[$SourceRange], $pivotTableName) + } + else {Write-warning "Could not create a PivotTable with the Source Range provided."; return} + foreach ($Row in $PivotRows) { + try {$null = $pivotTable.RowFields.Add($pivotTable.Fields[$Row]) } + catch {Write-Warning -message "Could not add '$row' to Rows in PivotTable $pivotTableName." } + } + foreach ($Column in $PivotColumns) { + try {$null = $pivotTable.ColumnFields.Add($pivotTable.Fields[$Column])} + catch {Write-Warning -message "Could not add '$Column' to Columns in PivotTable $pivotTableName." } + } + if ($PivotData -is [HashTable] -or $PivotData -is [System.Collections.Specialized.OrderedDictionary]) { + $PivotData.Keys | ForEach-Object { + try { + $df = $pivotTable.DataFields.Add($pivotTable.Fields[$_]) + $df.Function = $PivotData.$_ + if ($PivotNumberFormat) {$df.Format = (Expand-NumberFormat -NumberFormat $PivotNumberFormat)} + } + catch {Write-Warning -message "Problem adding data fields to PivotTable $pivotTableName." } + } + } + else { + foreach ($field in $PivotData) { + try { + $df = $pivotTable.DataFields.Add($pivotTable.Fields[$field]) + $df.Function = 'Count' + } + catch {Write-Warning -message "Problem adding data field '$field' to PivotTable $pivotTableName." } + } + } + foreach ( $pFilter in $PivotFilter) { + try { $null = $pivotTable.PageFields.Add($pivotTable.Fields[$pFilter])} + catch {Write-Warning -message "Could not add '$pFilter' to Filter/Page fields in PivotTable $pivotTableName." } + } + if ($NoTotalsInPivot) {$PivotTotals = "None" } + if ($PivotTotals -eq "None" -or $PivotTotals -eq "Columns") { $pivotTable.RowGrandTotals = $false } + elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Rows") { $pivotTable.RowGrandTotals = $true } + if ($PivotTotals -eq "None" -or $PivotTotals -eq "Rows") { $pivotTable.ColumGrandTotals = $false } # Epplus spelling mistake, not mine! + elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Columns") { $pivotTable.ColumGrandTotals = $true } + if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false } + if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle} + if ($GroupNumericRow) { + $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupNumericRow }) + if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupNumericRow'; no numeric grouping will be done."} + else {$r.AddNumericGrouping($GroupNumericMin, $GroupNumericMax, $GroupNumericInterval)} + } + if ($GroupDateRow -and $PSBoundParameters.ContainsKey("GroupDatePart")) { + $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupDateRow }) + if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupDateRow'; no date grouping will be done."} + else {$r.AddDateGrouping($GroupDatePart)} + } + } + catch {Write-Warning -Message "Failed adding PivotTable '$pivotTableName': $_"} + } + else { + Write-Warning -Message "PivotTable defined in $($pivotTableName) already exists, only the data range will be changed." + $pivotTable = $wsPivot.PivotTables[$pivotTableName] + if (-not $SourceRange) { $SourceRange = $SourceWorkSheet.Dimension.Address} + $pivotTable.CacheDefinition.SourceRange = $SourceWorkSheet.cells[$SourceRange] + #change for epPlus 4.5 - Previously needed to hack the xml + # $pivotTable.CacheDefinition.CacheDefinitionXml.pivotCacheDefinition.cacheSource.worksheetSource.ref = $SourceRange + + } + + #Create the chart if it doesn't exist, leave alone if it does. + if ($IncludePivotChart -and -not $wsPivot.Drawings["Chart$pivotTableName"] ) { + try {Add-ExcelChart -PivotTable $pivotTable -ChartType $ChartType -Width $ChartWidth -Height $ChartHeight -Row $ChartRow -Column $ChartColumn -RowOffSetPixels $ChartRowOffSetPixels -ColumnOffSetPixels $ChartColumnOffSetPixels -Title $ChartTitle -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent } + catch {Write-Warning -Message "Failed adding chart for pivotable '$pivotTableName': $_"} + } + elseif ($PivotChartDefinition -and -not $wsPivot.Drawings["Chart$pivotTableName"]) { + if ($PivotChartDefinition -is [System.Management.Automation.PSCustomObject]) { + $params = @{PivotTable = $pivotTable } + $PivotChartDefinition.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}} + Add-ExcelChart @params + } + elseif ($PivotChartDefinition -is [hashtable] -or $PivotChartDefinition -is [System.Collections.Specialized.OrderedDictionary]) { + Add-ExcelChart -PivotTable $pivotTable @PivotChartDefinition + } + } + if ($PassThru) {return $pivotTable} +} diff --git a/ExportedCommands/Add-Worksheet.ps1 b/ExportedCommands/Add-Worksheet.ps1 new file mode 100644 index 0000000..0a025ab --- /dev/null +++ b/ExportedCommands/Add-Worksheet.ps1 @@ -0,0 +1,80 @@ +function Add-Worksheet { + [cmdletBinding()] + [OutputType([OfficeOpenXml.ExcelWorksheet])] + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = "Package", Position = 0)] + [OfficeOpenXml.ExcelPackage]$ExcelPackage, + [Parameter(Mandatory = $true, ParameterSetName = "WorkBook")] + [OfficeOpenXml.ExcelWorkbook]$ExcelWorkbook, + [string]$WorksheetName , + [switch]$ClearSheet, + [Switch]$MoveToStart, + [Switch]$MoveToEnd, + $MoveBefore , + $MoveAfter , + [switch]$Activate, + [OfficeOpenXml.ExcelWorksheet]$CopySource, + [parameter(DontShow=$true)] + [Switch] $NoClobber + ) + #if we were given a workbook use it, if we were given a package, use its workbook + if ($ExcelPackage -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelPackage.Workbook} + + # If WorksheetName was given, try to use that worksheet. If it wasn't, and we are copying an existing sheet, try to use the sheet name + # If we are not copying a sheet, and have no name, use the name "SheetX" where X is the number of the new sheet + if (-not $WorksheetName -and $CopySource -and -not $ExcelWorkbook[$CopySource.Name]) {$WorksheetName = $CopySource.Name} + elseif (-not $WorksheetName) {$WorksheetName = "Sheet" + (1 + $ExcelWorkbook.Worksheets.Count)} + else {$ws = $ExcelWorkbook.Worksheets[$WorksheetName]} + + #If -clearsheet was specified and the named sheet exists, delete it + if ($ws -and $ClearSheet) { $ExcelWorkbook.Worksheets.Delete($WorksheetName) ; $ws = $null } + + #Copy or create new sheet as needed + if (-not $ws -and $CopySource) { + Write-Verbose -Message "Copying into worksheet '$WorksheetName'." + $ws = $ExcelWorkbook.Worksheets.Add($WorksheetName, $CopySource) + } + elseif (-not $ws) { + $ws = $ExcelWorkbook.Worksheets.Add($WorksheetName) + Write-Verbose -Message "Adding worksheet '$WorksheetName'." + } + else {Write-Verbose -Message "Worksheet '$WorksheetName' already existed."} + #region Move sheet if needed + if ($MoveToStart) {$ExcelWorkbook.Worksheets.MoveToStart($WorksheetName) } + elseif ($MoveToEnd ) {$ExcelWorkbook.Worksheets.MoveToEnd($WorksheetName) } + elseif ($MoveBefore ) { + if ($ExcelWorkbook.Worksheets[$MoveBefore]) { + if ($MoveBefore -is [int]) { + $ExcelWorkbook.Worksheets.MoveBefore($ws.Index, $MoveBefore) + } + else {$ExcelWorkbook.Worksheets.MoveBefore($WorksheetName, $MoveBefore)} + } + else {Write-Warning "Can't find worksheet '$MoveBefore'; worsheet '$WorksheetName' will not be moved."} + } + elseif ($MoveAfter ) { + if ($MoveAfter -eq "*") { + if ($WorksheetName -lt $ExcelWorkbook.Worksheets[1].Name) {$ExcelWorkbook.Worksheets.MoveToStart($WorksheetName)} + else { + $i = 1 + While ($i -lt $ExcelWorkbook.Worksheets.Count -and ($ExcelWorkbook.Worksheets[$i + 1].Name -le $WorksheetName) ) { $i++} + $ExcelWorkbook.Worksheets.MoveAfter($ws.Index, $i) + } + } + elseif ($ExcelWorkbook.Worksheets[$MoveAfter]) { + if ($MoveAfter -is [int]) { + $ExcelWorkbook.Worksheets.MoveAfter($ws.Index, $MoveAfter) + } + else { + $ExcelWorkbook.Worksheets.MoveAfter($WorksheetName, $MoveAfter) + } + } + else {Write-Warning "Can't find worksheet '$MoveAfter'; worsheet '$WorksheetName' will not be moved."} + } + #endregion + if ($Activate) {Select-Worksheet -ExcelWorksheet $ws } + if ($ExcelPackage -and -not (Get-Member -InputObject $ExcelPackage -Name $ws.Name)) { + $sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $ws.name)) + Add-Member -InputObject $ExcelPackage -MemberType ScriptProperty -Name $ws.name -Value $sb + } + return $ws +} diff --git a/ExportedCommands/Close-ExcelPackage.ps1 b/ExportedCommands/Close-ExcelPackage.ps1 new file mode 100644 index 0000000..d49425e --- /dev/null +++ b/ExportedCommands/Close-ExcelPackage.ps1 @@ -0,0 +1,34 @@ + +Function Close-ExcelPackage { + [CmdLetBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] + Param ( + [parameter(Mandatory=$true, ValueFromPipeline=$true)] + [OfficeOpenXml.ExcelPackage]$ExcelPackage, + [switch]$Show, + [Switch]$NoSave, + $SaveAs, + [ValidateNotNullOrEmpty()] + [String]$Password, + [switch]$Calculate + ) + if ( $NoSave) {$ExcelPackage.Dispose()} + else { + if ($Calculate) { + try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) } + Catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."} + } + if ($SaveAs) { + $SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs) + if ($Password) {$ExcelPackage.SaveAs( $SaveAs, $Password ) } + else {$ExcelPackage.SaveAs( $SaveAs)} + } + else { + if ($Password) {$ExcelPackage.Save($Password) } + else {$ExcelPackage.Save() } + $SaveAs = $ExcelPackage.File.FullName + } + $ExcelPackage.Dispose() + if ($Show) {Start-Process -FilePath $SaveAs } + } +} diff --git a/Compare-WorkSheet.ps1 b/ExportedCommands/Compare-WorkSheet.ps1 similarity index 68% rename from Compare-WorkSheet.ps1 rename to ExportedCommands/Compare-WorkSheet.ps1 index fb8edf6..8d478ed 100644 --- a/Compare-WorkSheet.ps1 +++ b/ExportedCommands/Compare-WorkSheet.ps1 @@ -1,116 +1,29 @@ Function Compare-WorkSheet { -<# - .Synopsis - Compares two worksheets and shows the differences. - .Description - This command takes two file names, one or two worksheet names and a name - for a "key" column. It reads the worksheet from each file and decides the - column names and builds a hashtable of the key-column values and the - rows in which they appear. - It then uses PowerShell's Compare-Object command to compare the sheets - (explicitly checkingall the column names which have not been excluded). - For the difference rows it adds the row number for the key of that row - - we have to add the key after doing the comparison, otherwise identical - rows at different positions in the file will not be considered a match. - We also add the name of the file and sheet in which the difference occurs. - If -BackgroundColor is specified the difference rows will be changed to - that background in the orginal file. - .Example - Compare-WorkSheet -Referencefile 'Server56.xlsx' -Differencefile 'Server57.xlsx' -WorkSheetName Products -key IdentifyingNumber -ExcludeProperty Install* | Format-Table - - The two workbooks in this example contain the result of redirecting a subset - of properties from Get-WmiObject -Class win32_product to Export-Excel. - The command compares the "Products" pages in the two workbooks, but we - don't want to register a difference if the software was installed on a - different date or from a different place, and excluding Install* removes - InstallDate and InstallSource. This data doesn't have a "Name" column, so - we specify the "IdentifyingNumber" column as the key. - The results will be presented as a table. - .Example - Compare-WorkSheet "Server54.xlsx" "Server55.xlsx" -WorkSheetName Services -GridView - - This time two workbooks contain the result of redirecting the command - Get-WmiObject -Class win32_service to Export-Excel. Here the -Differencefile - and -Referencefile parameter switches are assumed and the default setting for - -Key ("Name") works for services. This will display the differences between - the "Services" sheets using a grid view - .Example - Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen - - This version of the command outputs the differences between the "services" pages and highlights any different rows in the spreadsheet files. - .Example - Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen -FontColor Red -Show - - This example builds on the previous one: this time where two changed rows have - the value in the "Name" column (the default value for -Key), this version adds - highlighting of the changed cells in red; and then opens the Excel file. - .Example - Compare-WorkSheet 'Pester-tests.xlsx' 'Pester-tests.xlsx' -WorkSheetName 'Server1','Server2' -Property "full Description","Executed","Result" -Key "full Description" - - This time the reference file and the difference file are the same file and - two different sheets are used. Because the tests include the machine name - and time the test was run, the command specifies that a limited set of - columns should be used. - .Example - Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -GridView -ExcludeDifferent - - The "General" page in the two workbooks has a title and two unlabelled columns - with a row each for CPU, Memory, Domain, Disk and so on. So the command is - told to start at row 2 in order to skip the title and given names for the - columns: the first is "label" and the second "Value"; the label acts as the key. - This time we are interested in those rows which are the same in both sheets, - and the result is displayed using grid view. - Note that grid view works best when the number of columns is small. - .Example - Compare-WorkSheet 'Server1.xlsx' 'Server2.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -BackgroundColor White -Show -AllDataBackgroundColor LightGray - - This version of the previous command highlights all the cells in LightGray - and then sets the changed rows back to white. - Only the unchanged rows are highlighted. -#> [cmdletbinding(DefaultParameterSetName)] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] Param( - #First file to compare. [parameter(Mandatory=$true,Position=0)] $Referencefile , - #Second file to compare. [parameter(Mandatory=$true,Position=1)] $Differencefile , - #Name(s) of worksheets to compare. $WorkSheetName = "Sheet1", - #Properties to include in the comparison - supports wildcards, default is "*". $Property = "*" , - #Properties to exclude from the comparison - supports wildcards. $ExcludeProperty , - #Specifies custom property names to use, instead of the values defined in the starting row of the sheet. [Parameter(ParameterSetName='B', Mandatory)] [String[]]$Headername, - #Automatically generate property names (P1, P2, P3 ...) instead of the using the values the starting row of the sheet. [Parameter(ParameterSetName='C', Mandatory)] [switch]$NoHeader, - #The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. [int]$Startrow = 1, - #If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. $AllDataBackgroundColor, - #If specified, highlights the rows with differences. $BackgroundColor, - #If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). $TabColor, - #Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". $Key = "Name" , - #If specified, highlights the DIFF columns in rows which have the same key. $FontColor, - #If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). [Switch]$Show, - #If specified, the command tries to the show the DIFF in a Grid-View and not on the console. (unless-PassThru is also specified). This works best with few columns selected, and requires a key. [switch]$GridView, - #If specifieda full set of DIFF data is returned without filtering to the specified properties. [Switch]$PassThru, - #If specified the result will include equal rows as well. By default only different rows are returned. [Switch]$IncludeEqual, - #If specified, the result includes only the rows where both are equal. [Switch]$ExcludeDifferent ) diff --git a/ConvertExcelToImageFile.ps1 b/ExportedCommands/Convert-ExcelRangeToImage.ps1 similarity index 69% rename from ConvertExcelToImageFile.ps1 rename to ExportedCommands/Convert-ExcelRangeToImage.ps1 index 08efd46..988a931 100644 --- a/ConvertExcelToImageFile.ps1 +++ b/ExportedCommands/Convert-ExcelRangeToImage.ps1 @@ -1,28 +1,12 @@ -Function Convert-XlRangeToImage { - <# - .Synopsis - Gets the specified part of an Excel file and exports it as an image - .Description - Excel allows charts to be exported directly to a file, but can't do this with the rest of a sheet. To work round this this function - * Opens a copy of Excel and loads a file - * Selects a worksheet and then a range of cells in that worksheet - * Copies the select to the clipboard - * Saves the clipboard contents as an image file (it will save as .JPG unless the file name ends .BMP or .PNG) - * Copies a single cell to the clipboard (to prevent the "you have put a lot in the clipboard" message appearing) - * Closes Excel - #> +Function Convert-ExcelRangeToImage { + [alias("Convert-XlRangeToImage")] Param ( - #Path to the Excel file [parameter(Mandatory=$true)] $Path, - #Worksheet name - if none is specified "Sheet1" will be assumed $workSheetname = "Sheet1" , - #Range of cells within the sheet, e.g "A1:Z99" [parameter(Mandatory=$true)] $range, - #A bmp, png or jpg file where the result will be saved $destination = "$pwd\temp.png", - #If specified opens the image in the default viewer. [switch]$show ) $extension = $destination -replace '^.*\.(\w+)$' ,'$1' @@ -67,8 +51,8 @@ Add-ConditionalFormatting -WorkSheet $workSheet -Range "b2:B1000" -RuleType Grea Export-Excel -ExcelPackage $excelPackage -WorkSheetname $workSheetname -Convert-XlRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show +Convert-ExcelRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show #> -#Convert-XlRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show \ No newline at end of file +#Convert-ExcelRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show \ No newline at end of file diff --git a/ExportedCommands/ConvertFrom-ExcelData.md b/ExportedCommands/ConvertFrom-ExcelData.md new file mode 100644 index 0000000..95a8520 --- /dev/null +++ b/ExportedCommands/ConvertFrom-ExcelData.md @@ -0,0 +1,161 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# ConvertFrom-ExcelData + +## SYNOPSIS +Reads data from a sheet, and for each row, calls a custom scriptblock with a list of property names and the row of data. + +## SYNTAX + +``` +ConvertFrom-ExcelData [-Path] [[-scriptBlock] ] [[-WorkSheetname] ] + [[-HeaderRow] ] [[-Header] ] [-NoHeader] [-DataOnly] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### EXAMPLE 1 +``` +ConvertFrom-ExcelData .\testSQLGen.xlsx { +``` + +param($propertyNames, $record) + + $reportRecord = @() + foreach ($pn in $propertyNames) { + $reportRecord += "{0}: {1}" -f $pn, $record.$pn + } + $reportRecord +="" + $reportRecord -join "\`r\`n" +} + +First: John +Last: Doe +The Zip: 12345 +.... + +## PARAMETERS + +### -Path +{{ Fill Path Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: FullName + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -scriptBlock +{{ Fill scriptBlock Description }} + +```yaml +Type: ScriptBlock +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheetname +{{ Fill WorkSheetname Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Sheet + +Required: False +Position: 3 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HeaderRow +{{ Fill HeaderRow Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Header +{{ Fill Header Description }} + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +{{ Fill NoHeader Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataOnly +{{ Fill DataOnly Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/ConvertFromExcelData.ps1 b/ExportedCommands/ConvertFrom-ExcelData.ps1 similarity index 58% rename from ConvertFromExcelData.ps1 rename to ExportedCommands/ConvertFrom-ExcelData.ps1 index 6b18fc1..536c703 100644 --- a/ConvertFromExcelData.ps1 +++ b/ExportedCommands/ConvertFrom-ExcelData.ps1 @@ -1,26 +1,5 @@ function ConvertFrom-ExcelData { - <# - .SYNOPSIS - Reads data from a sheet, and for each row, calls a custom scriptblock with a list of property names and the row of data. - - - .EXAMPLE - ConvertFrom-ExcelData .\testSQLGen.xlsx { - param($propertyNames, $record) - - $reportRecord = @() - foreach ($pn in $propertyNames) { - $reportRecord += "{0}: {1}" -f $pn, $record.$pn - } - $reportRecord +="" - $reportRecord -join "`r`n" - } - - First: John - Last: Doe - The Zip: 12345 - .... - #> + [alias("Use-ExcelData")] param( [Alias("FullName")] [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true, Mandatory = $true)] diff --git a/ExportedCommands/ConvertFrom-ExcelSheet.md b/ExportedCommands/ConvertFrom-ExcelSheet.md new file mode 100644 index 0000000..b91972c --- /dev/null +++ b/ExportedCommands/ConvertFrom-ExcelSheet.md @@ -0,0 +1,140 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# ConvertFrom-ExcelSheet + +## SYNOPSIS +Reads an Excel file an converts the data to a delimited text file. + +## SYNTAX + +``` +ConvertFrom-ExcelSheet [-Path] [[-OutputPath] ] [[-SheetName] ] [[-Encoding] ] + [[-Extension] ] [[-Delimiter] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### EXAMPLE 1 +``` +ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data +``` + +Reads each sheet in TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt. + +### EXAMPLE 2 +``` +ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data sheet?0 +``` + +Reads and outputs sheets like Sheet10 and Sheet20 form TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt. + +## PARAMETERS + +### -Path +{{ Fill Path Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: FullName + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputPath +{{ Fill OutputPath Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: .\ +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SheetName +{{ Fill SheetName Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Encoding +{{ Fill Encoding Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: UTF8 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Extension +{{ Fill Extension Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: .csv +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Delimiter +{{ Fill Delimiter Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: ; +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/ExportedCommands/ConvertFrom-ExcelSheet.ps1 b/ExportedCommands/ConvertFrom-ExcelSheet.ps1 new file mode 100644 index 0000000..2c997af --- /dev/null +++ b/ExportedCommands/ConvertFrom-ExcelSheet.ps1 @@ -0,0 +1,48 @@ +function ConvertFrom-ExcelSheet { + [CmdletBinding()] + param + ( + [Alias("FullName")] + [Parameter(Mandatory = $true)] + [String] + $Path, + [String] + $OutputPath = '.\', + [String] + $SheetName = "*", + [ValidateSet('ASCII', 'BigEndianUniCode', 'Default', 'OEM', 'UniCode', 'UTF32', 'UTF7', 'UTF8')] + [string] + $Encoding = 'UTF8', + [ValidateSet('.txt', '.log', '.csv')] + [string] + $Extension = '.csv', + [ValidateSet(';', ',')] + [string] + $Delimiter = ';' + ) + + $Path = (Resolve-Path $Path).Path + $Stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, "Open", "Read", "ReadWrite" + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Stream + $workbook = $xl.Workbook + + $targetSheets = $workbook.Worksheets | Where-Object { $_.Name -like $SheetName } + + $params = @{ } + $PSBoundParameters + $params.Remove("OutputPath") + $params.Remove("SheetName") + $params.Remove('Extension') + $params.NoTypeInformation = $true + + Foreach ($sheet in $targetSheets) { + Write-Verbose "Exporting sheet: $($sheet.Name)" + + $params.Path = "$OutputPath\$($Sheet.Name)$Extension" + + Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params + } + + $Stream.Close() + $Stream.Dispose() + $xl.Dispose() +} diff --git a/ExportedCommands/ConvertFrom-ExcelToSQLInsert.ps1 b/ExportedCommands/ConvertFrom-ExcelToSQLInsert.ps1 new file mode 100644 index 0000000..bd2fda0 --- /dev/null +++ b/ExportedCommands/ConvertFrom-ExcelToSQLInsert.ps1 @@ -0,0 +1,48 @@ +function ConvertFrom-ExcelToSQLInsert { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + $TableName, + [Alias("FullName")] + [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true, Mandatory = $true)] + [ValidateScript( { Test-Path $_ -PathType Leaf })] + $Path, + [Alias("Sheet")] + $WorkSheetname = 1, + [Alias('HeaderRow', 'TopRow')] + [ValidateRange(1, 9999)] + [Int]$StartRow, + [string[]]$Header, + [switch]$NoHeader, + [switch]$DataOnly, + [switch]$ConvertEmptyStringsToNull, + [switch]$UseMSSQLSyntax + ) + + $null = $PSBoundParameters.Remove('TableName') + $null = $PSBoundParameters.Remove('ConvertEmptyStringsToNull') + $null = $PSBoundParameters.Remove('UseMSSQLSyntax') + + $params = @{} + $PSBoundParameters + + ConvertFrom-ExcelData @params { + param($propertyNames, $record) + + $ColumnNames = "'" + ($PropertyNames -join "', '") + "'" + if($UseMSSQLSyntax) { + $ColumnNames = "[" + ($PropertyNames -join "], [") + "]" + } + + $values = foreach ($propertyName in $PropertyNames) { + if ($ConvertEmptyStringsToNull.IsPresent -and [string]::IsNullOrEmpty($record.$propertyName)) { + 'NULL' + } + else { + "'" + $record.$propertyName + "'" + } + } + $targetValues = ($values -join ", ") + + "INSERT INTO {0} ({1}) Values({2});" -f $TableName, $ColumnNames, $targetValues + } +} \ No newline at end of file diff --git a/ExportedCommands/ConvertTo-ExcelXlsx.md b/ExportedCommands/ConvertTo-ExcelXlsx.md new file mode 100644 index 0000000..99178e7 --- /dev/null +++ b/ExportedCommands/ConvertTo-ExcelXlsx.md @@ -0,0 +1,72 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# ConvertTo-ExcelXlsx + +## SYNOPSIS +Converts an Excel xls to a xlsx using -ComObject + +## SYNTAX + +``` +ConvertTo-ExcelXlsx [-Path] [-Force] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Path +{{ Fill Path Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Force +{{ Fill Force Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/ConvertToExcelXlsx.ps1 b/ExportedCommands/ConvertTo-ExcelXlsx.ps1 similarity index 94% rename from ConvertToExcelXlsx.ps1 rename to ExportedCommands/ConvertTo-ExcelXlsx.ps1 index f280a4c..21ef2f3 100644 --- a/ConvertToExcelXlsx.ps1 +++ b/ExportedCommands/ConvertTo-ExcelXlsx.ps1 @@ -1,8 +1,4 @@ Function ConvertTo-ExcelXlsx { - <# - .SYNOPSIS - Converts an Excel xls to a xlsx using -ComObject - #> [CmdletBinding()] Param ( diff --git a/Copy-ExcelWorkSheet.ps1 b/ExportedCommands/Copy-ExcelWorkSheet.ps1 similarity index 68% rename from Copy-ExcelWorkSheet.ps1 rename to ExportedCommands/Copy-ExcelWorkSheet.ps1 index d6ada62..ca79a29 100644 --- a/Copy-ExcelWorkSheet.ps1 +++ b/ExportedCommands/Copy-ExcelWorkSheet.ps1 @@ -1,48 +1,13 @@ function Copy-ExcelWorkSheet { - <# - .SYNOPSIS - Copies a worksheet between workbooks or within the same workbook. - .DESCRIPTION - Copy-ExcelWorkSheet takes a Source object which is either a worksheet, - or a package, Workbook or path, in which case the source worksheet can be specified - by name or number (starting from 1). - The destination worksheet can be explicitly named, or will follow the name of the source if no name is specified. - The Destination workbook can be given as the path to an XLSx file, an ExcelPackage object or an ExcelWorkbook object. - - .EXAMPLE - C:\> Copy-ExcelWorkSheet -SourceWorkbook Test1.xlsx -DestinationWorkbook Test2.xlsx - This is the simplest version of the command: no source worksheet is specified so Copy-ExcelWorksheet uses the first sheet in the workbook - No Destination sheet is specified so the new worksheet will be the same as the one which is being copied. - .EXAMPLE - C:\> Copy-ExcelWorkSheet -SourceWorkbook Server1.xlsx -sourceWorksheet "Settings" -DestinationWorkbook Settings.xlsx -DestinationWorksheet "Server1" - Here the Settings page from Server1's workbook is copied to the 'Server1" page of a "Settings" workbook. - .EXAMPLE - C:\> $excel = Open-ExcelPackage .\test.xlsx - C:\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet "first" -DestinationWorkbook $excel -Show -DestinationWorksheet Duplicate - This opens the workbook test.xlsx and copies the worksheet named "first" to a new worksheet named "Duplicate", - because -Show is specified the file is saved and opened in Excel - .EXAMPLE - C:\> $excel = Open-ExcelPackage .\test.xlsx - C:\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet 1 -DestinationWorkbook $excel -DestinationWorksheet Duplicate - C:\> Close-ExcelPackage $excel - This is almost the same as the previous example, except source sheet is specified by position rather than name and - because -Show is not specified, so other steps can be carried using the package object, at the end the file is saved by Close-ExcelPackage - - #> [CmdletBinding()] param( - #An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found. [Parameter(Mandatory = $true,ValueFromPipeline=$true)] [Alias('SourceWorkbook')] $SourceObject, - #Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1). $SourceWorkSheet = 1 , - #An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied. [Parameter(Mandatory = $true)] $DestinationWorkbook, - #Name of the worksheet in the destination workbook; by default the same as the source worksheet's name. If the sheet exists it will be deleted and re-copied. $DestinationWorksheet, - #if the destination is an excel package or a path, launch excel and open the file on completion. [Switch]$Show ) begin { diff --git a/ExportedCommands/Expand-NumberFormat.ps1 b/ExportedCommands/Expand-NumberFormat.ps1 new file mode 100644 index 0000000..2027f47 --- /dev/null +++ b/ExportedCommands/Expand-NumberFormat.ps1 @@ -0,0 +1,77 @@ + +function Expand-NumberFormat { + <# + .SYNOPSIS + Converts short names for number formats to the formatting strings used in Excel + .DESCRIPTION + Where you can type a number format you can write, for example, 'Short-Date' + and the module will translate it into the format string used by Excel. + Some formats, like Short-Date change how they are presented when Excel + loads (so date will use the local ordering of year, month and Day). Other + formats change how they appear when loaded with different cultures + (depending on the country "," or "." or " " may be the thousand seperator + although Excel always stores it as ",") + .EXAMPLE + Expand-NumberFormat percentage + + Returns "0.00%" + .EXAMPLE + Expand-NumberFormat Currency + + Returns the currency format specified in the local regional settings. This + may not be the same as Excel uses. The regional settings set the currency + symbol and then whether it is before or after the number and separated with + a space or not; for negative numbers the number may be wrapped in parentheses + or a - sign might appear before or after the number and symbol. + So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00- + for French. (Note some Eurozone countries write €1,23 and others 1,23€ ) + In French the decimal point will be rendered as a "," and the thousand + separator as a space. + #> + [cmdletbinding()] + [OutputType([String])] + param ( + #the format string to Expand + $NumberFormat + ) + switch ($NumberFormat) { + "Currency" { + #https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern(v=vs.110).aspx + $sign = [cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol + switch ([cultureinfo]::CurrentCulture.NumberFormat.CurrencyPositivePattern) { + 0 {$pos = "$Sign#,##0.00" ; break } + 1 {$pos = "#,##0.00$Sign" ; break } + 2 {$pos = "$Sign #,##0.00" ; break } + 3 {$pos = "#,##0.00 $Sign" ; break } + } + switch ([cultureinfo]::CurrentCulture.NumberFormat.CurrencyPositivePattern) { + 0 {return "$pos;($Sign#,##0.00)" } + 1 {return "$pos;-$Sign#,##0.00" } + 2 {return "$pos;$Sign-#,##0.00" } + 3 {return "$pos;$Sign#,##0.00-" } + 4 {return "$pos;(#,##0.00$Sign)" } + 5 {return "$pos;-#,##0.00$Sign" } + 6 {return "$pos;#,##0.00-$Sign" } + 7 {return "$pos;#,##0.00$Sign-" } + 8 {return "$pos;-#,##0.00 $Sign" } + 9 {return "$pos;-$Sign #,##0.00" } + 10 {return "$pos;#,##0.00 $Sign-" } + 11 {return "$pos;$Sign #,##0.00-" } + 12 {return "$pos;$Sign -#,##0.00" } + 13 {return "$pos;#,##0.00- $Sign" } + 14 {return "$pos;($Sign #,##0.00)" } + 15 {return "$pos;(#,##0.00 $Sign)" } + } + } + "Number" {return "0.00" } # format id 2 + "Percentage" {return "0.00%" } # format id 10 + "Scientific" {return "0.00E+00" } # format id 11 + "Fraction" {return "# ?/?" } # format id 12 + "Short Date" {return "mm-dd-yy" } # format id 14 localized on load by Excel. + "Short Time" {return "h:mm" } # format id 20 localized on load by Excel. + "Long Time" {return "h:mm:ss" } # format id 21 localized on load by Excel. + "Date-Time" {return "m/d/yy h:mm"} # format id 22 localized on load by Excel. + "Text" {return "@" } # format ID 49 + Default {return $NumberFormat} + } +} diff --git a/ExportedCommands/Export-Excel.ps1 b/ExportedCommands/Export-Excel.ps1 new file mode 100644 index 0000000..2659470 --- /dev/null +++ b/ExportedCommands/Export-Excel.ps1 @@ -0,0 +1,670 @@ +function Export-Excel { + [CmdletBinding(DefaultParameterSetName = 'Default')] + [OutputType([OfficeOpenXml.ExcelPackage])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] + Param( + [Parameter(ParameterSetName = 'Default', Position = 0)] + [String]$Path, + [Parameter(Mandatory = $true, ParameterSetName = "Package")] + [OfficeOpenXml.ExcelPackage]$ExcelPackage, + [Parameter(ValueFromPipeline = $true)] + [Alias('TargetData')] + $InputObject, + [Switch]$Calculate, + [Switch]$Show, + [String]$WorksheetName = 'Sheet1', + [Alias("P")] + [String]$Password, + [switch]$ClearSheet, + [switch]$Append, + [String]$Title, + [OfficeOpenXml.Style.ExcelFillStyle]$TitleFillPattern = 'Solid', + [Switch]$TitleBold, + [Int]$TitleSize = 22, + $TitleBackgroundColor, + [Switch]$IncludePivotTable, + [String]$PivotTableName, + [String[]]$PivotRows, + [String[]]$PivotColumns, + $PivotData, + [String[]]$PivotFilter, + [Switch]$PivotDataToColumn, + [Hashtable]$PivotTableDefinition, + [Switch]$IncludePivotChart, + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', + [Switch]$NoLegend, + [Switch]$ShowCategory, + [Switch]$ShowPercent, + [Switch]$AutoSize, + $MaxAutoSizeRows = 1000, + [Switch]$NoClobber, + [Switch]$FreezeTopRow, + [Switch]$FreezeFirstColumn, + [Switch]$FreezeTopRowFirstColumn, + [Int[]]$FreezePane, + [Switch]$AutoFilter, + [Switch]$BoldTopRow, + [Switch]$NoHeader, + [ValidateScript( { + if (-not $_) { throw 'RangeName is null or empty.' } + elseif ($_[0] -notmatch '[a-z]') { throw 'RangeName starts with an invalid character.' } + else { $true } + })] + [String]$RangeName, + [Alias('Table')] + $TableName, + [OfficeOpenXml.Table.TableStyles]$TableStyle = [OfficeOpenXml.Table.TableStyles]::Medium6, + [Switch]$Barchart, + [Switch]$PieChart, + [Switch]$LineChart , + [Switch]$ColumnChart , + [Object[]]$ExcelChartDefinition, + [String[]]$HideSheet, + [String[]]$UnHideSheet, + [Switch]$MoveToStart, + [Switch]$MoveToEnd, + $MoveBefore , + $MoveAfter , + [Switch]$KillExcel, + [Switch]$AutoNameRange, + [Int]$StartRow = 1, + [Int]$StartColumn = 1, + [alias('PT')] + [Switch]$PassThru, + [String]$Numberformat = 'General', + [string[]]$ExcludeProperty, + [Switch]$NoAliasOrScriptPropeties, + [Switch]$DisplayPropertySet, + [String[]]$NoNumberConversion, + [Object[]]$ConditionalFormat, + [Object[]]$ConditionalText, + [Object[]]$Style, + [ScriptBlock]$CellStyleSB, + #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified + [switch]$Activate, + [Parameter(ParameterSetName = 'Default')] + [Switch]$Now, + [Switch]$ReturnRange, + #By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + [ValidateSet("Both","Columns","Rows","None")] + [String]$PivotTotals = "Both", + #Included for compatibility - equivalent to -PivotTotals "None" + [Switch]$NoTotalsInPivot, + [Switch]$ReZip + ) + + begin { + $numberRegex = [Regex]'\d' + $isDataTypeValueType = $false + if ($NoClobber) {Write-Warning -Message "-NoClobber parameter is no longer used" } + #Open the file, get the worksheet, and decide where in the sheet we are writing, and if there is a number format to apply. + try { + $script:Header = $null + if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet." ; return} + #To force -Now not to format as a table, allow $false in -TableName to be "No table" + $TableName = if ($null -eq $TableName -or ($TableName -is [bool] -and $false -eq $TableName)) { $null } else {[String]$TableName} + if ($Now -or (-not $Path -and -not $ExcelPackage) ) { + if (-not $PSBoundParameters.ContainsKey("Path")) { $Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx' } + if (-not $PSBoundParameters.ContainsKey("Show")) { $Show = $true } + if (-not $PSBoundParameters.ContainsKey("AutoSize")) { $AutoSize = $true } + #"Now" option will create a table, unless something passed in TableName/Table Style. False in TableName will block autocreation + if (-not $PSBoundParameters.ContainsKey("TableName") -and + -not $PSBoundParameters.ContainsKey("TableStyle") -and + -not $AutoFilter) { + $TableName = 'Table1' + } + } + if ($ExcelPackage) { + $pkg = $ExcelPackage + $Path = $pkg.File + } + Else { $pkg = Open-ExcelPackage -Path $Path -Create -KillExcel:$KillExcel -Password:$Password} + } + catch {throw "Could not open Excel Package $path"} + try { + $params = @{WorksheetName=$WorksheetName} + foreach ($p in @("ClearSheet", "MoveToStart", "MoveToEnd", "MoveBefore", "MoveAfter", "Activate")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} + $ws = $pkg | Add-WorkSheet @params + if ($ws.Name -ne $WorksheetName) { + Write-Warning -Message "The Worksheet name has been changed from $WorksheetName to $($ws.Name), this may cause errors later." + $WorksheetName = $ws.Name + } + } + catch {throw "Could not get worksheet $worksheetname"} + try { + if ($Append -and $ws.Dimension) { + #if there is a title or anything else above the header row, append needs to be combined wih a suitable startrow parameter + $headerRange = $ws.Dimension.Address -replace "\d+$", $StartRow + #using a slightly odd syntax otherwise header ends up as a 2D array + $ws.Cells[$headerRange].Value | ForEach-Object -Begin {$Script:header = @()} -Process {$Script:header += $_ } + #if we did not get AutoNameRange, but headers have ranges of the same name make autoNameRange True, otherwise make it false + if (-not $AutoNameRange) { + $AutoNameRange = $true ; foreach ($h in $header) {if ($ws.names.name -notcontains $h) {$AutoNameRange = $false} } + } + #if we did not get a Rangename but there is a Range which covers the active part of the sheet, set Rangename to that. + if (-not $RangeName -and $ws.names.where({$_.name[0] -match '[a-z]'})) { + $theRange = $ws.names.where({ + ($_.Name[0] -match '[a-z]' ) -and + ($_.Start.Row -eq $StartRow) -and + ($_.Start.Column -eq $StartColumn) -and + ($_.End.Row -eq $ws.Dimension.End.Row) -and + ($_.End.Column -eq $ws.Dimension.End.column) } , 'First', 1) + if ($theRange) {$rangename = $theRange.name} + } + + #if we did not get a table name but there is a table which covers the active part of the sheet, set table name to that, and don't do anything with autofilter + if ($null -eq $TableName -and $ws.Tables.Where({$_.address.address -eq $ws.dimension.address})) { + $TableName = $ws.Tables.Where({$_.address.address -eq $ws.dimension.address},'First', 1).Name + $AutoFilter = $false + } + #if we did not get $autofilter but a filter range is set and it covers the right area, set autofilter to true + elseif (-not $AutoFilter -and $ws.Names['_xlnm._FilterDatabase']) { + if ( ($ws.Names['_xlnm._FilterDatabase'].Start.Row -eq $StartRow) -and + ($ws.Names['_xlnm._FilterDatabase'].Start.Column -eq $StartColumn) -and + ($ws.Names['_xlnm._FilterDatabase'].End.Row -eq $ws.Dimension.End.Row) -and + ($ws.Names['_xlnm._FilterDatabase'].End.Column -eq $ws.Dimension.End.Column) ) {$AutoFilter = $true} + } + + $row = $ws.Dimension.End.Row + Write-Debug -Message ("Appending: headers are " + ($script:Header -join ", ") + " Start row is $row") + if ($Title) {Write-Warning -Message "-Title Parameter is ignored when appending."} + } + elseif ($Title) { + #Can only add a title if not appending! + $Row = $StartRow + $ws.Cells[$Row, $StartColumn].Value = $Title + $ws.Cells[$Row, $StartColumn].Style.Font.Size = $TitleSize + + if ($PSBoundParameters.ContainsKey("TitleBold")) { + #Set title to Bold face font if -TitleBold was specified. + #Otherwise the default will be unbolded. + $ws.Cells[$Row, $StartColumn].Style.Font.Bold = [boolean]$TitleBold + } + if ($TitleBackgroundColor ) { + if ($TitleBackgroundColor -is [string]) {$TitleBackgroundColor = [System.Drawing.Color]::$TitleBackgroundColor } + $ws.Cells[$Row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern + $ws.Cells[$Row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor) + } + $Row ++ ; $startRow ++ + } + else { $Row = $StartRow } + $ColumnIndex = $StartColumn + $Numberformat = Expand-NumberFormat -NumberFormat $Numberformat + if ((-not $ws.Dimension) -and ($Numberformat -ne $ws.Cells.Style.Numberformat.Format)) { + $ws.Cells.Style.Numberformat.Format = $Numberformat + $setNumformat = $false + } + else { $setNumformat = ($Numberformat -ne $ws.Cells.Style.Numberformat.Format) } + } + catch {throw "Failed preparing to export to worksheet '$WorksheetName' to '$Path': $_"} + #region Special case -inputobject passed a dataTable object + <# If inputObject was passed via the pipeline it won't be visible until the process block, we will only see it here if it was passed as a parameter + if it is a data table don't do foreach on it (slow) - put the whole table in and set dates on date columns, + set things up for the end block, and skip the process block #> + if ($InputObject -is [System.Data.DataTable]) { + #don't leave caller with a renamed table, save the name and set it back later + $orginalTableName = $InputObject.TableName + if ($TableName) { + $InputObject.TableName = $TableName + } + while ($InputObject.TableName -in $pkg.Workbook.Worksheets.Tables.name) { + Write-Warning "Table name $($InputObject.TableName) is not unique, adding '_' to it " + $InputObject.TableName += "_" + } + if ($TableName -or $PSBoundParameters.ContainsKey("TableStyle")) { + $TableName = $null + $null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader),$TableStyle ) + } + else { + $null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader) ) + } + $InputObject.TableName = $orginalTableName + foreach ($c in $InputObject.Columns.where({$_.datatype -eq [datetime]})) { + Set-ExcelColumn -Worksheet $ws -Column ($c.Ordinal + $StartColumn) -NumberFormat 'Date-Time' + } + foreach ($c in $InputObject.Columns.where({$_.datatype -eq [timespan]})) { + Set-ExcelColumn -Worksheet $ws -Column ($c.Ordinal + $StartColumn) -NumberFormat '[h]:mm:ss' + } + $ColumnIndex += $InputObject.Columns.Count - 1 + if ($noHeader) {$row += $InputObject.Rows.Count -1 } + else {$row += $InputObject.Rows.Count } + $null = $PSBoundParameters.Remove('InputObject') + $firstTimeThru = $false + } + #endregion + else {$firstTimeThru = $true} + } + + process { if ($PSBoundParameters.ContainsKey("InputObject")) { + try { + if ($null -eq $InputObject) {$row += 1} + foreach ($TargetData in $InputObject) { + if ($firstTimeThru) { + $firstTimeThru = $false + $isDataTypeValueType = ($null -eq $TargetData) -or ($TargetData.GetType().name -match 'string|timespan|datetime|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort|URI|ExcelHyperLink') + if ($isDataTypeValueType ) { + $script:Header = @(".") # dummy value to make sure we go through the "for each name in $header" + if (-not $Append) {$row -= 1} # By default row will be 1, it is incremented before inserting values (so it ends pointing at final row.); si first data row is 2 - move back up 1 if there is no header . + } + if ($null -ne $TargetData) {Write-Debug "DataTypeName is '$($TargetData.GetType().name)' isDataTypeValueType '$isDataTypeValueType'" } + } + #region Add headers - if we are appending, or we have been through here once already we will have the headers + if (-not $script:Header) { + if ($DisplayPropertySet -and $TargetData.psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames) { + $script:Header = $TargetData.psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames.Where( {$_ -notin $ExcludeProperty}) + } + else { + if ($NoAliasOrScriptPropeties) {$propType = "Property"} else {$propType = "*"} + $script:Header = $TargetData.PSObject.Properties.where( {$_.MemberType -like $propType}).Name + } + foreach ($exclusion in $ExcludeProperty) {$script:Header = $script:Header -notlike $exclusion} + if ($NoHeader) { + # Don't push the headers to the spreadsheet + $Row -= 1 + } + else { + $ColumnIndex = $StartColumn + foreach ($Name in $script:Header) { + $ws.Cells[$Row, $ColumnIndex].Value = $Name + Write-Verbose "Cell '$Row`:$ColumnIndex' add header '$Name'" + $ColumnIndex += 1 + } + } + } + #endregion + #region Add non header values + $Row += 1 + $ColumnIndex = $StartColumn + <# + For each item in the header OR for the Data item if this is a simple Type or data table : + If it is a date insert with one of Excel's built in formats - recognized as "Date and time to be localized" + if it is a timespan insert with a built in format for elapsed hours, minutes and seconds + if its any other numeric insert as is , setting format if need be. + Preserve URI, Insert a data table, convert non string objects to string. + For strings, check for fomula, URI or Number, before inserting as a string (ignore nulls) #> + foreach ($Name in $script:Header) { + if ($isDataTypeValueType) {$v = $TargetData} + else {$v = $TargetData.$Name} + try { + if ($v -is [DateTime]) { + $ws.Cells[$Row, $ColumnIndex].Value = $v + $ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized. + } + elseif ($v -is [TimeSpan]) { + $ws.Cells[$Row, $ColumnIndex].Value = $v + $ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = '[h]:mm:ss' + } + elseif ($v -is [System.ValueType]) { + $ws.Cells[$Row, $ColumnIndex].Value = $v + if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } + } + elseif ($v -is [uri] ) { + $ws.Cells[$Row, $ColumnIndex].HyperLink = $v + $ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) + $ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true + } + elseif ($v -isnot [String] ) { #Other objects or null. + if ($null -ne $v) { $ws.Cells[$Row, $ColumnIndex].Value = $v.toString()} + } + elseif ($v[0] -eq '=') { + $ws.Cells[$Row, $ColumnIndex].Formula = ($v -replace '^=','') + if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } + } + elseif ( [System.Uri]::IsWellFormedUriString($v , [System.UriKind]::Absolute) ) { + if ($v -match "^xl://internal/") { + $referenceAddress = $v -replace "^xl://internal/" , "" + $display = $referenceAddress -replace "!A1$" , "" + $h = New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList $referenceAddress , $display + $ws.Cells[$Row, $ColumnIndex].HyperLink = $h + } + else {$ws.Cells[$Row, $ColumnIndex].HyperLink = $v } #$ws.Cells[$Row, $ColumnIndex].Value = $v.AbsoluteUri + $ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) + $ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true + } + else { + $number = $null + if ( $numberRegex.IsMatch($v) -and # if it contains digit(s) - this syntax is quicker than -match for many items and cuts out slow checks for non numbers + $NoNumberConversion -ne '*' -and # and NoNumberConversion isn't specified + $NoNumberConversion -notcontains $Name -and + [Double]::TryParse($v, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) + ) { + $ws.Cells[$Row, $ColumnIndex].Value = $number + if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } + } + else { + $ws.Cells[$Row, $ColumnIndex].Value = $v + } + + } + } + catch {Write-Warning -Message "Could not insert the '$Name' property at Row $Row, Column $ColumnIndex"} + $ColumnIndex += 1 + } + $ColumnIndex -= 1 # column index will be the last column whether isDataTypeValueType was true or false + #endregion + } + } + catch {throw "Failed exporting data to worksheet '$WorksheetName' to '$Path': $_" } + + }} + + end { + if ($firstTimeThru -and $ws.Dimension) { + $LastRow = $ws.Dimension.End.Row + $LastCol = $ws.Dimension.End.Column + $endAddress = $ws.Dimension.End.Address + } + else { + $LastRow = $Row + $LastCol = $ColumnIndex + $endAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($LastRow , $LastCol) + } + $startAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($StartRow, $StartColumn) + $dataRange = "{0}:{1}" -f $startAddress, $endAddress + + Write-Debug "Data Range '$dataRange'" + if ($AutoNameRange) { + try { + if (-not $script:header) { + # if there aren't any headers, use the the first row of data to name the ranges: this is the last point that headers will be used. + $headerRange = $ws.Dimension.Address -replace "\d+$", $StartRow + #using a slightly odd syntax otherwise header ends up as a 2D array + $ws.Cells[$headerRange].Value | ForEach-Object -Begin {$Script:header = @()} -Process {$Script:header += $_ } + if ($PSBoundParameters.ContainsKey($TargetData)) { #if Export was called with data that writes no header start the range at $startRow ($startRow is data) + $targetRow = $StartRow + } + else { $targetRow = $StartRow + 1 } #if Export was called without data to add names (assume $startRow is a header) or... + } # ... called with data that writes a header, then start the range at $startRow + 1 + else { $targetRow = $StartRow + 1 } + + #Dimension.start.row always seems to be one so we work out the target row + #, but start.column is the first populated one and .Columns is the count of populated ones. + # if we have 5 columns from 3 to 8, headers are numbered 0..4, so that is in the for loop and used for getting the name... + # but we have to add the start column on when referencing positions + foreach ($c in 0..($LastCol - $StartColumn)) { + $targetRangeName = @($script:Header)[$c] #Let Add-ExcelName fix (and warn about) bad names + Add-ExcelName -RangeName $targetRangeName -Range $ws.Cells[$targetRow, ($StartColumn + $c ), $LastRow, ($StartColumn + $c )] + try {#this test can throw with some names, surpress any error + if ([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress(($targetRangeName -replace '\W' , '_' ))) { + Write-Warning -Message "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property." + } + } + Catch { + Write-Warning -Message "AutoNameRange: Testing '$targetRangeName' caused an error. This should be harmless, but a change of property name may be needed.." + } + } + } + catch {Write-Warning -Message "Failed adding named ranges to worksheet '$WorksheetName': $_" } + } + #Empty string is not allowed as a name for ranges or tables. + if ($RangeName) { Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $RangeName} + + #Allow table to be inserted by specifying Name, or Style or both; only process autoFilter if there is no table (they clash). + if ($null -ne $TableName) { + Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $PSBoundParameters['TableName'] -TableStyle $TableStyle + } + elseif ($PSBoundParameters.ContainsKey('TableStyle')) { + Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName "" -TableStyle $TableStyle + } + elseif ($AutoFilter) { + try { + $ws.Cells[$dataRange].AutoFilter = $true + Write-Verbose -Message "Enabled autofilter. " + } + catch {Write-Warning -Message "Failed adding autofilter to worksheet '$WorksheetName': $_"} + } + + if ($PivotTableDefinition) { + foreach ($item in $PivotTableDefinition.GetEnumerator()) { + $params = $item.value + if ($Activate) {$params.Activate = $true } + if ($params.keys -notcontains 'SourceRange' -and + ($params.Keys -notcontains 'SourceWorkSheet' -or $params.SourceWorkSheet -eq $WorksheetName)) {$params.SourceRange = $dataRange} + if ($params.Keys -notcontains 'SourceWorkSheet') {$params.SourceWorkSheet = $ws } + if ($params.Keys -notcontains 'NoTotalsInPivot' -and $NoTotalsInPivot ) {$params.PivotTotals = 'None'} + if ($params.Keys -notcontains 'PivotTotals' -and $PivotTotals ) {$params.PivotTotals = $PivotTotals} + if ($params.Keys -notcontains 'PivotDataToColumn' -and $PivotDataToColumn) {$params.PivotDataToColumn = $true} + + Add-PivotTable -ExcelPackage $pkg -PivotTableName $item.key @Params + } + } + if ($IncludePivotTable -or $IncludePivotChart) { + $params = @{ + 'SourceRange' = $dataRange + } + if ($PivotTableName -and ($pkg.workbook.worksheets.tables.name -contains $PivotTableName)) { + Write-Warning -Message "The selected PivotTable name '$PivotTableName' is already used as a table name. Adding a suffix of 'Pivot'." + $PivotTableName += 'Pivot' + } + + if ($PivotTableName) {$params.PivotTableName = $PivotTableName} + else {$params.PivotTableName = $WorksheetName + 'PivotTable'} + if ($Activate) {$params.Activate = $true } + if ($PivotFilter) {$params.PivotFilter = $PivotFilter} + if ($PivotRows) {$params.PivotRows = $PivotRows} + if ($PivotColumns) {$Params.PivotColumns = $PivotColumns} + if ($PivotData) {$Params.PivotData = $PivotData} + if ($NoTotalsInPivot) {$params.PivotTotals = "None" } + Elseif ($PivotTotals) {$params.PivotTotals = $PivotTotals} + if ($PivotDataToColumn) {$params.PivotDataToColumn = $true} + if ($IncludePivotChart) { + $params.IncludePivotChart = $true + $Params.ChartType = $ChartType + if ($ShowCategory) {$params.ShowCategory = $true} + if ($ShowPercent) {$params.ShowPercent = $true} + if ($NoLegend) {$params.NoLegend = $true} + } + Add-PivotTable -ExcelPackage $pkg -SourceWorkSheet $ws @params + } + + try { + #Allow single switch or two seperate ones. + if ($FreezeTopRowFirstColumn -or ($FreezeTopRow -and $FreezeFirstColumn)) { + $ws.View.FreezePanes(2, 2) + Write-Verbose -Message "Froze top row and first column" + } + elseif ($FreezeTopRow) { + $ws.View.FreezePanes(2, 1) + Write-Verbose -Message "Froze top row" + } + elseif ($FreezeFirstColumn) { + $ws.View.FreezePanes(1, 2) + Write-Verbose -Message "Froze first column" + } + #Must be 1..maxrows or and array of 1..maxRows,1..MaxCols + if ($FreezePane) { + $freezeRow, $freezeColumn = $FreezePane + if (-not $freezeColumn -or $freezeColumn -eq 0) { + $freezeColumn = 1 + } + + if ($freezeRow -ge 1) { + $ws.View.FreezePanes($freezeRow, $freezeColumn) + Write-Verbose -Message "Froze panes at row $freezeRow and column $FreezeColumn" + } + } + } + catch {Write-Warning -Message "Failed adding Freezing the panes in worksheet '$WorksheetName': $_"} + + if ($PSBoundParameters.ContainsKey("BoldTopRow")) { #it sets bold as far as there are populated cells: for whole row could do $ws.row($x).style.font.bold = $true + try { + if ($Title) { + $range = $ws.Dimension.Address -replace '\d+', ($StartRow + 1) + } + else { + $range = $ws.Dimension.Address -replace '\d+', $StartRow + } + $ws.Cells[$range].Style.Font.Bold = [boolean]$BoldTopRow + Write-Verbose -Message "Set $range font style to bold." + } + catch {Write-Warning -Message "Failed setting the top row to bold in worksheet '$WorksheetName': $_"} + } + if ($AutoSize -and -not $env:NoAutoSize) { + try { + #Don't fit the all the columns in the sheet; if we are adding cells beside things with hidden columns, that unhides them + if ($MaxAutoSizeRows -and $MaxAutoSizeRows -lt $LastRow ) { + $AutosizeRange = [OfficeOpenXml.ExcelAddress]::GetAddress($startRow,$StartColumn, $MaxAutoSizeRows , $LastCol) + $ws.Cells[$AutosizeRange].AutoFitColumns() + } + else {$ws.Cells[$dataRange].AutoFitColumns() } + Write-Verbose -Message "Auto-sized columns" + } + catch { Write-Warning -Message "Failed autosizing columns of worksheet '$WorksheetName': $_"} + } + elseif ($AutoSize) {Write-Warning -Message "Auto-fitting columns is not available with this OS configuration." } + + foreach ($Sheet in $HideSheet) { + try { + $pkg.Workbook.WorkSheets.Where({$_.Name -like $sheet}) | ForEach-Object { + $_.Hidden = 'Hidden' + Write-verbose -Message "Sheet '$($_.Name)' Hidden." + } + } + catch {Write-Warning -Message "Failed hiding worksheet '$sheet': $_"} + } + foreach ($Sheet in $UnHideSheet) { + try { + $pkg.Workbook.WorkSheets.Where({$_.Name -like $sheet}) | ForEach-Object { + $_.Hidden = 'Visible' + Write-verbose -Message "Sheet '$($_.Name)' shown" + } + } + catch {Write-Warning -Message "Failed showing worksheet '$sheet': $_"} + } + if (-not $pkg.Workbook.Worksheets.Where({$_.Hidden -eq 'visible'})) { + Write-Verbose -Message "No Sheets were left visible, making $WorksheetName visible" + $ws.Hidden = 'Visible' + } + + foreach ($chartDef in $ExcelChartDefinition) { + if ($chartDef -is [System.Management.Automation.PSCustomObject]) { + $params = @{} + $chartDef.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}} + Add-ExcelChart -Worksheet $ws @params + } + elseif ($chartDef -is [hashtable] -or $chartDef -is[System.Collections.Specialized.OrderedDictionary]) { + Add-ExcelChart -Worksheet $ws @chartDef + } + } + + if ($Calculate) { + try { [OfficeOpenXml.CalculationExtension]::Calculate($ws) } + catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook. $_"} + } + + if ($Barchart -or $PieChart -or $LineChart -or $ColumnChart) { + if ($NoHeader) {$FirstDataRow = $startRow} + else {$FirstDataRow = $startRow + 1 } + $range = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $startColumn, $FirstDataRow, $lastCol ) + $xCol = $ws.cells[$range] | Where-Object {$_.value -is [string] } | ForEach-Object {$_.start.column} | Sort-Object | Select-Object -first 1 + if (-not $xcol) { + $xcol = $StartColumn + $range = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, ($startColumn +1), $FirstDataRow, $lastCol ) + } + $yCol = $ws.cells[$range] | Where-Object {$_.value -is [valueType] -or $_.Formula } | ForEach-Object {$_.start.column} | Sort-Object | Select-Object -first 1 + if (-not ($xCol -and $ycol)) { Write-Warning -Message "Can't identify a string column and a number column to use as chart labels and data. "} + else { + $params = @{ + XRange = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $xcol , $lastrow, $xcol) + YRange = [OfficeOpenXml.ExcelAddress]::GetAddress($FirstDataRow, $ycol , $lastrow, $ycol) + Title = '' + Column = ($lastCol +1) + Width = 800 + } + if ($ShowPercent) {$params["ShowPercent"] = $true} + if ($ShowCategory) {$params["ShowCategory"] = $true} + if ($NoLegend) {$params["NoLegend"] = $true} + if (-not $NoHeader) {$params["SeriesHeader"] = $ws.Cells[$startRow, $YCol].Value} + if ($ColumnChart) {$Params["chartType"] = "ColumnStacked" } + elseif ($Barchart) {$Params["chartType"] = "BarStacked" } + elseif ($PieChart) {$Params["chartType"] = "PieExploded3D" } + elseif ($LineChart) {$Params["chartType"] = "Line" } + + Add-ExcelChart -Worksheet $ws @params + } + } + + # It now doesn't matter if the conditional formating rules are passed in $conditionalText or $conditional format. + # Just one with an alias for compatiblity it will break things for people who are using both at once + foreach ($c in (@() + $ConditionalText + $ConditionalFormat) ) { + try { + #we can take an object with a .ConditionalType property made by New-ConditionalText or with a .Formatter Property made by New-ConditionalFormattingIconSet or a hash table + if ($c.ConditionalType) { + $cfParams = @{RuleType = $c.ConditionalType; ConditionValue = $c.Text ; + BackgroundColor = $c.BackgroundColor; BackgroundPattern = $c.PatternType ; + ForeGroundColor = $c.ConditionalTextColor} + if ($c.Range) {$cfParams.Range = $c.Range} + else {$cfParams.Range = $ws.Dimension.Address } + Add-ConditionalFormatting -WorkSheet $ws @cfParams + Write-Verbose -Message "Added conditional formatting to range $($c.range)" + } + elseif ($c.formatter) { + switch ($c.formatter) { + "ThreeIconSet" {Add-ConditionalFormatting -WorkSheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse } + "FourIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse } + "FiveIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse } + } + Write-Verbose -Message "Added conditional formatting to range $($c.range)" + } + elseif ($c -is [hashtable] -or $c -is[System.Collections.Specialized.OrderedDictionary]) { + if (-not $c.Range -or $c.Address) {$c.Address = $ws.Dimension.Address } + Add-ConditionalFormatting -WorkSheet $ws @c + } + } + catch {throw "Error applying conditional formatting to worksheet $_"} + } + foreach ($s in $Style) { + if (-not $s.Range) {$s["Range"] = $ws.Dimension.Address } + Set-ExcelRange -WorkSheet $ws @s + } + if ($CellStyleSB) { + try { + $TotalRows = $ws.Dimension.Rows + $LastColumn = $ws.Dimension.Address -replace "^.*:(\w*)\d+$" , '$1' + & $CellStyleSB $ws $TotalRows $LastColumn + } + catch {Write-Warning -Message "Failed processing CellStyleSB in worksheet '$WorksheetName': $_"} + } + + #Can only add password, may want to support -password $Null removing password. + if ($Password) { + try { + $ws.Protection.SetPassword($Password) + Write-Verbose -Message 'Set password on workbook' + } + + catch {throw "Failed setting password for worksheet '$WorksheetName': $_"} + } + + if ($PassThru) { $pkg } + else { + if ($ReturnRange) {$dataRange } + + if ($Password) { $pkg.Save($Password) } + else { $pkg.Save() } + Write-Verbose -Message "Saved workbook $($pkg.File)" + if ($ReZip) { + Write-Verbose -Message "Re-Zipping $($pkg.file) using .NET ZIP library" + try { + Add-Type -AssemblyName 'System.IO.Compression.Filesystem' -ErrorAction stop + } + catch { + Write-Error "The -ReZip parameter requires .NET Framework 4.5 or later to be installed. Recommend to install Powershell v4+" + continue + } + try { + $TempZipPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName()) + $null = [io.compression.zipfile]::ExtractToDirectory($pkg.File, $TempZipPath) + Remove-Item $pkg.File -Force + $null = [io.compression.zipfile]::CreateFromDirectory($TempZipPath, $pkg.File) + } + catch {throw "Error resizipping $path : $_"} + } + + $pkg.Dispose() + + if ($Show) { Invoke-Item $Path } + } + + } +} diff --git a/ExportedCommands/Export-ExcelSheet.md b/ExportedCommands/Export-ExcelSheet.md new file mode 100644 index 0000000..765dea7 --- /dev/null +++ b/ExportedCommands/Export-ExcelSheet.md @@ -0,0 +1,138 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Export-ExcelSheet + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Export-ExcelSheet [-Path] [[-OutputPath] ] [[-SheetName] ] [[-Encoding] ] [[-Extension] ] [[-Delimiter] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Delimiter +{{ Fill Delimiter Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: ;, , + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Encoding +{{ Fill Encoding Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: ASCII, BigEndianUniCode, Default, OEM, UniCode, UTF32, UTF7, UTF8 + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Extension +{{ Fill Extension Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: .txt, .log, .csv + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputPath +{{ Fill OutputPath Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +{{ Fill Path Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SheetName +{{ Fill SheetName Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Export-ExcelSheet.ps1 b/ExportedCommands/Export-ExcelSheet.ps1 similarity index 100% rename from Export-ExcelSheet.ps1 rename to ExportedCommands/Export-ExcelSheet.ps1 diff --git a/ExportedCommands/Export-MultipleExcelSheets.md b/ExportedCommands/Export-MultipleExcelSheets.md new file mode 100644 index 0000000..e30679b --- /dev/null +++ b/ExportedCommands/Export-MultipleExcelSheets.md @@ -0,0 +1,120 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Export-MultipleExcelSheets + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Export-MultipleExcelSheets [-Path] [-InfoMap] [[-Password] ] [-Show] [-AutoSize] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -AutoSize +{{ Fill AutoSize Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InfoMap +{{ Fill InfoMap Description }} + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Password +{{ Fill Password Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +{{ Fill Path Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +{{ Fill Show Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/ExportedCommands/Export-MultipleExcelSheets.ps1 b/ExportedCommands/Export-MultipleExcelSheets.ps1 new file mode 100644 index 0000000..378ceb8 --- /dev/null +++ b/ExportedCommands/Export-MultipleExcelSheets.ps1 @@ -0,0 +1,27 @@ +function Export-MultipleExcelSheets { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] + param( + [Parameter(Mandatory = $true)] + $Path, + [Parameter(Mandatory = $true)] + [hashtable]$InfoMap, + [string]$Password, + [Switch]$Show, + [Switch]$AutoSize + ) + + $parameters = @{ } + $PSBoundParameters + $parameters.Remove("InfoMap") + $parameters.Remove("Show") + + $parameters.Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) + + foreach ($entry in $InfoMap.GetEnumerator()) { + Write-Progress -Activity "Exporting" -Status "$($entry.Key)" + $parameters.WorkSheetname = $entry.Key + + & $entry.Value | Export-Excel @parameters + } + + if ($Show) { Invoke-Item $Path } +} diff --git a/Export-StocksToExcel.ps1 b/ExportedCommands/Export-StocksToExcel.ps1 similarity index 100% rename from Export-StocksToExcel.ps1 rename to ExportedCommands/Export-StocksToExcel.ps1 diff --git a/ExportedCommands/Get-ExcelColumnName.md b/ExportedCommands/Get-ExcelColumnName.md new file mode 100644 index 0000000..85a891f --- /dev/null +++ b/ExportedCommands/Get-ExcelColumnName.md @@ -0,0 +1,60 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-ExcelColumnName + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-ExcelColumnName [[-columnNumber] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -columnNumber +{{ Fill columnNumber Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Get-ExcelColumnName.ps1 b/ExportedCommands/Get-ExcelColumnName.ps1 similarity index 100% rename from Get-ExcelColumnName.ps1 rename to ExportedCommands/Get-ExcelColumnName.ps1 diff --git a/Get-ExcelSheetInfo.ps1 b/ExportedCommands/Get-ExcelSheetInfo.ps1 similarity index 61% rename from Get-ExcelSheetInfo.ps1 rename to ExportedCommands/Get-ExcelSheetInfo.ps1 index edccf04..f4fb88a 100644 --- a/Get-ExcelSheetInfo.ps1 +++ b/ExportedCommands/Get-ExcelSheetInfo.ps1 @@ -1,22 +1,4 @@ Function Get-ExcelSheetInfo { - <# - .SYNOPSIS - Get worksheet names and their indices of an Excel workbook. - .DESCRIPTION - The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook. - .PARAMETER Path - Specifies the path to the Excel file. This parameter is required. - .EXAMPLE - Get-ExcelSheetInfo .\Test.xlsx - - .NOTES - CHANGELOG - 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) - - .LINK - https://github.com/dfinke/ImportExcel - #> - [CmdletBinding()] param( [Alias('FullName')] diff --git a/ExportedCommands/Get-ExcelWorkbookInfo.ps1 b/ExportedCommands/Get-ExcelWorkbookInfo.ps1 new file mode 100644 index 0000000..a064314 --- /dev/null +++ b/ExportedCommands/Get-ExcelWorkbookInfo.ps1 @@ -0,0 +1,27 @@ +Function Get-ExcelWorkbookInfo { + [CmdletBinding()] + Param ( + [Alias('FullName')] + [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] + [String]$Path + ) + + Process { + Try { + $Path = (Resolve-Path $Path).ProviderPath + + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream + $workbook = $xl.Workbook + $workbook.Properties + + $stream.Close() + $stream.Dispose() + $xl.Dispose() + $xl = $null + } + Catch { + throw "Failed retrieving Excel workbook information for '$Path': $_" + } + } +} diff --git a/ExportedCommands/Get-HtmlTable.md b/ExportedCommands/Get-HtmlTable.md new file mode 100644 index 0000000..7fe2d1a --- /dev/null +++ b/ExportedCommands/Get-HtmlTable.md @@ -0,0 +1,121 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-HtmlTable + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-HtmlTable [-url] [[-tableIndex] ] [[-Header] ] [[-FirstDataRow] ] + [-UseDefaultCredentials] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -FirstDataRow +{{ Fill FirstDataRow Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Header +{{ Fill Header Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseDefaultCredentials +{{ Fill UseDefaultCredentials Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -tableIndex +{{ Fill tableIndex Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{ Fill url Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Get-HtmlTable.ps1 b/ExportedCommands/Get-HtmlTable.ps1 similarity index 100% rename from Get-HtmlTable.ps1 rename to ExportedCommands/Get-HtmlTable.ps1 diff --git a/ExportedCommands/Get-Range.md b/ExportedCommands/Get-Range.md new file mode 100644 index 0000000..9d37398 --- /dev/null +++ b/ExportedCommands/Get-Range.md @@ -0,0 +1,87 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-Range + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-Range [[-start] ] [[-stop] ] [[-step] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -start +{{ Fill start Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -step +{{ Fill step Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -stop +{{ Fill stop Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Get-Range.ps1 b/ExportedCommands/Get-Range.ps1 similarity index 100% rename from Get-Range.ps1 rename to ExportedCommands/Get-Range.ps1 diff --git a/ExportedCommands/Get-XYRange.md b/ExportedCommands/Get-XYRange.md new file mode 100644 index 0000000..3d0af44 --- /dev/null +++ b/ExportedCommands/Get-XYRange.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-XYRange + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-XYRange [[-targetData] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Get-XYRange.ps1 b/ExportedCommands/Get-XYRange.ps1 similarity index 100% rename from Get-XYRange.ps1 rename to ExportedCommands/Get-XYRange.ps1 diff --git a/ExportedCommands/Import-Excel.ps1 b/ExportedCommands/Import-Excel.ps1 new file mode 100644 index 0000000..0eae2e3 --- /dev/null +++ b/ExportedCommands/Import-Excel.ps1 @@ -0,0 +1,399 @@ + +function Import-Excel { + <# + .SYNOPSIS + Create custom objects from the rows in an Excel worksheet. + + .DESCRIPTION + The Import-Excel cmdlet creates custom objects from the rows in an Excel worksheet. Each row represents one object. All of this is possible without installing Microsoft Excel and by using the .NET library ‘EPPLus.dll’. + + By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blank property name, only columns with column headers will be imported. + + If the default behavior is not desired and you want to import the complete worksheet ‘as is’, the parameter ‘-NoHeader’ can be used. In case you want to provide your own property names, you can use the parameter ‘-HeaderName’. + + .PARAMETER Path + Specifies the path to the Excel file. + .PARAMETER ExcelPackage + Instead of specifying a path provides an Excel Package object (from Open-ExcelPackage) + Using this avoids re-reading the whole file when importing multiple parts of it. + To allow multiple read operations Import-Excel does NOT close the package, and you should use + Close-ExcelPackage -noSave to close it. + .PARAMETER WorksheetName + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + .PARAMETER DataOnly + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + .PARAMETER HeaderName + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. + If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. + If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. + + .PARAMETER NoHeader + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. + This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names. + + .PARAMETER StartRow + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. + + .PARAMETER EndRow + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + .PARAMETER StartColumn + The number of the first column to read data from (1 by default). + + .PARAMETER EndColumn + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + .PARAMETER AsText + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. * is supported as a wildcard. + + .PARAMETER Password + Accepts a string that will be used to open a password protected Excel file. + + .EXAMPLE + Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the column names defined in the first row. In case a column doesn’t have a column header (usually in row 1 when ‘-StartRow’ is not used), then the unnamed columns will be skipped and the data in those columns will not be imported. + + ---------------------------------------------- + | File: Movies.xlsx - Sheet: Actors | + ---------------------------------------------- + | A B C | + |1 First Name Address | + |2 Chuck Norris California | + |3 Jean-Claude Vandamme Brussels | + ---------------------------------------------- + + PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors + + First Name: Chuck + Address : California + + First Name: Jean-Claude + Address : Brussels + + Notice that column 'B' is not imported because there's no value in cell 'B1' that can be used as property name for the objects. + + .EXAMPLE + Import the complete Excel worksheet ‘as is’ by using the ‘-NoHeader’ switch. One object is created for each row. The property names of the objects will be automatically generated (P1, P2, P3, ..). + + ---------------------------------------------- + | File: Movies.xlsx - Sheet: Actors | + ---------------------------------------------- + | A B C | + |1 First Name Address | + |2 Chuck Norris California | + |3 Jean-Claude Vandamme Brussels | + ---------------------------------------------- + + PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -NoHeader + + P1: First Name + P2: + P3: Address + + P1: Chuck + P2: Norris + P3: California + + P1: Jean-Claude + P2: Vandamme + P3: Brussels + + Notice that the column header (row 1) is imported as an object too. + + .EXAMPLE + Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the names defined in the parameter ‘-HeaderName’. The properties are named starting from the most left column (A) to the right. In case no value is present in one of the columns, that property will have an empty value. + + ---------------------------------------------------------- + | File: Movies.xlsx - Sheet: Movies | + ---------------------------------------------------------- + | A B C D | + |1 The Bodyguard 1992 9 | + |2 The Matrix 1999 8 | + |3 | + |4 Skyfall 2012 9 | + ---------------------------------------------------------- + + PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -HeaderName 'Movie name', 'Year', 'Rating', 'Genre' + + Movie name: The Bodyguard + Year : 1992 + Rating : 9 + Genre : + + Movie name: The Matrix + Year : 1999 + Rating : 8 + Genre : + + Movie name: + Year : + Rating : + Genre : + + Movie name: Skyfall + Year : 2012 + Rating : 9 + Genre : + + Notice that empty rows are imported and that data for the property 'Genre' is not present in the worksheet. As such, the 'Genre' property will be blanc for all objects. + + .EXAMPLE + Import data from an Excel worksheet. One object is created for each row. The property names of the objects are automatically generated by using the switch ‘-NoHeader’ (P1, P@, P#, ..). The switch ‘-DataOnly’ will speed up the import because empty rows and empty columns are not imported. + + ---------------------------------------------------------- + | File: Movies.xlsx - Sheet: Movies | + ---------------------------------------------------------- + | A B C D | + |1 The Bodyguard 1992 9 | + |2 The Matrix 1999 8 | + |3 | + |4 Skyfall 2012 9 | + ---------------------------------------------------------- + + PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies –NoHeader -DataOnly + + P1: The Bodyguard + P2: 1992 + P3: 9 + + P1: The Matrix + P2: 1999 + P3: 8 + + P1: Skyfall + P2: 2012 + P3: 9 + + Notice that empty rows and empty columns are not imported. + + .EXAMPLE + Import data from an Excel worksheet. One object is created for each row. The property names are provided with the ‘-HeaderName’ parameter. The import will start from row 2 and empty columns and rows are not imported. + + ---------------------------------------------------------- + | File: Movies.xlsx - Sheet: Actors | + ---------------------------------------------------------- + | A B C D | + |1 Chuck Norris California | + |2 | + |3 Jean-Claude Vandamme Brussels | + ---------------------------------------------------------- + + PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -DataOnly -HeaderName 'FirstName', 'SecondName', 'City' –StartRow 2 + + FirstName : Jean-Claude + SecondName: Vandamme + City : Brussels + + Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with ‘Chuck Norris’ has not been imported, because we started the import from row 2 with the parameter ‘-StartRow 2’. + + .EXAMPLE + > + PS> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | + Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force + + Imports data from an Excel file and pipe the data to the Write-SqlTableData to be INSERTed into a table in a SQL Server database. + The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows. + The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in. + NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet. + + .LINK + https://github.com/dfinke/ImportExcel + + .NOTES + #> + + [CmdLetBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] + Param ( + [Alias('FullName')] + [Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] + [Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] + [Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] + [String]$Path, + [Parameter(ParameterSetName = "PackageA", Mandatory)] + [Parameter(ParameterSetName = "PackageB", Mandatory)] + [Parameter(ParameterSetName = "PackageC", Mandatory)] + [OfficeOpenXml.ExcelPackage]$ExcelPackage, + [Alias('Sheet')] + [Parameter(Position = 1)] + [ValidateNotNullOrEmpty()] + [String]$WorksheetName, + [Parameter(ParameterSetName = 'PathB' , Mandatory)] + [Parameter(ParameterSetName = 'PackageB', Mandatory)] + [String[]]$HeaderName , + [Parameter(ParameterSetName = 'PathC' , Mandatory)] + [Parameter(ParameterSetName = 'PackageC', Mandatory)] + [Switch]$NoHeader , + [Alias('HeaderRow', 'TopRow')] + [ValidateRange(1, 9999)] + [Int]$StartRow = 1, + [Alias('StopRow', 'BottomRow')] + [Int]$EndRow , + [Alias('LeftColumn')] + [Int]$StartColumn = 1, + [Alias('RightColumn')] + [Int]$EndColumn , + [Switch]$DataOnly, + [string[]]$AsText, + [ValidateNotNullOrEmpty()] + [String]$Password + ) + begin { + $sw = [System.Diagnostics.Stopwatch]::StartNew() + + Function Get-PropertyNames { + <# + .SYNOPSIS + Create objects containing the column number and the column name for each of the different header types. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")] + Param ( + [Parameter(Mandatory)] + [Int[]]$Columns, + [Parameter(Mandatory)] + [Int]$StartRow + ) + + Try { + if ($HeaderName) { + $i = 0 + foreach ($H in $HeaderName) { + $H | Select-Object @{N = 'Column'; E = { $Columns[$i] } }, @{N = 'Value'; E = { $H } } + $i++ + } + } + elseif ($NoHeader) { + $i = 0 + foreach ($C in $Columns) { + $i++ + $C | Select-Object @{N = 'Column'; E = { $_ } }, @{N = 'Value'; E = { 'P' + $i } } + } + } + + else { + if ($StartRow -lt 1) { + throw 'The top row can never be less than 1 when we need to retrieve headers from the worksheet.' ; return + } + + foreach ($C in $Columns) { + $Worksheet.Cells[$StartRow, $C] | Where-Object { $_.Value } | Select-Object @{N = 'Column'; E = { $C } }, Value + } + } + } + Catch { + throw "Failed creating property names: $_" ; return + } + } + } + + process { + if ($path) { + $extension = [System.IO.Path]::GetExtension($Path) + if ($extension -notmatch '.xlsx$|.xlsm$') { + throw "Import-Excel does not support reading this extension type $($extension)" + } + + $resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue) + if ($resolvedPath) { + $Path = $resolvedPath.ProviderPath + } + else { + throw "'$($Path)' file not found" + } + + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite' + $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage + if ($Password) { $ExcelPackage.Load($stream, $Password) } + else { $ExcelPackage.Load($stream) } + } + try { + #Select worksheet + if (-not $WorksheetName) { $Worksheet = $ExcelPackage.Workbook.Worksheets[1] } + elseif (-not ($Worksheet = $ExcelPackage.Workbook.Worksheets[$WorkSheetName])) { + throw "Worksheet '$WorksheetName' not found, the workbook only contains the worksheets '$($ExcelPackage.Workbook.Worksheets)'. If you only wish to select the first worksheet, please remove the '-WorksheetName' parameter." ; return + } + + Write-Debug $sw.Elapsed.TotalMilliseconds + #region Get rows and columns + #If we are doing dataonly it is quicker to work out which rows to ignore before processing the cells. + if (-not $EndRow ) { $EndRow = $Worksheet.Dimension.End.Row } + if (-not $EndColumn) { $EndColumn = $Worksheet.Dimension.End.Column } + $endAddress = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[$EndRow]C[$EndColumn]", 0, 0) + if ($DataOnly) { + #If we are using headers startrow will be the header-row so examine data from startRow + 1, + if ($NoHeader) { $range = "A" + ($StartRow ) + ":" + $endAddress } + else { $range = "A" + ($StartRow + 1 ) + ":" + $endAddress } + #We're going to look at every cell and build 2 hash tables holding rows & columns which contain data. + #Want to Avoid 'select unique' operations & large Sorts, becuse time time taken increases with square + #of number of items (PS uses heapsort at large size). Instead keep a list of what we have seen, + #using Hash tables: "we've seen it" is all we need, no need to worry about "seen it before" / "Seen it many times". + $colHash = @{ } + $rowHash = @{ } + foreach ($cell in $Worksheet.Cells[$range]) { + if ($null -ne $cell.Value ) { $colHash[$cell.Start.Column] = 1; $rowHash[$cell.Start.row] = 1 } + } + $rows = ( $StartRow..$EndRow ).Where( { $rowHash[$_] }) + $columns = ($StartColumn..$EndColumn).Where( { $colHash[$_] }) + } + else { + $Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." } + if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } } + elseif ($HeaderName) { $Rows = $StartRow..$EndRow } + else { $Rows = (1 + $StartRow)..$EndRow } # ; if ($StartRow -ge $EndRow) { Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results." } } + } + #endregion + #region Create property names + if ((-not $Columns) -or (-not ($PropertyNames = Get-PropertyNames -Columns $Columns -StartRow $StartRow))) { + throw "No column headers found on top row '$StartRow'. If column headers in the worksheet are not a requirement then please use the '-NoHeader' or '-HeaderName' parameter."; return + } + if ($Duplicates = $PropertyNames | Group-Object Value | Where-Object Count -GE 2) { + throw "Duplicate column headers found on row '$StartRow' in columns '$($Duplicates.Group.Column)'. Column headers must be unique, if this is not a requirement please use the '-NoHeader' or '-HeaderName' parameter."; return + } + #endregion + Write-Debug $sw.Elapsed.TotalMilliseconds + if (-not $Rows) { + Write-Warning "Worksheet '$WorksheetName' in workbook '$Path' contains no data in the rows after top row '$StartRow'" + } + else { + #region Create one object per row + if ($AsText) { + <#join items in AsText together with ~~~ . Escape any regex special characters... + # which turns * into \* make it .*. Convert ~~~ to $|^ and top and tail with ^%; + So if we get "Week", "[Time]" and "*date*" ; make the expression ^week$|^\[Time\]$|^.*Date.*$ + $make a regex for this which is case insensitive (option 1) and compiled (option 8) + #> + $TextColExpression = "^" + [regex]::Escape($AsText -join "~~~").replace("\*", ".*").replace("~~~", "$|^") + "$" + $TextColRegEx = New-Object -TypeName regex -ArgumentList $TextColExpression , 9 + } + foreach ($R in $Rows) { + #Disabled write-verbose for speed + # Write-Verbose "Import row '$R'" + $NewRow = [Ordered]@{ } + if ($TextColRegEx) { + foreach ($P in $PropertyNames) { + if ($TextColRegEx.IsMatch($P.Value)) { + $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Text + } + else { $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Value } + } + } + else { + foreach ($P in $PropertyNames) { + $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Value + # Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'." + } + } + [PSCustomObject]$NewRow + } + #endregion + } + Write-Debug $sw.Elapsed.TotalMilliseconds + } + catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$Worksheetname': $_"; return } + finally { + if ($Path) { $stream.close(); $ExcelPackage.Dispose() } + } + } +} diff --git a/ExportedCommands/Import-Html.md b/ExportedCommands/Import-Html.md new file mode 100644 index 0000000..91725a4 --- /dev/null +++ b/ExportedCommands/Import-Html.md @@ -0,0 +1,121 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Import-Html + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Import-Html [[-url] ] [[-index] ] [[-Header] ] [[-FirstDataRow] ] + [-UseDefaultCredentials] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -FirstDataRow +{{ Fill FirstDataRow Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Header +{{ Fill Header Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseDefaultCredentials +{{ Fill UseDefaultCredentials Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -index +{{ Fill index Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{ Fill url Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Import-Html.ps1 b/ExportedCommands/Import-Html.ps1 similarity index 100% rename from Import-Html.ps1 rename to ExportedCommands/Import-Html.ps1 diff --git a/ExportedCommands/Import-UPS.md b/ExportedCommands/Import-UPS.md new file mode 100644 index 0000000..625c903 --- /dev/null +++ b/ExportedCommands/Import-UPS.md @@ -0,0 +1,72 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Import-UPS + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Import-UPS [[-TrackingNumber] ] [-UseDefaultCredentials] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -TrackingNumber +{{ Fill TrackingNumber Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseDefaultCredentials +{{ Fill UseDefaultCredentials Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/TrackingUtils.ps1 b/ExportedCommands/Import-UPS.ps1 similarity index 100% rename from TrackingUtils.ps1 rename to ExportedCommands/Import-UPS.ps1 diff --git a/ExportedCommands/Import-USPS.md b/ExportedCommands/Import-USPS.md new file mode 100644 index 0000000..48833fc --- /dev/null +++ b/ExportedCommands/Import-USPS.md @@ -0,0 +1,72 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Import-USPS + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Import-USPS [[-TrackingNumber] ] [-UseDefaultCredentials] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -TrackingNumber +{{ Fill TrackingNumber Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseDefaultCredentials +{{ Fill UseDefaultCredentials Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/ExportedCommands/Import-USPS.ps1 b/ExportedCommands/Import-USPS.ps1 new file mode 100644 index 0000000..921fa71 --- /dev/null +++ b/ExportedCommands/Import-USPS.ps1 @@ -0,0 +1,9 @@ +function Import-USPS { + param( + $TrackingNumber, + [Switch]$UseDefaultCredentials + + ) + + Import-Html "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=$($TrackingNumber)" 0 -UseDefaultCredentials: $UseDefaultCredentials +} diff --git a/ExportedCommands/Invoke-Sum.md b/ExportedCommands/Invoke-Sum.md new file mode 100644 index 0000000..efbb46e --- /dev/null +++ b/ExportedCommands/Invoke-Sum.md @@ -0,0 +1,87 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Invoke-Sum + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Invoke-Sum [[-data] ] [[-dimension] ] [[-measure] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -data +{{ Fill data Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -dimension +{{ Fill dimension Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -measure +{{ Fill measure Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Invoke-Sum.ps1 b/ExportedCommands/Invoke-Sum.ps1 similarity index 100% rename from Invoke-Sum.ps1 rename to ExportedCommands/Invoke-Sum.ps1 diff --git a/Join-Worksheet.ps1 b/ExportedCommands/Join-Worksheet.ps1 similarity index 52% rename from Join-Worksheet.ps1 rename to ExportedCommands/Join-Worksheet.ps1 index 955ceab..cb24d4e 100644 --- a/Join-Worksheet.ps1 +++ b/ExportedCommands/Join-Worksheet.ps1 @@ -1,134 +1,56 @@ function Join-Worksheet { - <# - .SYNOPSIS - Combines data on all the sheets in an Excel worksheet onto a single sheet. - .DESCRIPTION - Join-Worksheet can work in two main ways, either - Combining data which has the same layout from many pages into one, or - combining pages which have nothing in common. - In the former case the header row is copied from the first sheet and, - by default, each row of data is labelled with the name of the sheet it came from. - In the latter case -NoHeader is specified, and each copied block can have the - sheet it came from placed above it as a title. - .EXAMPLE - > - PS> foreach ($computerName in @('Server1', 'Server2', 'Server3', 'Server4')) { - Get-Service -ComputerName $computerName | Select-Object -Property Status, Name, DisplayName, StartType | - Export-Excel -Path .\test.xlsx -WorkSheetname $computerName -AutoSize - } - PS> $ptDef =New-PivotTableDefinition -PivotTableName "Pivot1" -SourceWorkSheet "Combined" -PivotRows "Status" -PivotFilter "MachineName" -PivotData @{Status='Count'} -IncludePivotChart -ChartType BarClustered3D - PS> Join-Worksheet -Path .\test.xlsx -WorkSheetName combined -FromLabel "MachineName" -HideSource -AutoSize -FreezeTopRow -BoldTopRow -PivotTableDefinition $pt -Show - - The foreach command gets the services running on four servers and exports each - to its own page in Test.xlsx. - $PtDef= creates a definition for a PivotTable. - The Join-Worksheet command uses the same file and merges the results into a sheet - named "Combined". It sets a column header of "Machinename", this column will - contain the name of the sheet the data was copied from; after copying the data - to the sheet "Combined", the other sheets will be hidden. - Join-Worksheet finishes by calling Export-Excel to AutoSize cells, freeze the - top row and make it bold and add thePivotTable. - - .EXAMPLE - > - PS> Get-WmiObject -Class win32_logicaldisk | Select-Object -Property DeviceId,VolumeName, Size,Freespace | - Export-Excel -Path "$env:computerName.xlsx" -WorkSheetname Volumes -NumberFormat "0,000" - PS> Get-NetAdapter | Select-Object Name,InterfaceDescription,MacAddress,LinkSpeed | - Export-Excel -Path "$env:COMPUTERNAME.xlsx" -WorkSheetname NetAdapter - PS> Join-Worksheet -Path "$env:COMPUTERNAME.xlsx" -WorkSheetName Summary -Title "Summary" -TitleBold -TitleSize 22 -NoHeader -LabelBlocks -AutoSize -HideSource -show - - The first two commands get logical-disk and network-card information; each type - is exported to its own sheet in a workbook. - The Join-Worksheet command copies both onto a page named "Summary". Because - the data is dissimilar, -NoHeader is specified, ensuring the whole of each - page is copied. Specifying -LabelBlocks causes each sheet's name to become - a title on the summary page above the copied data. The source data is - hidden, a title is added in 22 point boldface and the columns are sized - to fit the data. - #> [CmdletBinding(DefaultParameterSetName = 'Default')] param ( - # Path to a new or existing .XLSX file. [Parameter(ParameterSetName = "Default", Position = 0)] [Parameter(ParameterSetName = "Table" , Position = 0)] [String]$Path , - # An object representing an Excel Package - either from Open-Excel Package or specifying -PassThru to Export-Excel. [Parameter(Mandatory = $true, ParameterSetName = "PackageDefault")] [Parameter(Mandatory = $true, ParameterSetName = "PackageTable")] [OfficeOpenXml.ExcelPackage]$ExcelPackage, - # The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. $WorkSheetName = 'Combined', - # If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. [switch]$Clearsheet, - #Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. [switch]$NoHeader, - #If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. [string]$FromLabel = "From" , - #If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. [switch]$LabelBlocks, - #Sets the width of the Excel columns to display all the data in their cells. [Switch]$AutoSize, - #Freezes headers etc. in the top row. [Switch]$FreezeTopRow, - #Freezes titles etc. in the left column. [Switch]$FreezeFirstColumn, - #Freezes top row and left column (equivalent to Freeze pane 2,2 ). [Switch]$FreezeTopRowFirstColumn, - # Freezes panes at specified coordinates (in the form RowNumber , ColumnNumber). [Int[]]$FreezePane, - #Enables the Excel filter on the headers of the combined sheet. [Parameter(ParameterSetName = 'Default')] [Parameter(ParameterSetName = 'PackageDefault')] [Switch]$AutoFilter, - #Makes the top row boldface. [Switch]$BoldTopRow, - #If specified, hides the sheets that the data is copied from. [switch]$HideSource, - #Text of a title to be placed in Cell A1. [String]$Title, - #Sets the fill pattern for the title cell. [OfficeOpenXml.Style.ExcelFillStyle]$TitleFillPattern = 'Solid', - #Sets the cell background color for the title cell. $TitleBackgroundColor, - #Sets the title in boldface type. [Switch]$TitleBold, - #Sets the point size for the title. [Int]$TitleSize = 22, - #Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). [Hashtable]$PivotTableDefinition, - #A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. [Object[]]$ExcelChartDefinition, - #One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. [Object[]]$ConditionalFormat, - #Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied [Object[]]$ConditionalText, - #Makes each column a named range. [switch]$AutoNameRange, - #Makes the data in the worksheet a named range. [ValidateScript( { if (-not $_) { throw 'RangeName is null or empty.' } elseif ($_[0] -notmatch '[a-z]') { throw 'RangeName starts with an invalid character.' } else { $true } - })] + })] [String]$RangeName, [ValidateScript( { if (-not $_) { throw 'Tablename is null or empty.' } elseif ($_[0] -notmatch '[a-z]') { throw 'Tablename starts with an invalid character.' } else { $true } - })] + })] [Parameter(ParameterSetName = 'Table' , Mandatory = $true)] [Parameter(ParameterSetName = 'PackageTable' , Mandatory = $true)] - # Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. [String]$TableName, [Parameter(ParameterSetName = 'Table')] [Parameter(ParameterSetName = 'PackageTable')] - #Selects the style for the named table - defaults to "Medium6". [OfficeOpenXml.Table.TableStyles]$TableStyle = 'Medium6', - #If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". [switch]$ReturnRange, - #Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. [switch]$Show, - #If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. [switch]$PassThru ) #region get target worksheet, select it and move it to the end. diff --git a/ExportedCommands/Merge-MultipleSheets.ps1 b/ExportedCommands/Merge-MultipleSheets.ps1 new file mode 100644 index 0000000..14017dc --- /dev/null +++ b/ExportedCommands/Merge-MultipleSheets.ps1 @@ -0,0 +1,147 @@ +function Merge-MultipleSheets { + [cmdletbinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")] + #[Alias("Merge-MulipleSheets")] #There was a spelling error in the first release. This was there to ensure things didn't break but intelisense gave the alias first. + param ( + [Parameter(Mandatory=$true,ValueFromPipeline=$true)] + $Path , + [int]$Startrow = 1, + + [String[]]$Headername, + + [switch]$NoHeader, + + $WorksheetName = "Sheet1", + [Alias('OutFile')] + $OutputFile = ".\temp.xlsx", + [Alias('OutSheet')] + $OutputSheetName = "Sheet1", + $Property = "*" , + $ExcludeProperty , + $Key = "Name" , + $KeyFontColor = [System.Drawing.Color]::Red, + $ChangeBackgroundColor = [System.Drawing.Color]::Orange, + $DeleteBackgroundColor = [System.Drawing.Color]::LightPink, + $AddBackgroundColor = [System.Drawing.Color]::Orange, + [switch]$HideRowNumbers , + [switch]$Passthru , + [Switch]$Show + ) + begin { $filestoProcess = @() } + process { $filestoProcess += $Path} + end { + if ($filestoProcess.Count -eq 1 -and $WorksheetName -match '\*') { + Write-Progress -Activity "Merging sheets" -CurrentOperation "Expanding * to names of sheets in $($filestoProcess[0]). " + $excel = Open-ExcelPackage -Path $filestoProcess + $WorksheetName = $excel.Workbook.Worksheets.Name.where({$_ -like $WorksheetName}) + Close-ExcelPackage -NoSave -ExcelPackage $excel + } + + #Merge identically named sheets in different work books; + if ($filestoProcess.Count -ge 2 -and $WorksheetName -is "string" ) { + Get-Variable -Name 'HeaderName','NoHeader','StartRow','Key','Property','ExcludeProperty','WorksheetName' -ErrorAction SilentlyContinue | + Where-Object {$_.Value} | ForEach-Object -Begin {$params= @{} } -Process {$params[$_.Name] = $_.Value} + + Write-Progress -Activity "Merging sheets" -CurrentOperation "comparing '$WorksheetName' in $($filestoProcess[-1]) against $($filestoProcess[0]). " + $merged = Merge-Worksheet @params -Referencefile $filestoProcess[0] -Differencefile $filestoProcess[-1] + $nextFileNo = 2 + while ($nextFileNo -lt $filestoProcess.count -and $merged) { + Write-Progress -Activity "Merging sheets" -CurrentOperation "comparing '$WorksheetName' in $($filestoProcess[-$nextFileNo]) against $($filestoProcess[0]). " + $merged = Merge-Worksheet @params -ReferenceObject $merged -Differencefile $filestoProcess[-$nextFileNo] + $nextFileNo ++ + + } + } + #Merge different sheets from one workbook + elseif ($filestoProcess.Count -eq 1 -and $WorksheetName.Count -ge 2 ) { + Get-Variable -Name 'HeaderName','NoHeader','StartRow','Key','Property','ExcludeProperty' -ErrorAction SilentlyContinue | + Where-Object {$_.Value} | ForEach-Object -Begin {$params= @{} } -Process {$params[$_.Name] = $_.Value} + + Write-Progress -Activity "Merging sheets" -CurrentOperation "Comparing $($WorksheetName[-1]) against $($WorksheetName[0]). " + $merged = Merge-Worksheet @params -Referencefile $filestoProcess[0] -Differencefile $filestoProcess[0] -WorksheetName $WorksheetName[0,-1] + $nextSheetNo = 2 + while ($nextSheetNo -lt $WorksheetName.count -and $merged) { + Write-Progress -Activity "Merging sheets" -CurrentOperation "Comparing $($WorksheetName[-$nextSheetNo]) against $($WorksheetName[0]). " + $merged = Merge-Worksheet @params -ReferenceObject $merged -Differencefile $filestoProcess[0] -WorksheetName $WorksheetName[-$nextSheetNo] -DiffPrefix $WorksheetName[-$nextSheetNo] + $nextSheetNo ++ + } + } + #We either need one Worksheet name and many files or one file and many sheets. + else { Write-Warning -Message "Need at least two files to process" ; return } + #if the process didn't return data then abandon now. + if (-not $merged) {Write-Warning -Message "The merge operation did not return any data."; return } + + $orderByProperties = $merged[0].psobject.properties.where({$_.name -match "row$"}).name + Write-Progress -Activity "Merging sheets" -CurrentOperation "creating output sheet '$OutputSheetName' in $OutputFile" + $excel = $merged | Sort-Object -Property $orderByProperties | + Export-Excel -Path $OutputFile -Worksheetname $OutputSheetName -ClearSheet -BoldTopRow -AutoFilter -PassThru + $sheet = $excel.Workbook.Worksheets[$OutputSheetName] + + #We will put in a conditional format for "if all the others are not flagged as 'same'" to mark rows where something is added, removed or changed + $sameChecks = @() + + #All the 'difference' columns in the sheet are labeled with the file they came from, 'reference' columns need their + #headers prefixed with the ref file name, $colnames is the basis of a regular expression to identify what should have $refPrefix appended + $colNames = @("^_Row$") + if ($key -ne "*") + {$colnames += "^$Key$"} + if ($filesToProcess.Count -ge 2) { + $refPrefix = (Split-Path -Path $filestoProcess[0] -Leaf) -replace "\.xlsx$"," " + } + else {$refPrefix = $WorksheetName[0] } + Write-Progress -Activity "Merging sheets" -CurrentOperation "applying formatting to sheet '$OutputSheetName' in $OutputFile" + #Find the column headings which are in the form "diffFile is"; which will hold 'Same', 'Added' or 'Changed' + foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "\sIS$"}) ) { + #Work leftwards across the headings applying conditional formatting which says + # 'Format this cell if the "IS" column has a value of ...' until you find a heading which doesn't have the prefix. + $prefix = $cell.value -replace "\sIS$","" + $columnNo = $cell.start.Column -1 + $cellAddr = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R1C$columnNo",1,$columnNo) + while ($sheet.cells[$cellAddr].value -match $prefix) { + $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='Solid'; Worksheet=$sheet; StopIfTrue=$true; Range=$([OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[1]C[$columnNo]:R[1048576]C[$columnNo]",0,0)) } + Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Added"' ) -BackgroundColor $AddBackgroundColor + Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Changed"') -BackgroundColor $ChangeBackgroundColor + Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Removed"') -BackgroundColor $DeleteBackgroundColor + $columnNo -- + $cellAddr = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R1C$columnNo",1,$columnNo) + } + #build up a list of prefixes in $colnames - we'll use that to set headers on rows from the reference file; and build up the "if the 'is' cell isn't same" list + $colNames += $prefix + $sameChecks += (($cell.Address -replace "1","2") +'<>"Same"') + } + + #For all the columns which don't match one of the Diff-file prefixes or "_Row" or the 'Key' columnn name; add the reference file prefix to their header. + $nameRegex = $colNames -Join '|' + foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -Notmatch $nameRegex}) ) { + $cell.Value = $refPrefix + $cell.Value + $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='Solid'; Worksheet=$sheet; StopIfTrue=$true; Range=[OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[2]C[$($cell.start.column)]:R[1048576]C[$($cell.start.column)]",0,0)} + Add-ConditionalFormatting @condFormattingParams -ConditionValue ("OR(" +(($sameChecks -join ",") -replace '<>"Same"','="Added"' ) +")" ) -BackgroundColor $DeleteBackgroundColor + Add-ConditionalFormatting @condFormattingParams -ConditionValue ("AND(" +(($sameChecks -join ",") -replace '<>"Same"','="Changed"') +")" ) -BackgroundColor $ChangeBackgroundColor + } + #We've made a bunch of things wider so now is the time to autofit columns. Any hiding has to come AFTER this, because it unhides things + if ($env:NoAutoSize) {Write-Warning "Autofit is not available with this OS configuration."} + else {$sheet.Cells.AutoFitColumns()} + + #if we have a key field (we didn't concatenate all fields) use what we built up in $sameChecks to apply conditional formatting to it (Row no will be in column A, Key in Column B) + if ($Key -ne '*') { + Add-ConditionalFormatting -Worksheet $sheet -Range "B2:B1048576" -ForeGroundColor $KeyFontColor -BackgroundPattern 'None' -RuleType Expression -ConditionValue ("OR(" +($sameChecks -join ",") +")" ) + $sheet.view.FreezePanes(2, 3) + } + else {$sheet.view.FreezePanes(2, 2) } + #Go back over the headings to find and hide the "is" columns; + foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "\sIS$"}) ) { + $sheet.Column($cell.start.Column).HIDDEN = $true + } + + #If specified, look over the headings for "row" and hide the columns which say "this was in row such-and-such" + if ($HideRowNumbers) { + foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "Row$"}) ) { + $sheet.Column($cell.start.Column).HIDDEN = $true + } + } + if ($Passthru) {$excel} + else {Close-ExcelPackage -ExcelPackage $excel -Show:$Show} + Write-Progress -Activity "Merging sheets" -Completed + } + } diff --git a/ExportedCommands/Merge-Worksheet.ps1 b/ExportedCommands/Merge-Worksheet.ps1 new file mode 100644 index 0000000..0674f65 --- /dev/null +++ b/ExportedCommands/Merge-Worksheet.ps1 @@ -0,0 +1,263 @@ +function Merge-Worksheet { + [cmdletbinding(SupportsShouldProcess=$true)] + Param( + [parameter(ParameterSetName='A',Mandatory=$true,Position=0)] #A = Compare two files default headers + [parameter(ParameterSetName='B',Mandatory=$true,Position=0)] #B = Compare two files user supplied headers + [parameter(ParameterSetName='C',Mandatory=$true,Position=0)] #C = Compare two files headers P1, P2, P3 etc + $Referencefile , + + [parameter(ParameterSetName='A',Mandatory=$true,Position=1)] + [parameter(ParameterSetName='B',Mandatory=$true,Position=1)] + [parameter(ParameterSetName='C',Mandatory=$true,Position=1)] + [parameter(ParameterSetName='E',Mandatory=$true,Position=1)] #D Compare two objects; E = Compare one object one file that uses default headers + [parameter(ParameterSetName='F',Mandatory=$true,Position=1)] #F = Compare one object one file that uses user supplied headers + [parameter(ParameterSetName='G',Mandatory=$true,Position=1)] #G Compare one object one file that uses headers P1, P2, P3 etc + $Differencefile , + + [parameter(ParameterSetName='A',Position=2)] #Applies to all sets EXCEPT D which is two objects (no sheets) + [parameter(ParameterSetName='B',Position=2)] + [parameter(ParameterSetName='C',Position=2)] + [parameter(ParameterSetName='E',Position=2)] + [parameter(ParameterSetName='F',Position=2)] + [parameter(ParameterSetName='G',Position=2)] + $WorksheetName = "Sheet1", + + [parameter(ParameterSetName='A')] #Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + [parameter(ParameterSetName='B')] + [parameter(ParameterSetName='C')] + [parameter(ParameterSetName='E')] + [parameter(ParameterSetName='F')] + [parameter(ParameterSetName='G')] + [int]$Startrow = 1, + + [Parameter(ParameterSetName='B',Mandatory=$true)] #Compare object + sheet or 2 sheets with user supplied headers + [Parameter(ParameterSetName='F',Mandatory=$true)] + [String[]]$Headername, + + [Parameter(ParameterSetName='C',Mandatory=$true)] #Compare object + sheet or 2 sheets with headers of P1, P2, P3 ... + [Parameter(ParameterSetName='G',Mandatory=$true)] + [switch]$NoHeader, + + [parameter(ParameterSetName='D',Mandatory=$true)] + [parameter(ParameterSetName='E',Mandatory=$true)] + [parameter(ParameterSetName='F',Mandatory=$true)] + [parameter(ParameterSetName='G',Mandatory=$true)] + [Alias('RefObject')] + $ReferenceObject , + [parameter(ParameterSetName='D',Mandatory=$true,Position=1)] + [Alias('DiffObject')] + $DifferenceObject , + [parameter(ParameterSetName='D',Position=2)] + [parameter(ParameterSetName='E',Position=2)] + [parameter(ParameterSetName='F',Position=2)] + [parameter(ParameterSetName='G',Position=2)] + $DiffPrefix = "=>" , + [parameter(Position=3)] + [Alias('OutFile')] + $OutputFile , + [parameter(Position=4)] + [Alias('OutSheet')] + $OutputSheetName = "Sheet1", + $Property = "*" , + $ExcludeProperty , + $Key = "Name" , + $KeyFontColor = [System.Drawing.Color]::DarkRed , + $ChangeBackgroundColor = [System.Drawing.Color]::Orange, + $DeleteBackgroundColor = [System.Drawing.Color]::LightPink, + $AddBackgroundColor = [System.Drawing.Color]::PaleGreen, + [switch]$HideEqual , + [switch]$Passthru , + [Switch]$Show + ) + + #region Read Excel data + if ($Differencefile -is [System.IO.FileInfo]) {$Differencefile = $Differencefile.FullName} + if ($Referencefile -is [System.IO.FileInfo]) {$Referencefile = $Referencefile.FullName} + if ($Referencefile -and $Differencefile) { + #if the filenames don't resolve, give up now. + try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} + Catch { Write-Warning -Message "Could not Resolve the filenames." ; return } + + #If we have one file , we must have two different Worksheet names. If we have two files $WorksheetName can be a single string or two strings. + if ($onefile -and ( ($WorksheetName.count -ne 2) -or $WorksheetName[0] -eq $WorksheetName[1] ) ) { + Write-Warning -Message "If both the Reference and difference file are the same then Worksheet name must provide 2 different names" + return + } + if ($WorksheetName.count -eq 2) {$Worksheet2 = $DiffPrefix = $WorksheetName[1] ; $Worksheet1 = $WorksheetName[0] ; } + elseif ($WorksheetName -is [string]) {$Worksheet2 = $Worksheet1 = $WorksheetName ; + $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" } + else {Write-Warning -Message "You must provide either a single Worksheet name or two names." ; return } + + $params= @{ ErrorAction = [System.Management.Automation.ActionPreference]::Stop } + foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} + try { + $ReferenceObject = Import-Excel -Path $Referencefile -WorksheetName $Worksheet1 @params + $DifferenceObject = Import-Excel -Path $Differencefile -WorksheetName $Worksheet2 @Params + } + Catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return } + if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} + } + elseif ( $Differencefile) { + if ($WorksheetName -isnot [string]) {Write-Warning -Message "You must provide a single Worksheet name." ; return } + $params = @{WorksheetName=$WorksheetName; Path=$Differencefile; ErrorAction=[System.Management.Automation.ActionPreference]::Stop } + foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} + try {$DifferenceObject = Import-Excel @Params } + Catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return } + if ($DiffPrefix -eq "=>" ) { + $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" + } + if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} + } + else { $firstDataRow = 1 } + #endregion + + #region Set lists of properties and row numbers + #Make a list of properties/headings using the Property (default "*") and ExcludeProperty parameters + $propList = @() + $DifferenceObject = $DifferenceObject | Update-FirstObjectProperties + $headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using get-member would sort them alphabetically! There may be extra properties in + if ($NoHeader -and "Name" -eq $Key) {$Key = "p1"} + if ($headings -notcontains $Key -and + ('*' -ne $Key)) {Write-Warning -Message "You need to specify one of the headings in the sheet '$Worksheet1' as a key." ; return } + foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )} + foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) } + if (($propList -notcontains $Key) -and + ('*' -ne $Key)) { $propList += $Key} #If $key isn't one of the headings we will have bailed by now + $propList = $propList | Select-Object -Unique #so, prolist must contain at least $key if nothing else + + #If key is "*" we treat it differently , and we will create a script property which concatenates all the Properties in $Proplist + $ConCatblock = [scriptblock]::Create( ($proplist | ForEach-Object {'$this."' + $_ + '"'}) -join " + ") + + #Build the list of the properties to output, in order. + $diffpart = @() + $refpart = @() + foreach ($p in $proplist.Where({$key -ne $_}) ) {$refPart += $p ; $diffPart += "$DiffPrefix $p" } + $lastRefColNo = $proplist.count + $FirstDiffColNo = $lastRefColNo + 1 + + if ($key -ne '*') { + $outputProps = @($key) + $refpart + $diffpart + #If we are using a single column as the key, don't duplicate it, so the last difference column will be A if there is one property, C if there are two, E if there are 3 + $lastDiffColNo = (2 * $proplist.count) - 1 + } + else { + $outputProps = @( ) + $refpart + $diffpart + #If we not using a single column as a key all columns are duplicated so, the Last difference column will be B if there is one property, D if there are two, F if there are 3 + $lastDiffColNo = (2 * $proplist.count ) + } + + #Add RowNumber to every row + #If one sheet has extra rows we can get a single "==" result from compare, with the row from the reference sheet, but + #the row in the other sheet might be different so we will look up the row number from the key field - build a hash table for that here + #If we have "*" as the key ad the script property to concatenate the [selected] properties. + + $Rowhash = @{} + $rowNo = $firstDataRow + foreach ($row in $ReferenceObject) { + if ($null -eq $row._row) {Add-Member -InputObject $row -MemberType NoteProperty -Value ($rowNo ++) -Name "_Row" } + else {$rowNo++ } + if ($Key -eq '*' ) {Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All" } + } + $rowNo = $firstDataRow + foreach ($row in $DifferenceObject) { + Add-Member -InputObject $row -MemberType NoteProperty -Value $rowNo -Name "$DiffPrefix Row" -Force + if ($Key -eq '*' ) { + Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All" + $Rowhash[$row._All] = $rowNo + } + else {$Rowhash[$row.$key] = $rowNo } + $rowNo ++ + } + if ($DifferenceObject.count -gt $Rowhash.Keys.Count) { + Write-Warning -Message "Difference object has $($DifferenceObject.Count) rows; but only $($Rowhash.keys.count) unique keys" + } + if ($Key -eq '*') {$key = "_ALL"} + #endregion + #We need to know all the properties we've met on the objects we've diffed + $eDiffProps = [ordered]@{} + #When we do a compare object changes will result in two rows so we group them and join them together. + $expandedDiff = Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property $propList -PassThru -IncludeEqual | + Group-Object -Property $key | ForEach-Object { + #The value of the key column is the name of the Group. + $keyval = $_.name + #we're going to create a custom object from a hash table. + $hash = [ordered]@{} + foreach ($result in $_.Group) { + if ($result.SideIndicator -ne "=>") {$hash["_Row"] = $result._Row } + elseif (-not $hash["$DiffPrefix Row"]) {$hash["_Row"] = "" } + #if we have already set the side, this must be the second record, so set side to indicate "changed"; if we got two "Same" indicators we may have a classh of keys + if ($hash.Side) { + if ($hash.Side -eq $result.SideIndicator) {Write-Warning -Message "'$keyval' may be a duplicate."} + $hash.Side = "<>" + } + else {$hash["Side"] = $result.SideIndicator} + switch ($hash.side) { + '==' { $hash["$DiffPrefix is"] = 'Same' } + '=>' { $hash["$DiffPrefix is"] = 'Added' } + '<>' { if (-not $hash["_Row"]) { + $hash["$DiffPrefix is"] = 'Added' + } + else { + $hash["$DiffPrefix is"] = 'Changed' + } + } + '<=' { $hash["$DiffPrefix is"] = 'Removed'} + } + #find the number of the row in the the "difference" object which has this key. If it is the object is only in the reference this will be blank. + $hash["$DiffPrefix Row"] = $Rowhash[$keyval] + $hash[$key] = $keyval + #Create FieldName and/or =>FieldName columns + foreach ($p in $result.psobject.Properties.name.where({$_ -ne $key -and $_ -ne "SideIndicator" -and $_ -ne "$DiffPrefix Row" })) { + if ($result.SideIndicator -eq "==" -and $p -in $propList) + {$hash[("$p")] = $hash[("$DiffPrefix $p")] = $result.$P} + elseif ($result.SideIndicator -eq "==" -or $result.SideIndicator -eq "<=") + {$hash[("$p")] = $result.$P} + elseif ($result.SideIndicator -eq "=>") { $hash[("$DiffPrefix $p")] = $result.$P} + } + } + + foreach ($k in $hash.keys) {$eDiffProps[$k] = $true} + [Pscustomobject]$hash + } | Sort-Object -Property "_row" + + #Already sorted by reference row number, fill in any blanks in the difference-row column. + for ($i = 1; $i -lt $expandedDiff.Count; $i++) {if (-not $expandedDiff[$i]."$DiffPrefix Row") {$expandedDiff[$i]."$DiffPrefix Row" = $expandedDiff[$i-1]."$DiffPrefix Row" } } + + #Now re-Sort by difference row number, and fill in any blanks in the reference-row column. + $expandedDiff = $expandedDiff | Sort-Object -Property "$DiffPrefix Row" + for ($i = 1; $i -lt $expandedDiff.Count; $i++) {if (-not $expandedDiff[$i]."_Row") {$expandedDiff[$i]."_Row" = $expandedDiff[$i-1]."_Row" } } + + $AllProps = @("_Row") + $OutputProps + $eDiffProps.keys.where({$_ -notin ($outputProps + @("_row","side","SideIndicator","_ALL" ))}) + + if ($PassThru -or -not $OutputFile) {return ($expandedDiff | Select-Object -Property $allprops | Sort-Object -Property "_row", "$DiffPrefix Row" ) } + elseif ($PSCmdlet.ShouldProcess($OutputFile,"Write Output to Excel file")) { + $expandedDiff = $expandedDiff | Sort-Object -Property "_row", "$DiffPrefix Row" + $xl = $expandedDiff | Select-Object -Property $OutputProps | Update-FirstObjectProperties | + Export-Excel -Path $OutputFile -Worksheetname $OutputSheetName -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -PassThru + $ws = $xl.Workbook.Worksheets[$OutputSheetName] + for ($i = 0; $i -lt $expandedDiff.Count; $i++ ) { + if ( $expandedDiff[$i].side -ne "==" ) { + Set-ExcelRange -Worksheet $ws -Range ("A" + ($i + 2 )) -FontColor $KeyFontColor + } + elseif ( $HideEqual ) {$ws.row($i+2).hidden = $true } + if ( $expandedDiff[$i].side -eq "<>" ) { + $range = $ws.Dimension -replace "\d+", ($i + 2 ) + Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $ChangeBackgroundColor + } + elseif ( $expandedDiff[$i].side -eq "<=" ) { + $rangeR1C1 = "R[{0}]C[1]:R[{0}]C[{1}]" -f ($i + 2 ) , $lastRefColNo + $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) + Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $DeleteBackgroundColor + } + elseif ( $expandedDiff[$i].side -eq "=>" ) { + if ($propList.count -gt 1) { + $rangeR1C1 = "R[{0}]C[{1}]:R[{0}]C[{2}]" -f ($i + 2 ) , $FirstDiffColNo , $lastDiffColNo + $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) + Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $AddBackgroundColor + } + Set-ExcelRange -Worksheet $ws -Range ("A" + ($i + 2 )) -BackgroundColor $AddBackgroundColor + } + } + Close-ExcelPackage -ExcelPackage $xl -Show:$Show + } +} diff --git a/New-ConditionalFormattingIconSet.ps1 b/ExportedCommands/New-ConditionalFormattingIconSet.ps1 similarity index 58% rename from New-ConditionalFormattingIconSet.ps1 rename to ExportedCommands/New-ConditionalFormattingIconSet.ps1 index acd7547..18ff937 100644 --- a/New-ConditionalFormattingIconSet.ps1 +++ b/ExportedCommands/New-ConditionalFormattingIconSet.ps1 @@ -1,32 +1,4 @@ function New-ConditionalFormattingIconSet { - <# - .SYNOPSIS - Creates an object which describes a conditional formatting rule a for 3,4 or 5 icon set. - .DESCRIPTION - Export-Excel takes a -ConditionalFormat parameter which can hold one or more descriptions for conditional formats; - this command builds the defintion of a Conditional formatting rule for an icon set. - .PARAMETER Range - The range of cells that the conditional format applies to. - .PARAMETER ConditionalFormat - The type of rule: one of "ThreeIconSet","FourIconSet" or "FiveIconSet" - .PARAMETER IconType - The name of an iconSet - different icons are available depending on whether 3,4 or 5 icon set is selected. - .PARAMETER Reverse - Use the icons in the reverse order. - .Example - $cfRange = [OfficeOpenXml.ExcelAddress]::new($topRow, $column, $lastDataRow, $column) - $cfdef = New-ConditionalFormattingIconSet -Range $cfrange -ConditionalFormat ThreeIconSet -IconType Arrows - Export-Excel -ExcelPackage $excel -ConditionalFormat $cfdef -show - - The first line creates a range - one column wide in the column $column, running - from $topRow to $lastDataRow. - The second line creates a definition object using this range - and the third uses Export-Excel with an open package to apply the format and - save and open the file. - .Link - Add-Add-ConditionalFormatting - New-ConditionalText - #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] param( [Parameter(Mandatory=$true)] diff --git a/ExportedCommands/New-ConditionalText.ps1 b/ExportedCommands/New-ConditionalText.ps1 new file mode 100644 index 0000000..a5b6743 --- /dev/null +++ b/ExportedCommands/New-ConditionalText.ps1 @@ -0,0 +1,41 @@ +function New-ConditionalText { + [cmdletbinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] + param( + #[Parameter(Mandatory=$true)] + [Alias("ConditionValue")] + $Text, + [Alias("ForeGroundColor")] + $ConditionalTextColor=[System.Drawing.Color]::DarkRed, + $BackgroundColor=[System.Drawing.Color]::LightPink, + [String]$Range, + [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid, + [ValidateSet( + "LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual", + "Equal", "NotEqual", + "Top", "TopPercent", "Bottom", "BottomPercent", + "ContainsText", "NotContainsText", "BeginsWith", "EndsWith", + "ContainsBlanks", "NotContainsBlanks", "ContainsErrors", "NotContainsErrors", + "DuplicateValues", "UniqueValues", + "Tomorrow", "Today", "Yesterday", "Last7Days", + "NextWeek", "ThisWeek", "LastWeek", + "NextMonth", "ThisMonth", "LastMonth", + "AboveAverage", "AboveOrEqualAverage", "BelowAverage", "BelowOrEqualAverage" + )] + [Alias("RuleType")] + $ConditionalType="ContainsText" + ) + + $obj = [PSCustomObject]@{ + Text = $Text + ConditionalTextColor = $ConditionalTextColor + ConditionalType = $ConditionalType + PatternType = $PatternType + Range = $Range + BackgroundColor = $BackgroundColor + } + + $obj.pstypenames.Clear() + $obj.pstypenames.Add("ConditionalText") + $obj +} \ No newline at end of file diff --git a/ExportedCommands/New-ExcelChartDefinition.ps1 b/ExportedCommands/New-ExcelChartDefinition.ps1 new file mode 100644 index 0000000..e657d84 --- /dev/null +++ b/ExportedCommands/New-ExcelChartDefinition.ps1 @@ -0,0 +1,88 @@ +function New-ExcelChartDefinition { + [Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook. + [cmdletbinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] + param( + $Title = "Chart Title", + $Header, + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked", + [OfficeOpenXml.Drawing.Chart.eTrendLine[]]$ChartTrendLine, + $XRange, + $YRange, + $Width = 500, + $Height = 350, + $Row = 0, + $RowOffSetPixels = 10, + $Column = 6, + $ColumnOffSetPixels = 5, + [OfficeOpenXml.Drawing.Chart.eLegendPosition]$LegendPosition, + $LegendSize, + [Switch]$LegendBold, + [Switch]$NoLegend, + [Switch]$ShowCategory, + [Switch]$ShowPercent, + $SeriesHeader, + [Switch]$TitleBold, + [Int]$TitleSize , + [String]$XAxisTitleText, + [Switch]$XAxisTitleBold, + $XAxisTitleSize , + [string]$XAxisNumberformat, + $XMajorUnit, + $XMinorUnit, + $XMaxValue, + $XMinValue, + [OfficeOpenXml.Drawing.Chart.eAxisPosition]$XAxisPosition , + [String]$YAxisTitleText, + [Switch]$YAxisTitleBold, + $YAxisTitleSize, + [string]$YAxisNumberformat, + $YMajorUnit, + $YMinorUnit, + $YMaxValue, + $YMinValue, + [OfficeOpenXml.Drawing.Chart.eAxisPosition]$YAxisPosition + ) + if ( $Header ) { Write-Warning "The header parameter is ignored." } #Nothing was done with it when creating a chart. + #might be able to do [PSCustomObject]$PsboundParameters, the defaults here match those in Add-Excel Chart + [PSCustomObject]@{ + Title = $Title + ChartType = $ChartType + ChartTrendLine = $ChartTrendLine + XRange = $XRange + YRange = $YRange + Width = $Width + Height = $Height + Row = $Row + RowOffSetPixels = $RowOffSetPixels + Column = $Column + ColumnOffSetPixels = $ColumnOffSetPixels + LegendPosition = $LegendPosition + LegendSize = $LegendSize + Legendbold = $LegendBold + NoLegend = $NoLegend -as [Boolean] + ShowCategory = $ShowCategory -as [Boolean] + ShowPercent = $ShowPercent -as [Boolean] + SeriesHeader = $SeriesHeader + TitleBold = $TitleBold -as [Boolean] + TitleSize = $TitleSize + XAxisTitleText = $XAxisTitleText + XAxisTitleBold = $XAxisTitleBold -as [Boolean] + XAxisTitleSize = $XAxisTitleSize + XAxisNumberformat = $XAxisNumberformat + XMajorUnit = $XMajorUnit + XMinorUnit = $XMinorUnit + XMaxValue = $XMaxValue + XMinValue = $XMinValue + XAxisPosition = $XAxisPosition + YAxisTitleText = $YAxisTitleText + YAxisTitleBold = $YAxisTitleBold -as [Boolean] + YAxisTitleSize = $YAxisTitleSize + YAxisNumberformat = $YAxisNumberformat + YMajorUnit = $YMajorUnit + YMinorUnit = $YMinorUnit + YMaxValue = $YMaxValue + YMinValue = $YMinValue + YAxisPosition = $YAxisPosition + } +} diff --git a/ExportedCommands/New-ExcelStyle.md b/ExportedCommands/New-ExcelStyle.md new file mode 100644 index 0000000..a71b355 --- /dev/null +++ b/ExportedCommands/New-ExcelStyle.md @@ -0,0 +1,570 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-ExcelStyle + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +New-ExcelStyle [[-Range] ] [[-NumberFormat] ] [[-BorderAround] ] + [[-BorderColor] ] [[-BorderBottom] ] [[-BorderTop] ] + [[-BorderLeft] ] [[-BorderRight] ] [[-FontColor] ] + [[-Value] ] [[-Formula] ] [-ArrayFormula] [-ResetFont] [-Bold] [-Italic] [-Underline] + [[-UnderLineType] ] [-StrikeThru] [[-FontShift] ] + [[-FontName] ] [[-FontSize] ] [[-BackgroundColor] ] + [[-BackgroundPattern] ] [[-PatternColor] ] [-WrapText] + [[-HorizontalAlignment] ] [[-VerticalAlignment] ] + [[-TextRotation] ] [-AutoSize] [[-Width] ] [[-Height] ] [-Hidden] [-Locked] [-Merge] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ArrayFormula +{{ Fill ArrayFormula Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoSize +{{ Fill AutoSize Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: AutoFit + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +{{ Fill BackgroundColor Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 15 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundPattern +{{ Fill BackgroundPattern Description }} + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: 16 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Bold +{{ Fill Bold Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderAround +{{ Fill BorderAround Description }} + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderBottom +{{ Fill BorderBottom Description }} + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderColor +{{ Fill BorderColor Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderLeft +{{ Fill BorderLeft Description }} + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderRight +{{ Fill BorderRight Description }} + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: 7 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderTop +{{ Fill BorderTop Description }} + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontColor +{{ Fill FontColor Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: ForegroundColor + +Required: False +Position: 8 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontName +{{ Fill FontName Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 13 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontShift +{{ Fill FontShift Description }} + +```yaml +Type: ExcelVerticalAlignmentFont +Parameter Sets: (All) +Aliases: +Accepted values: None, Baseline, Subscript, Superscript + +Required: False +Position: 12 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontSize +{{ Fill FontSize Description }} + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: 14 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Formula +{{ Fill Formula Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 10 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Height +{{ Fill Height Description }} + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: 22 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Hidden +{{ Fill Hidden Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HorizontalAlignment +{{ Fill HorizontalAlignment Description }} + +```yaml +Type: ExcelHorizontalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: General, Left, Center, CenterContinuous, Right, Fill, Distributed, Justify + +Required: False +Position: 18 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Italic +{{ Fill Italic Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Locked +{{ Fill Locked Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Merge +{{ Fill Merge Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumberFormat +{{ Fill NumberFormat Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: NFormat + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternColor +{{ Fill PatternColor Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: PatternColour + +Required: False +Position: 17 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Range +{{ Fill Range Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Address + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResetFont +{{ Fill ResetFont Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StrikeThru +{{ Fill StrikeThru Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TextRotation +{{ Fill TextRotation Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 20 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnderLineType +{{ Fill UnderLineType Description }} + +```yaml +Type: ExcelUnderLineType +Parameter Sets: (All) +Aliases: +Accepted values: None, Single, Double, SingleAccounting, DoubleAccounting + +Required: False +Position: 11 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Underline +{{ Fill Underline Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +{{ Fill Value Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 9 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VerticalAlignment +{{ Fill VerticalAlignment Description }} + +```yaml +Type: ExcelVerticalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: Top, Center, Bottom, Distributed, Justify + +Required: False +Position: 19 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Width +{{ Fill Width Description }} + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: 21 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WrapText +{{ Fill WrapText Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/ExportedCommands/New-ExcelStyle.ps1 b/ExportedCommands/New-ExcelStyle.ps1 new file mode 100644 index 0000000..f15b48f --- /dev/null +++ b/ExportedCommands/New-ExcelStyle.ps1 @@ -0,0 +1,45 @@ +function New-ExcelStyle { + param ( + [Alias("Address")] + $Range , + [Alias("NFormat")] + $NumberFormat, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, + $BorderColor=[System.Drawing.Color]::Black, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight, + [Alias('ForegroundColor')] + $FontColor, + $Value, + $Formula, + [Switch]$ArrayFormula, + [Switch]$ResetFont, + [Switch]$Bold, + [Switch]$Italic, + [Switch]$Underline, + [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, + [Switch]$StrikeThru, + [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, + [String]$FontName, + [float]$FontSize, + $BackgroundColor, + [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , + [Alias("PatternColour")] + $PatternColor, + [Switch]$WrapText, + [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, + [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, + [ValidateRange(-90, 90)] + [int]$TextRotation , + [Alias("AutoFit")] + [Switch]$AutoSize, + [float]$Width, + [float]$Height, + [Switch]$Hidden, + [Switch]$Locked, + [Switch]$Merge + ) + $PSBoundParameters +} \ No newline at end of file diff --git a/ExportedCommands/New-PSItem.md b/ExportedCommands/New-PSItem.md new file mode 100644 index 0000000..d2d8cac --- /dev/null +++ b/ExportedCommands/New-PSItem.md @@ -0,0 +1,42 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-PSItem + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +New-PSItem +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/New-PSItem.ps1 b/ExportedCommands/New-PSItem.ps1 similarity index 100% rename from New-PSItem.ps1 rename to ExportedCommands/New-PSItem.ps1 diff --git a/ExportedCommands/New-PivotTableDefinition.ps1 b/ExportedCommands/New-PivotTableDefinition.ps1 new file mode 100644 index 0000000..ce813c7 --- /dev/null +++ b/ExportedCommands/New-PivotTableDefinition.ps1 @@ -0,0 +1,72 @@ + +function New-PivotTableDefinition { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] + param( + [Parameter(Mandatory)] + [Alias("PivtoTableName")]#Previous typo - use alias to avoid breaking scripts + $PivotTableName, + $SourceWorkSheet, + $SourceRange, + $PivotRows, + [hashtable]$PivotData, + $PivotColumns, + $PivotFilter, + [Switch]$PivotDataToColumn, + [ValidateSet("Both", "Columns", "Rows", "None")] + [String]$PivotTotals = "Both", + [Switch]$NoTotalsInPivot, + [String]$GroupDateRow, + [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, + [String]$GroupNumericRow, + [double]$GroupNumericMin = 0 , + [double]$GroupNumericMax = [Double]::MaxValue , + [double]$GroupNumericInterval = 100 , + [string]$PivotNumberFormat, + [OfficeOpenXml.Table.TableStyles]$PivotTableStyle, + [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + $PivotChartDefinition, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$IncludePivotChart, + [Parameter(ParameterSetName = 'ChartbyParams')] + [String]$ChartTitle, + [Parameter(ParameterSetName = 'ChartbyParams')] + [int]$ChartHeight = 400 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [int]$ChartWidth = 600, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartRow = 0 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartColumn = 4, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartRowOffSetPixels = 0 , + [Parameter(ParameterSetName = 'ChartbyParams')] + [Int]$ChartColumnOffSetPixels = 0, + [Parameter(ParameterSetName = 'ChartbyParams')] + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$NoLegend, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$ShowCategory, + [Parameter(ParameterSetName = 'ChartbyParams')] + [Switch]$ShowPercent, + [switch]$Activate + ) + $validDataFuntions = [system.enum]::GetNames([OfficeOpenXml.Table.PivotTable.DataFieldFunctions]) + + if ($PivotData.values.Where( {$_ -notin $validDataFuntions}) ) { + Write-Warning -Message ("Pivot data functions might not be valid, they should be one of " + ($validDataFuntions -join ", ") + ".") + } + + $parameters = @{} + $PSBoundParameters + if ($NoTotalsInPivot) { + $parameters.Remove('NoTotalsInPivot') + $parameters["PivotTotals"] = "None" + } + $parameters.Remove('PivotTableName') + if ($PivotChartDefinition) { + $parameters.PivotChartDefinition.XRange = $null + $parameters.PivotChartDefinition.YRange = $null + $parameters.PivotChartDefinition.SeriesHeader = $null + } + @{$PivotTableName = $parameters} +} diff --git a/ExportedCommands/Open-ExcelPackage.ps1 b/ExportedCommands/Open-ExcelPackage.ps1 new file mode 100644 index 0000000..4277ba5 --- /dev/null +++ b/ExportedCommands/Open-ExcelPackage.ps1 @@ -0,0 +1,44 @@ +Function Open-ExcelPackage { + [CmdLetBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] + [OutputType([OfficeOpenXml.ExcelPackage])] + Param ( + #The path to the file to open. + [Parameter(Mandatory=$true)]$Path, + #If specified, any running instances of Excel will be terminated before opening the file. + [switch]$KillExcel, + #The password for a protected worksheet, as a [normal] string (not a secure string). + [String]$Password, + #By default Open-ExcelPackage will only opens an existing file; -Create instructs it to create a new file if required. + [switch]$Create + ) + + if($KillExcel) { + Get-Process -Name "excel" -ErrorAction Ignore | Stop-Process + while (Get-Process -Name "excel" -ErrorAction Ignore) {} + } + + $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) + #If -Create was not specified only open the file if it exists already (send a warning if it doesn't exist). + if ($Create -and -not (Test-Path -Path $path)) { + #Create the directory if required. + $targetPath = Split-Path -Parent -Path $Path + if (!(Test-Path -Path $targetPath)) { + Write-Debug "Base path $($targetPath) does not exist, creating" + $null = New-item -ItemType Directory -Path $targetPath -ErrorAction Ignore + } + New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path + } + elseif (Test-Path -Path $path) { + if ($Password) {$pkgobj = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path , $Password } + else {$pkgobj = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path } + if ($pkgobj) { + foreach ($w in $pkgobj.Workbook.Worksheets) { + $sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $w.name)) + Add-Member -InputObject $pkgobj -MemberType ScriptProperty -Name $w.name -Value $sb + } + return $pkgobj + } + } + else {Write-Warning "Could not find $path" } + } diff --git a/RemoveWorksheet.ps1 b/ExportedCommands/Remove-WorkSheet.ps1 similarity index 53% rename from RemoveWorksheet.ps1 rename to ExportedCommands/Remove-WorkSheet.ps1 index 1e919c5..2d465e1 100644 --- a/RemoveWorksheet.ps1 +++ b/ExportedCommands/Remove-WorkSheet.ps1 @@ -1,21 +1,4 @@ Function Remove-WorkSheet { - <# - .SYNOPSIS - Removes one or more worksheets from one or more workbooks - .EXAMPLE - C:\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1 - Removes the worksheet named 'Sheet1' from 'Test1.xlsx' - - C:\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 - Removes the worksheet named 'Sheet1' and 'Target1' from 'Test1.xlsx' - - C:\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 -Show - Removes the worksheets and then launches the xlsx in Excel - - C:\> dir c:\reports\*.xlsx | Remove-WorkSheet - Removes 'Sheet1' from all the xlsx files in the c:\reports directory - - #> [cmdletbinding(SupportsShouldProcess=$true)] param( # [Parameter(ValueFromPipelineByPropertyName)] diff --git a/ExportedCommands/Select-Worksheet.ps1 b/ExportedCommands/Select-Worksheet.ps1 new file mode 100644 index 0000000..0385876 --- /dev/null +++ b/ExportedCommands/Select-Worksheet.ps1 @@ -0,0 +1,24 @@ +function Select-Worksheet { + param ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Package', Position = 0)] + [OfficeOpenXml.ExcelPackage]$ExcelPackage, + [Parameter(Mandatory = $true, ParameterSetName = 'Workbook')] + [OfficeOpenXml.ExcelWorkbook]$ExcelWorkbook, + [Parameter(ParameterSetName='Package')] + [Parameter(ParameterSetName='Workbook')] + [string]$WorksheetName, + [Parameter(ParameterSetName='Sheet',Mandatory=$true)] + [OfficeOpenXml.ExcelWorksheet]$ExcelWorksheet + ) + #if we were given a package, use its workbook + if ($ExcelPackage -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelPackage.Workbook} + #if we now have workbook, get the worksheet; if we were given a sheet get the workbook + if ($ExcelWorkbook -and $WorksheetName) {$ExcelWorksheet = $ExcelWorkbook.Worksheets[$WorksheetName]} + elseif ($ExcelWorksheet -and -not $ExcelWorkbook) {$ExcelWorkbook = $ExcelWorksheet.Workbook ; } + #if we didn't get to a worksheet give up. If we did set all works sheets to not selected and then the one we want to selected. + if (-not $ExcelWorksheet) {Write-Warning -Message "The worksheet $WorksheetName was not found." ; return } + else { + foreach ($w in $ExcelWorkbook.Worksheets) {$w.View.TabSelected = $false} + $ExcelWorksheet.View.TabSelected = $true + } +} diff --git a/Send-SQLDataToExcel.ps1 b/ExportedCommands/Send-SQLDataToExcel.ps1 similarity index 51% rename from Send-SQLDataToExcel.ps1 rename to ExportedCommands/Send-SQLDataToExcel.ps1 index c7c3555..0ba3169 100644 --- a/Send-SQLDataToExcel.ps1 +++ b/ExportedCommands/Send-SQLDataToExcel.ps1 @@ -1,96 +1,4 @@ Function Send-SQLDataToExcel { - <# - .SYNOPSIS - Inserts a DataTable - returned by a SQL query - into an ExcelSheet - .DESCRIPTION - This command takes a SQL statement and run it against a database connection; for the connection it accepts either - * an object representing a session with a SQL server or ODBC database, or - * a connection string to make a session (if -MSSQLServer is specified it uses the SQL Native client, - and -Connection can be a server name instead of a detailed connection string. Without this switch it uses ODBC) - The command takes all the parameters of Export-Excel, except for -InputObject (alias TargetData); after - fetching the data it calls Export-Excel with the data as the value of InputParameter and whichever of - Export-Excel's parameters it was passed; for details of these parameters see the help for Export-Excel. - .PARAMETER Session - An active ODBC Connection or SQL connection object representing a session with a database which will be queried to get the data . - .PARAMETER Connection - A database connection string to be used to create a database session; either - * A Data source name written in the form DSN=ODBC_Data_Source_Name, or - * A full ODBC or SQL Native Client Connection string, or - * The name of a SQL server. - .PARAMETER MSSQLServer - Specifies the connection string is for SQL server, not ODBC. - .PARAMETER SQL - The SQL query to run against the session which was passed in -Session or set up from -Connection. - .PARAMETER Database - Switches to a specific database on a SQL server. - .PARAMETER QueryTimeout - Override the default query time of 30 seconds. - .PARAMETER DataTable - A System.Data.DataTable object containing the data to be inserted into the spreadsheet without running a query. - This remains supported to avoid breaking older scripts, but if you have a DataTable object you can pass the it - into Export-Excel using -InputObject. - .PARAMETER Force - If specified Export-Excel will be called with parameters specified, even if there is no data to send - .EXAMPLE - C:\> Send-SQLDataToExcel -MsSQLserver -Connection localhost -SQL "select name,type,type_desc from [master].[sys].[all_objects]" -Path .\temp.xlsx -WorkSheetname master -AutoSize -FreezeTopRow -AutoFilter -BoldTopRow - - Connects to the local SQL server and selects 3 columns from [Sys].[all_objects] and exports then to a sheet named master with some basic header management - .EXAMPLE - C:\> $dbPath = 'C:\Users\James\Documents\Database1.accdb' - C:\> $Connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbPath;" - C:\> $SQL="SELECT top 25 Name,Length From TestData ORDER BY Length DESC" - - C:\> Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo1.xlsx -WorkSheetname "Sizes" -AutoSize - - This creates an ODBC connection string to read from an Access file and a SQL Statement to extracts data from it, - and sends the resulting data to a new worksheet - - .EXAMPLE - C:\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' - C:\> $Connection = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=$dbPath;" - C:\> $SQL="SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + - " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" - - C:\> Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo2.xlsx -WorkSheetname "Winners" -AutoSize -AutoNameRange -ConditionalFormat @{DataBarColor="Blue"; Range="Wins"} - - Similar to the previous example this creates a connection string, this time for an Excel file, and runs - a SQL statement to get a list of motor-racing results, outputting the resulting data to a new spreadsheet. - The spreadsheet is formatted and a data bar added to show make the drivers' wins clearer. - (the F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) - .EXAMPLE - C:\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' - C:\> $SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + - " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" - C:\> $null = Get-SQL -Session F1 -excel -Connection $dbPath -sql $sql -OutputVariable Table - - C:\> Send-SQLDataToExcel -DataTable $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show - - This uses Get-SQL (at least V1.1 - download from the PowerShell gallery with Install-Module -Name GetSQL - - note the function is Get-SQL the module is GetSQL without the "-" ) - Get-SQL simplify making database connections and building /submitting SQL statements. - Here Get-SQL uses the same SQL statement as before; -OutputVariable leaves a System.Data.DataTable object in $table - and Send-SQLDataToExcel puts $table into the worksheet and sets it as an Excel table. - The command is equivalent to running - C:\> Export-Excel -inputObject $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show - This is quicker than using - C:\> Get-SQL | export-excel -ExcludeProperty rowerror,rowstate,table,itemarray,haserrors - (the F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) - .EXAMPLE - C:\> $SQL = "SELECT top 25 DriverName, Count(Win) as Wins FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" - C:\> Send-SQLDataToExcel -Session $DbSessions["f1"] -SQL $sql -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -ClearSheet -autosize -ColumnChart - - Like the previous example, this uses Get-SQL (download from the gallery with Install-Module -Name GetSQL). - It uses the database session which Get-SQL created, rather than an ODBC connection string. - The Session parameter can either be a object (as shown here), or the name used by Get-SQL ("F1" in this case). - Here the data is presented as a quick chart. - .EXAMPLE - C:\> Send-SQLDataToExcel -path .\demo4.xlsx -WorkSheetname "LR" -Connection "DSN=LR" -sql "SELECT name AS CollectionName FROM AgLibraryCollection Collection ORDER BY CollectionName" - - This example uses an Existing ODBC datasource name "LR" which maps to an adobe lightroom database and gets a list of collection names into a worksheet - - .Link - Export-Excel - #> [CmdletBinding(DefaultParameterSetName="none")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification="Allowed to use DBSessions Global variable from GETSQL Module")] diff --git a/ExportedCommands/Set-CellStyle.md b/ExportedCommands/Set-CellStyle.md new file mode 100644 index 0000000..c312af2 --- /dev/null +++ b/ExportedCommands/Set-CellStyle.md @@ -0,0 +1,119 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Set-CellStyle + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Set-CellStyle [[-WorkSheet] ] [[-Row] ] [[-LastColumn] ] [[-Pattern] ] + [[-Color] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Color +{{ Fill Color Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LastColumn +{{ Fill LastColumn Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Pattern +{{ Fill Pattern Description }} + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Row +{{ Fill Row Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheet +{{ Fill WorkSheet Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Set-CellStyle.ps1 b/ExportedCommands/Set-CellStyle.ps1 similarity index 100% rename from Set-CellStyle.ps1 rename to ExportedCommands/Set-CellStyle.ps1 diff --git a/Set-Column.ps1 b/ExportedCommands/Set-ExcelColumn.ps1 similarity index 57% rename from Set-Column.ps1 rename to ExportedCommands/Set-ExcelColumn.ps1 index 05543a5..2d080a1 100644 --- a/Set-Column.ps1 +++ b/ExportedCommands/Set-ExcelColumn.ps1 @@ -1,131 +1,50 @@ Function Set-ExcelColumn { - <# - .SYNOPSIS - Adds or modifies a column in an Excel worksheet, filling values, setting formatting and/or creating named ranges. - .DESCRIPTION - Set-ExcelColumn can take a value which is either a string containing a - value or formula or a scriptblock which evaluates to a string, - and optionally a column number and fills that value down the column. - A column heading can be specified, and the column can be made a named range. - The column can be formatted in the same operation. - .EXAMPLE - Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency' - - $ws contains a worksheet object - and column "E" is set to use the - local currency format. Intelisense will complete the names of predefined - number formats. You can see how currency is interpreted on the - local computer with the command - Expand-NumberFormat currency - .EXAMPLE - Set-ExcelColumn -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange - - Here, $WS already contains a worksheet which holds counts of races won - and fastest laps recorded by racing drivers (in columns C and E). - Set-ExcelColumn specifies that Column 7 should have a heading of - "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc - the new data cells should become a named range, which will also be - named "WinsToFastLaps" and the column width will be set automatically. - When a value begins with "=", it is treated as a formula. - If value is a script block it will be evaluated, so here the string "=E$row/C$Row" - will have the number of the current row inserted. See the value parameter for a list of - variables which can be used. Note than when evaluating an expression in a string, - it is necessary to wrap it in $() so $row is valid but $($row+1) is needed. To prevent - Variables merging into other parts of the string, use the back tick "$columnName`4" will - be "G4" - withouth the backtick the string will look for a variable named "columnName4" - - .EXAMPLE - Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize - - In this example, the worksheet in $ws has partial links to Wikipedia - pages in column B. The -Value parameter is a script block which - outputs a string beginning "https..." and ending with the value of - the cell at column B in the current row. - When given a valid URI, Set-ExcelColumn makes it a hyperlink. - The column will be autosized to fit the links. - .EXAMPLE - 4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange - - Again $ws contains a worksheet. Here columns 4 to 6 are made into - named ranges, row 1 is used for the range name - and the rest of the column becomes the range. - #> [cmdletbinding()] [Alias("Set-Column")] [OutputType([OfficeOpenXml.ExcelColumn],[String])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] Param ( - #If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. [Parameter(ParameterSetName="Package",Mandatory=$true)] [OfficeOpenXml.ExcelPackage]$ExcelPackage, - #The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. [Parameter(ParameterSetName="Package")] [String]$Worksheetname = "Sheet1", - #This passes the worksheet object instead of passing a sheet name and an Excelpackage object. [Parameter(ParameterSetName="sheet",Mandatory=$true)] [OfficeOpenXml.ExcelWorksheet]$Worksheet, - #Column to fill down - the first column is 1. 0 will be interpreted as first empty column. [Parameter(ValueFromPipeline=$true)] [ValidateRange(0,16384)] $Column = 0 , - #First row to fill data in. [ValidateRange(1,1048576)] [Int]$StartRow , - #A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. $Value , - #Optional column heading. $Heading , - #Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. [Alias("NFormat")] $NumberFormat, - #Style of border to draw around the row. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, - #Colour for the text - if none specified it will be left as it it is. $FontColor, - #Make text bold; use -Bold:$false to remove bold. [Switch]$Bold, - #Make text italic; use -Italic:$false to remove italic. [Switch]$Italic, - #Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. [Switch]$Underline, - #Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, - #Strike through text; use -StrikeThru:$false to remove strike through. [Switch]$StrikeThru, - #Subscript or Superscript (or None). [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, - #Font to use - Excel defaults to Calibri. [String]$FontName, - #Point size for the text. [float]$FontSize, - #Change background color. $BackgroundColor, - #Background pattern - "Solid" by default. [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , - #Secondary color for background pattern. [Alias("PatternColour")] $PatternColor, - #Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. [Switch]$WrapText, - #Position cell contents to Left, Right, Center etc. Default is "General". [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, - #Position cell contents to Top, Bottom or Center. [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, - #Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. [ValidateRange(-90, 90)] [int]$TextRotation , - #Attempt to auto-fit cells to the width their contents. [Alias("AutoFit")] [Switch]$AutoSize, - #Set cells to a fixed width, ignored if -AutoSize is specified. [float]$Width, - #Set the inserted data to be a named range. [Switch]$AutoNameRange, - #Hide the column. [Switch]$Hide, - #If specified, returns the range of cells which were affected. [Switch]$Specified, - #If specified, return an object representing the Column, to allow further work to be done on it. [Switch]$PassThru ) diff --git a/ExportedCommands/Set-ExcelRange.ps1 b/ExportedCommands/Set-ExcelRange.ps1 new file mode 100644 index 0000000..49ca0d0 --- /dev/null +++ b/ExportedCommands/Set-ExcelRange.ps1 @@ -0,0 +1,199 @@ +function Set-ExcelRange { + [cmdletbinding()] + [Alias("Set-Format")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] + Param ( + [Parameter(ValueFromPipeline = $true,Position=0)] + [Alias("Address")] + $Range , + [OfficeOpenXml.ExcelWorksheet]$WorkSheet , + [Alias("NFormat")] + $NumberFormat, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, + $BorderColor=[System.Drawing.Color]::Black, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft, + [OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight, + [Alias('ForegroundColor')] + $FontColor, + $Value, + $Formula, + [Switch]$ArrayFormula, + [Switch]$ResetFont, + [Switch]$Bold, + [Switch]$Italic, + [Switch]$Underline, + [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, + [Switch]$StrikeThru, + [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, + [String]$FontName, + [float]$FontSize, + $BackgroundColor, + [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , + [Alias("PatternColour")] + $PatternColor, + [Switch]$WrapText, + [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, + [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, + [ValidateRange(-90, 90)] + [int]$TextRotation , + [Alias("AutoFit")] + [Switch]$AutoSize, + [float]$Width, + [float]$Height, + [Switch]$Hidden, + [Switch]$Locked, + [Switch]$Merge + ) + process { + if ($Range -is [Array]) { + $null = $PSBoundParameters.Remove("Range") + $Range | Set-ExcelRange @PSBoundParameters + } + else { + #We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ] + if ($Range -is [OfficeOpenXml.Table.ExcelTable]) {$Range = $Range.Address} + elseif ($WorkSheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) { + $Range = $WorkSheet.Cells[$Range] + } + elseif ($Range -is [string]) {Write-Warning -Message "The range pararameter you have specified also needs a worksheet parameter." ;return} + #else we assume $Range is a range. + if ($ClearAll) { + $Range.Clear() + } + if ($ResetFont) { + $Range.Style.Font.Color.SetColor( ([System.Drawing.Color]::Black)) + $Range.Style.Font.Bold = $false + $Range.Style.Font.Italic = $false + $Range.Style.Font.UnderLine = $false + $Range.Style.Font.Strike = $false + $Range.Style.Font.VerticalAlign = [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]::None + } + if ($PSBoundParameters.ContainsKey('Underline')) { + $Range.Style.Font.UnderLine = [boolean]$Underline + $Range.Style.Font.UnderLineType = $UnderLineType + } + if ($PSBoundParameters.ContainsKey('Bold')) { + $Range.Style.Font.Bold = [boolean]$bold + } + if ($PSBoundParameters.ContainsKey('Italic')) { + $Range.Style.Font.Italic = [boolean]$italic + } + if ($PSBoundParameters.ContainsKey('StrikeThru')) { + $Range.Style.Font.Strike = [boolean]$StrikeThru + } + if ($PSBoundParameters.ContainsKey('FontSize')){ + $Range.Style.Font.Size = $FontSize + } + if ($PSBoundParameters.ContainsKey('FontName')){ + $Range.Style.Font.Name = $FontName + } + if ($PSBoundParameters.ContainsKey('FontShift')){ + $Range.Style.Font.VerticalAlign = $FontShift + } + if ($PSBoundParameters.ContainsKey('FontColor')){ + if ($FontColor -is [string]) {$FontColor = [System.Drawing.Color]::$FontColor } + $Range.Style.Font.Color.SetColor( $FontColor) + } + if ($PSBoundParameters.ContainsKey('TextRotation')) { + $Range.Style.TextRotation = $TextRotation + } + if ($PSBoundParameters.ContainsKey('WrapText')) { + $Range.Style.WrapText = [boolean]$WrapText + } + if ($PSBoundParameters.ContainsKey('HorizontalAlignment')) { + $Range.Style.HorizontalAlignment = $HorizontalAlignment + } + if ($PSBoundParameters.ContainsKey('VerticalAlignment')) { + $Range.Style.VerticalAlignment = $VerticalAlignment + } + if ($PSBoundParameters.ContainsKey('Merge')) { + $Range.Merge = [boolean]$Merge + } + if ($PSBoundParameters.ContainsKey('Value')) { + if ($Value -match '^=') {$PSBoundParameters["Formula"] = $Value -replace '^=','' } + else { + $Range.Value = $Value + if ($Value -is [datetime]) { $Range.Style.Numberformat.Format = 'm/d/yy h:mm' }# This is not a custom format, but a preset recognized as date and localized. It might be overwritten in a moment + if ($Value -is [timespan]) { $Range.Style.Numberformat.Format = '[h]:mm:ss' } + } + } + if ($PSBoundParameters.ContainsKey('Formula')) { + if ($ArrayFormula) {$Range.CreateArrayFormula(($Formula -replace '^=','')) } + else {$Range.Formula = ($Formula -replace '^=','') } + } + if ($PSBoundParameters.ContainsKey('NumberFormat')) { + $Range.Style.Numberformat.Format = (Expand-NumberFormat $NumberFormat) + } + if ($BorderColor -is [string]) {$BorderColor = [System.Drawing.Color]::$BorderColor } + if ($PSBoundParameters.ContainsKey('BorderAround')) { + $Range.Style.Border.BorderAround($BorderAround, $BorderColor) + } + if ($PSBoundParameters.ContainsKey('BorderBottom')) { + $Range.Style.Border.Bottom.Style=$BorderBottom + $Range.Style.Border.Bottom.Color.SetColor($BorderColor) + } + if ($PSBoundParameters.ContainsKey('BorderTop')) { + $Range.Style.Border.Top.Style=$BorderTop + $Range.Style.Border.Top.Color.SetColor($BorderColor) + } + if ($PSBoundParameters.ContainsKey('BorderLeft')) { + $Range.Style.Border.Left.Style=$BorderLeft + $Range.Style.Border.Left.Color.SetColor($BorderColor) + } + if ($PSBoundParameters.ContainsKey('BorderRight')) { + $Range.Style.Border.Right.Style=$BorderRight + $Range.Style.Border.Right.Color.SetColor($BorderColor) + } + if ($PSBoundParameters.ContainsKey('BackgroundColor')) { + $Range.Style.Fill.PatternType = $BackgroundPattern + if ($BackgroundColor -is [string]) {$BackgroundColor = [System.Drawing.Color]::$BackgroundColor } + $Range.Style.Fill.BackgroundColor.SetColor($BackgroundColor) + if ($PatternColor) { + if ($PatternColor -is [string]) {$PatternColor = [System.Drawing.Color]::$PatternColor } + $Range.Style.Fill.PatternColor.SetColor( $PatternColor) + } + } + if ($PSBoundParameters.ContainsKey('Height')) { + if ($Range -is [OfficeOpenXml.ExcelRow] ) {$Range.Height = $Height } + elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { + ($Range.Start.Row)..($Range.Start.Row + $Range.Rows) | + ForEach-Object {$Range.WorkSheet.Row($_).Height = $Height } + } + else {Write-Warning -Message ("Can set the height of a row or a range but not a {0} object" -f ($Range.GetType().name)) } + } + if ($Autosize -and -not $env:NoAutoSize) { + try { + if ($Range -is [OfficeOpenXml.ExcelColumn]) {$Range.AutoFit() } + elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { + $Range.AutoFitColumns() + + } + else {Write-Warning -Message ("Can autofit a column or a range but not a {0} object" -f ($Range.GetType().name)) } + } + catch {Write-Warning -Message "Failed autosizing columns of worksheet '$WorksheetName': $_"} + } + elseif ($AutoSize) {Write-Warning -Message "Auto-fitting columns is not available with this OS configuration." } + elseif ($PSBoundParameters.ContainsKey('Width')) { + if ($Range -is [OfficeOpenXml.ExcelColumn]) {$Range.Width = $Width} + elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { + ($Range.Start.Column)..($Range.Start.Column + $Range.Columns - 1) | + ForEach-Object { + #$ws.Column($_).Width = $Width + $Range.Worksheet.Column($_).Width = $Width + } + } + else {Write-Warning -Message ("Can set the width of a column or a range but not a {0} object" -f ($Range.GetType().name)) } + } + if ($PSBoundParameters.ContainsKey('Hidden')) { + if ($Range -is [OfficeOpenXml.ExcelRow] -or + $Range -is [OfficeOpenXml.ExcelColumn] ) {$Range.Hidden = [boolean]$Hidden} + else {Write-Warning -Message ("Can hide a row or a column but not a {0} object" -f ($Range.GetType().name)) } + } + if ($PSBoundParameters.ContainsKey('Locked')) { + $Range.Style.Locked=$Locked + } + } + } +} diff --git a/Set-Row.ps1 b/ExportedCommands/Set-ExcelRow.ps1 similarity index 64% rename from Set-Row.ps1 rename to ExportedCommands/Set-ExcelRow.ps1 index 0b3115b..67ef805 100644 --- a/Set-Row.ps1 +++ b/ExportedCommands/Set-ExcelRow.ps1 @@ -1,119 +1,52 @@ Function Set-ExcelRow { - <# - .Synopsis - Fills values into a [new] row in an Excel spreadsheet, and sets row formats. - .Description - Set-ExcelRow accepts either a Worksheet object or an ExcelPackage object - returned by Export-Excel and the name of a sheet, and inserts the chosen - contents into a row of the sheet. The contents can be a constant, - like "42", a formula or a script block which is converted into a - constant or a formula. - The first cell of the row can optionally be given a heading. - .Example - Set-ExcelRow -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" } - - $Ws contains a worksheet object, and no Row number is specified so - Set-ExcelRow will select the next row after the end of the data in - the sheet. The first cell in the row will contain "Total", and - each of the other cells will contain - =Sum(xx2:xx99) - where xx is the column name, and 99 is the last row of data. - Note the use of `2 to Prevent 2 becoming part of the variable "ColumnName" - The script block can use $Worksheet, $Row, $Column (number), - $ColumnName (letter), $StartRow/Column and $EndRow/Column. - .Example - Set-ExcelRow -Worksheet $ws -Heading Total -HeadingBold -Value {"=sum($columnName`2:$columnName$endrow)" } -NumberFormat 'Currency' -StartColumn 2 -Bold -BorderTop Double -BorderBottom Thin - - This builds on the previous example, but this time the label "Total" - appears in column 2 and the formula fills from column 3 onwards. - The formula and heading are set in bold face, and the formula is - formatted for the local currency, and given a double line border - above and single line border below. - #> [cmdletbinding()] [Alias("Set-Row")] [OutputType([OfficeOpenXml.ExcelRow],[String])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] Param ( - #An Excel package object - e.g. from Export-Excel -PassThru - requires a sheet name. [Parameter(ParameterSetName="Package",Mandatory=$true)] [OfficeOpenXml.ExcelPackage]$ExcelPackage, - #The name of the sheet to update in the package. [Parameter(ParameterSetName="Package")] $Worksheetname = "Sheet1", - #A worksheet object instead of passing a name and package. [Parameter(ParameterSetName="Sheet",Mandatory=$true)] [OfficeOpenXml.Excelworksheet] $Worksheet, - #Row to fill right - first row is 1. 0 will be interpreted as first unused row. [Parameter(ValueFromPipeline = $true)] $Row = 0 , - #Position in the row to start from. [int]$StartColumn, - #Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. $Value, - #Optional row-heading. $Heading , - #Set the heading in bold type. [Switch]$HeadingBold, - #Change the font-size of the heading. [Int]$HeadingSize , - #Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. [Alias("NFormat")] $NumberFormat, - #Style of border to draw around the row. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, - #Color of the border. $BorderColor=[System.Drawing.Color]::Black, - #Style for the bottom border. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom, - #Style for the top border. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop, - #Style for the left border. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft, - #Style for the right border. [OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight, - #Color for the text - if none specified it will be left as it it is. $FontColor, - #Make text bold; use -Bold:$false to remove bold. [Switch]$Bold, - #Make text italic; use -Italic:$false to remove italic. [Switch]$Italic, - #Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. [Switch]$Underline, - #Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, - #Strike through text; use -StrikeThru:$false to remove strike through. [Switch]$StrikeThru, - #Subscript or Superscript (or none). [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, - #Font to use - Excel defaults to Calibri. [String]$FontName, - #Point size for the text. [float]$FontSize, - #Change background color. $BackgroundColor, - #Background pattern - solid by default. [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , - #Secondary color for background pattern. [Alias("PatternColour")] $PatternColor, - #Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. [Switch]$WrapText, - #Position cell contents to Left, Right, Center etc. default is 'General'. [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, - #Position cell contents to Top, Bottom or Center. [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, - #Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. [ValidateRange(-90, 90)] [int]$TextRotation , - #Set cells to a fixed height. [float]$Height, - #Hide the row. [Switch]$Hide, - #If sepecified, returns the range of cells which were affected. [Switch]$ReturnRange, - #If Specified, return a row object to allow further work to be done. [Switch]$PassThru ) begin { diff --git a/ExportedCommands/Set-WorkSheetProtection.md b/ExportedCommands/Set-WorkSheetProtection.md new file mode 100644 index 0000000..ec1c389 --- /dev/null +++ b/ExportedCommands/Set-WorkSheetProtection.md @@ -0,0 +1,349 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Set-WorkSheetProtection + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Set-WorkSheetProtection [-WorkSheet] [-IsProtected] [-AllowAll] [-BlockSelectLockedCells] + [-BlockSelectUnlockedCells] [-AllowFormatCells] [-AllowFormatColumns] [-AllowFormatRows] [-AllowInsertColumns] + [-AllowInsertRows] [-AllowInsertHyperlinks] [-AllowDeleteColumns] [-AllowDeleteRows] [-AllowSort] + [-AllowAutoFilter] [-AllowPivotTables] [-BlockEditObject] [-BlockEditScenarios] [[-LockAddress] ] + [[-UnLockAddress] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -AllowAll +{{ Fill AllowAll Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowAutoFilter +{{ Fill AllowAutoFilter Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowDeleteColumns +{{ Fill AllowDeleteColumns Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowDeleteRows +{{ Fill AllowDeleteRows Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowFormatCells +{{ Fill AllowFormatCells Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowFormatColumns +{{ Fill AllowFormatColumns Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowFormatRows +{{ Fill AllowFormatRows Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowInsertColumns +{{ Fill AllowInsertColumns Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowInsertHyperlinks +{{ Fill AllowInsertHyperlinks Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowInsertRows +{{ Fill AllowInsertRows Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowPivotTables +{{ Fill AllowPivotTables Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllowSort +{{ Fill AllowSort Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BlockEditObject +{{ Fill BlockEditObject Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BlockEditScenarios +{{ Fill BlockEditScenarios Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BlockSelectLockedCells +{{ Fill BlockSelectLockedCells Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BlockSelectUnlockedCells +{{ Fill BlockSelectUnlockedCells Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IsProtected +{{ Fill IsProtected Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LockAddress +{{ Fill LockAddress Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnLockAddress +{{ Fill UnLockAddress Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheet +{{ Fill WorkSheet Description }} + +```yaml +Type: ExcelWorksheet +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Set-WorkSheetProtection.ps1 b/ExportedCommands/Set-WorkSheetProtection.ps1 similarity index 51% rename from Set-WorkSheetProtection.ps1 rename to ExportedCommands/Set-WorkSheetProtection.ps1 index 1b46560..e17f3c7 100644 --- a/Set-WorkSheetProtection.ps1 +++ b/ExportedCommands/Set-WorkSheetProtection.ps1 @@ -1,56 +1,27 @@ Function Set-WorkSheetProtection { [Cmdletbinding()] - <# - .Synopsis - Sets protection on the worksheet - .Description - - .Example - Set-WorkSheetProtection -WorkSheet $planSheet -IsProtected -AllowAll -AllowInsertColumns:$false -AllowDeleteColumns:$false -UnLockAddress "A:N" - Turns on protection for the worksheet in $planSheet, checks all the allow boxes except Insert and Delete columns and unlocks columns A-N - #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] param ( - #The worksheet where protection is to be applied. [Parameter(Mandatory=$true)] [OfficeOpenXml.ExcelWorksheet]$WorkSheet , - #Value of the "Protect Worksheet and Contents of locked cells" check box. Initially FALSE. use -IsProtected:$false to turn off it it has been switched on [switch]$IsProtected, - #If provided sets all the ALLOW options to true or false and then allows them to be changed individually [switch]$AllowAll, - #Opposite of the value in the 'Select locked cells' check box. Set to allow when Protect is first enabled [switch]$BlockSelectLockedCells, - #Opposite of the value in the 'Select unlocked cells' check box. Set to allow when Protect is first enabled [switch]$BlockSelectUnlockedCells, - #Value of the 'Format Cells' check box. Set to block when Protect is first enabled [switch]$AllowFormatCells, - #Value of the 'Format Columns' check box. Set to block when Protect is first enabled [switch]$AllowFormatColumns, - #Value of the 'Format Rows' check box. Set to block when Protect is first enabled [switch]$AllowFormatRows, - #Value of the 'Insert Columns' check box. Set to block when Protect is first enabled [switch]$AllowInsertColumns, - #Value of the 'Insert Columns' check box. Set to block when Protect is first enabled [switch]$AllowInsertRows, - #Value of the 'Insert Hyperlinks' check box. Set to block when Protect is first enabled [switch]$AllowInsertHyperlinks, - #Value of the 'Delete Columns' check box. Set to block when Protect is first enabled [switch]$AllowDeleteColumns, - #Value of the 'Delete Rows' check box. Set to block when Protect is first enabled [switch]$AllowDeleteRows, - #Value of the 'Sort' check box. Set to block when Protect is first enabled [switch]$AllowSort, - #Value of the 'Use AutoFilter' check box. Set to block when Protect is first enabled [switch]$AllowAutoFilter, - #Value of the 'Use PivotTable and PivotChart' check box. Set to block when Protect is first enabled [switch]$AllowPivotTables, - ##Opposite of the value in the 'Edit objects' check box. Set to allow when Protect is first enabled [switch]$BlockEditObject, - ##Opposite of the value in the 'Edit Scenarios' check box. Set to allow when Protect is first enabled [switch]$BlockEditScenarios, - #Address range for cells to lock in the form "A:Z" or "1:10" or "A1:Z10". If No range is specified, the whole sheet is locked by default. [string]$LockAddress, - #Address range for cells to Unlock in the form "A:Z" or "1:10" or "A1:Z10" [string]$UnLockAddress ) diff --git a/ExportedCommands/Update-FirstObjectProperties.ps1 b/ExportedCommands/Update-FirstObjectProperties.ps1 new file mode 100644 index 0000000..c859576 --- /dev/null +++ b/ExportedCommands/Update-FirstObjectProperties.ps1 @@ -0,0 +1,23 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Update*', Justification='Does not change system state')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Scope='Function', Target='Update*', Justification='Property would be incorrect')] + +param() + +Function Update-FirstObjectProperties { + + Try { + $Union = @() + $Input | ForEach-Object { + If ($Union.Count) { + $_ | Get-Member | Where-Object {-not ($Union[0] | Get-Member $_.Name)} | ForEach-Object { + $Union[0] | Add-Member -MemberType NoteProperty -Name $_.Name -Value $Null + } + } + $Union += $_ + } + $Union + } + Catch { + throw "Failed updating the properties of the first object: $_" + } +} \ No newline at end of file diff --git a/Get-ExcelWorkbookInfo.ps1 b/Get-ExcelWorkbookInfo.ps1 deleted file mode 100644 index ab4c845..0000000 --- a/Get-ExcelWorkbookInfo.ps1 +++ /dev/null @@ -1,65 +0,0 @@ -Function Get-ExcelWorkbookInfo { - <# - .SYNOPSIS - Retrieve information of an Excel workbook. - .DESCRIPTION - The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage. - .PARAMETER Path - Specifies the path to the Excel file. This parameter is required. - .EXAMPLE - Get-ExcelWorkbookInfo .\Test.xlsx - - CorePropertiesXml : #document - Title : - Subject : - Author : Konica Minolta User - Comments : - Keywords : - LastModifiedBy : Bond, James (London) GBR - LastPrinted : 2017-01-21T12:36:11Z - Created : 17/01/2017 13:51:32 - Category : - Status : - ExtendedPropertiesXml : #document - Application : Microsoft Excel - HyperlinkBase : - AppVersion : 14.0300 - Company : Secret Service - Manager : - Modified : 10/02/2017 12:45:37 - CustomPropertiesXml : #document - - .NOTES - CHANGELOG - 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) - - .LINK - https://github.com/dfinke/ImportExcel - #> - - [CmdletBinding()] - Param ( - [Alias('FullName')] - [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] - [String]$Path - ) - - Process { - Try { - $Path = (Resolve-Path $Path).ProviderPath - - $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream - $workbook = $xl.Workbook - $workbook.Properties - - $stream.Close() - $stream.Dispose() - $xl.Dispose() - $xl = $null - } - Catch { - throw "Failed retrieving Excel workbook information for '$Path': $_" - } - } -} diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index a74ca84..c602500 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -73,7 +73,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Close-ExcelPackage', 'ColumnChart', 'Compare-WorkSheet', - 'Convert-XlRangeToImage', + 'Convert-ExcelRangeToImage', 'ConvertFrom-ExcelData', 'ConvertFrom-ExcelSheet', 'ConvertFrom-ExcelToSQLInsert', @@ -107,7 +107,6 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'New-PivotTableDefinition', 'New-Plot', 'New-PSItem', - 'NumberFormatCompletion', 'Open-ExcelPackage', 'PieChart', 'Pivot', @@ -135,6 +134,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 # Aliases to export from this module AliasesToExport = @( + 'Convert-XlRangeToImage' 'New-ExcelChart', 'Set-Column', 'Set-Format', diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 5331493..6bc76f5 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -1,65 +1,9 @@ #region import everything we need Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" -. $PSScriptRoot\AddConditionalFormatting.ps1 -. $PSScriptRoot\AddDataValidation.ps1 -. $PSScriptRoot\Charting.ps1 -. $PSScriptRoot\ColorCompletion.ps1 -. $PSScriptRoot\Compare-WorkSheet.ps1 -. $PSScriptRoot\ConvertExcelToImageFile.ps1 -. $PSScriptRoot\ConvertFromExcelData.ps1 -. $PSScriptRoot\ConvertFromExcelToSQLInsert.ps1 -. $PSScriptRoot\ConvertToExcelXlsx.ps1 -. $PSScriptRoot\Copy-ExcelWorkSheet.ps1 -. $PSScriptRoot\Export-Excel.ps1 -. $PSScriptRoot\Export-ExcelSheet.ps1 -. $PSScriptRoot\Export-StocksToExcel.ps1 -. $PSScriptRoot\Get-ExcelColumnName.ps1 -. $PSScriptRoot\Get-ExcelSheetInfo.ps1 -. $PSScriptRoot\Get-ExcelWorkbookInfo.ps1 -. $PSScriptRoot\Get-HtmlTable.ps1 -. $PSScriptRoot\Get-Range.ps1 -. $PSScriptRoot\Get-XYRange.ps1 -. $PSScriptRoot\Import-Html.ps1 -. $PSScriptRoot\InferData.ps1 -. $PSScriptRoot\Invoke-Sum.ps1 -. $PSScriptRoot\Join-Worksheet.ps1 -. $PSScriptRoot\Merge-Worksheet.ps1 -. $PSScriptRoot\New-ConditionalFormattingIconSet.ps1 -. $PSScriptRoot\New-ConditionalText.ps1 -. $PSScriptRoot\New-ExcelChart.ps1 -. $PSScriptRoot\New-PSItem.ps1 -. $PSScriptRoot\Open-ExcelPackage.ps1 -. $PSScriptRoot\Pivot.ps1 -. $PSScriptRoot\PivotTable.ps1 -#. $PSScriptRoot\Plot.ps1 -. $PSScriptRoot\RemoveWorksheet.ps1 -. $PSScriptRoot\Send-SQLDataToExcel.ps1 -. $PSScriptRoot\Set-CellStyle.ps1 -. $PSScriptRoot\Set-Column.ps1 -. $PSScriptRoot\Set-Row.ps1 -. $PSScriptRoot\Set-WorkSheetProtection.ps1 -. $PSScriptRoot\SetFormat.ps1 -. $PSScriptRoot\TrackingUtils.ps1 -. $PSScriptRoot\Update-FirstObjectProperties.ps1 +try {[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")} +catch {Write-Warning -Message "System.Drawing could not be loaded. Color and font look-ups may not be available."} -New-Alias -Name Use-ExcelData -Value "ConvertFrom-ExcelData" -Force - -if ($PSVersionTable.PSVersion.Major -ge 5) { - . $PSScriptRoot\Plot.ps1 - - Function New-Plot { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'New-Plot does not change system state')] - Param() - - [PSPlot]::new() - } - -} -else { - Write-Warning 'PowerShell 5 is required for plot.ps1' - Write-Warning 'PowerShell Excel is ready, except for that functionality' -} if (($IsLinux -or $IsMacOS) -or $env:NoAutoSize) { $ExcelPackage = [OfficeOpenXml.ExcelPackage]::new() $Cells = ($ExcelPackage | Add-WorkSheet).Cells['A1'] @@ -83,509 +27,30 @@ if (($IsLinux -or $IsMacOS) -or $env:NoAutoSize) { $ExcelPackage | Close-ExcelPackage -NoSave } } + +Get-ChildItem -Path "$PSScriptRoot\ExportedCommands\*.ps1" | ForEach-Object {. $_.FullName} + +. $PSScriptRoot\Charting.ps1 +. $PSScriptRoot\Export-StocksToExcel.ps1 +. $PSScriptRoot\InferData.ps1 +. $PSScriptRoot\Pivot.ps1 + + +if ($PSVersionTable.PSVersion.Major -ge 5) { + . $PSScriptRoot\Plot.ps1 + + Function New-Plot { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'New-Plot does not change system state')] + Param() + + [PSPlot]::new() + } + +} +else { + Write-Warning 'PowerShell 5 is required for plot.ps1' + Write-Warning 'PowerShell Excel is ready, except for that functionality' +} #endregion -function Import-Excel { - <# - .SYNOPSIS - Create custom objects from the rows in an Excel worksheet. - .DESCRIPTION - The Import-Excel cmdlet creates custom objects from the rows in an Excel worksheet. Each row represents one object. All of this is possible without installing Microsoft Excel and by using the .NET library ‘EPPLus.dll’. - - By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blank property name, only columns with column headers will be imported. - - If the default behavior is not desired and you want to import the complete worksheet ‘as is’, the parameter ‘-NoHeader’ can be used. In case you want to provide your own property names, you can use the parameter ‘-HeaderName’. - - .PARAMETER Path - Specifies the path to the Excel file. - .PARAMETER ExcelPackage - Instead of specifying a path provides an Excel Package object (from Open-ExcelPackage) - Using this avoids re-reading the whole file when importing multiple parts of it. - To allow multiple read operations Import-Excel does NOT close the package, and you should use - Close-ExcelPackage -noSave to close it. - .PARAMETER WorksheetName - Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. - - .PARAMETER DataOnly - Import only rows and columns that contain data, empty rows and empty columns are not imported. - - .PARAMETER HeaderName - Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. - If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. - If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. - - .PARAMETER NoHeader - Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. - This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names. - - .PARAMETER StartRow - The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. - When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. - - .PARAMETER EndRow - By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. - - .PARAMETER StartColumn - The number of the first column to read data from (1 by default). - - .PARAMETER EndColumn - By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. - - .PARAMETER AsText - Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. * is supported as a wildcard. - - .PARAMETER Password - Accepts a string that will be used to open a password protected Excel file. - - .EXAMPLE - Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the column names defined in the first row. In case a column doesn’t have a column header (usually in row 1 when ‘-StartRow’ is not used), then the unnamed columns will be skipped and the data in those columns will not be imported. - - ---------------------------------------------- - | File: Movies.xlsx - Sheet: Actors | - ---------------------------------------------- - | A B C | - |1 First Name Address | - |2 Chuck Norris California | - |3 Jean-Claude Vandamme Brussels | - ---------------------------------------------- - - PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors - - First Name: Chuck - Address : California - - First Name: Jean-Claude - Address : Brussels - - Notice that column 'B' is not imported because there's no value in cell 'B1' that can be used as property name for the objects. - - .EXAMPLE - Import the complete Excel worksheet ‘as is’ by using the ‘-NoHeader’ switch. One object is created for each row. The property names of the objects will be automatically generated (P1, P2, P3, ..). - - ---------------------------------------------- - | File: Movies.xlsx - Sheet: Actors | - ---------------------------------------------- - | A B C | - |1 First Name Address | - |2 Chuck Norris California | - |3 Jean-Claude Vandamme Brussels | - ---------------------------------------------- - - PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -NoHeader - - P1: First Name - P2: - P3: Address - - P1: Chuck - P2: Norris - P3: California - - P1: Jean-Claude - P2: Vandamme - P3: Brussels - - Notice that the column header (row 1) is imported as an object too. - - .EXAMPLE - Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the names defined in the parameter ‘-HeaderName’. The properties are named starting from the most left column (A) to the right. In case no value is present in one of the columns, that property will have an empty value. - - ---------------------------------------------------------- - | File: Movies.xlsx - Sheet: Movies | - ---------------------------------------------------------- - | A B C D | - |1 The Bodyguard 1992 9 | - |2 The Matrix 1999 8 | - |3 | - |4 Skyfall 2012 9 | - ---------------------------------------------------------- - - PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -HeaderName 'Movie name', 'Year', 'Rating', 'Genre' - - Movie name: The Bodyguard - Year : 1992 - Rating : 9 - Genre : - - Movie name: The Matrix - Year : 1999 - Rating : 8 - Genre : - - Movie name: - Year : - Rating : - Genre : - - Movie name: Skyfall - Year : 2012 - Rating : 9 - Genre : - - Notice that empty rows are imported and that data for the property 'Genre' is not present in the worksheet. As such, the 'Genre' property will be blanc for all objects. - - .EXAMPLE - Import data from an Excel worksheet. One object is created for each row. The property names of the objects are automatically generated by using the switch ‘-NoHeader’ (P1, P@, P#, ..). The switch ‘-DataOnly’ will speed up the import because empty rows and empty columns are not imported. - - ---------------------------------------------------------- - | File: Movies.xlsx - Sheet: Movies | - ---------------------------------------------------------- - | A B C D | - |1 The Bodyguard 1992 9 | - |2 The Matrix 1999 8 | - |3 | - |4 Skyfall 2012 9 | - ---------------------------------------------------------- - - PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies –NoHeader -DataOnly - - P1: The Bodyguard - P2: 1992 - P3: 9 - - P1: The Matrix - P2: 1999 - P3: 8 - - P1: Skyfall - P2: 2012 - P3: 9 - - Notice that empty rows and empty columns are not imported. - - .EXAMPLE - Import data from an Excel worksheet. One object is created for each row. The property names are provided with the ‘-HeaderName’ parameter. The import will start from row 2 and empty columns and rows are not imported. - - ---------------------------------------------------------- - | File: Movies.xlsx - Sheet: Actors | - ---------------------------------------------------------- - | A B C D | - |1 Chuck Norris California | - |2 | - |3 Jean-Claude Vandamme Brussels | - ---------------------------------------------------------- - - PS C:\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -DataOnly -HeaderName 'FirstName', 'SecondName', 'City' –StartRow 2 - - FirstName : Jean-Claude - SecondName: Vandamme - City : Brussels - - Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with ‘Chuck Norris’ has not been imported, because we started the import from row 2 with the parameter ‘-StartRow 2’. - - .EXAMPLE - > - PS> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | - Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force - - Imports data from an Excel file and pipe the data to the Write-SqlTableData to be INSERTed into a table in a SQL Server database. - The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows. - The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in. - NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet. - - .LINK - https://github.com/dfinke/ImportExcel - - .NOTES - #> - - [CmdLetBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] - Param ( - [Alias('FullName')] - [Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] - [Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] - [Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] - [String]$Path, - [Parameter(ParameterSetName = "PackageA", Mandatory)] - [Parameter(ParameterSetName = "PackageB", Mandatory)] - [Parameter(ParameterSetName = "PackageC", Mandatory)] - [OfficeOpenXml.ExcelPackage]$ExcelPackage, - [Alias('Sheet')] - [Parameter(Position = 1)] - [ValidateNotNullOrEmpty()] - [String]$WorksheetName, - [Parameter(ParameterSetName = 'PathB' , Mandatory)] - [Parameter(ParameterSetName = 'PackageB', Mandatory)] - [String[]]$HeaderName , - [Parameter(ParameterSetName = 'PathC' , Mandatory)] - [Parameter(ParameterSetName = 'PackageC', Mandatory)] - [Switch]$NoHeader , - [Alias('HeaderRow', 'TopRow')] - [ValidateRange(1, 9999)] - [Int]$StartRow = 1, - [Alias('StopRow', 'BottomRow')] - [Int]$EndRow , - [Alias('LeftColumn')] - [Int]$StartColumn = 1, - [Alias('RightColumn')] - [Int]$EndColumn , - [Switch]$DataOnly, - [string[]]$AsText, - [ValidateNotNullOrEmpty()] - [String]$Password - ) - begin { - $sw = [System.Diagnostics.Stopwatch]::StartNew() - - Function Get-PropertyNames { - <# - .SYNOPSIS - Create objects containing the column number and the column name for each of the different header types. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")] - Param ( - [Parameter(Mandatory)] - [Int[]]$Columns, - [Parameter(Mandatory)] - [Int]$StartRow - ) - - Try { - if ($HeaderName) { - $i = 0 - foreach ($H in $HeaderName) { - $H | Select-Object @{N = 'Column'; E = { $Columns[$i] } }, @{N = 'Value'; E = { $H } } - $i++ - } - } - elseif ($NoHeader) { - $i = 0 - foreach ($C in $Columns) { - $i++ - $C | Select-Object @{N = 'Column'; E = { $_ } }, @{N = 'Value'; E = { 'P' + $i } } - } - } - - else { - if ($StartRow -lt 1) { - throw 'The top row can never be less than 1 when we need to retrieve headers from the worksheet.' ; return - } - - foreach ($C in $Columns) { - $Worksheet.Cells[$StartRow, $C] | Where-Object { $_.Value } | Select-Object @{N = 'Column'; E = { $C } }, Value - } - } - } - Catch { - throw "Failed creating property names: $_" ; return - } - } - } - - process { - if ($path) { - $extension = [System.IO.Path]::GetExtension($Path) - if ($extension -notmatch '.xlsx$|.xlsm$') { - throw "Import-Excel does not support reading this extension type $($extension)" - } - - $resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue) - if ($resolvedPath) { - $Path = $resolvedPath.ProviderPath - } - else { - throw "'$($Path)' file not found" - } - - $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite' - $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage - if ($Password) { $ExcelPackage.Load($stream, $Password) } - else { $ExcelPackage.Load($stream) } - } - try { - #Select worksheet - if (-not $WorksheetName) { $Worksheet = $ExcelPackage.Workbook.Worksheets[1] } - elseif (-not ($Worksheet = $ExcelPackage.Workbook.Worksheets[$WorkSheetName])) { - throw "Worksheet '$WorksheetName' not found, the workbook only contains the worksheets '$($ExcelPackage.Workbook.Worksheets)'. If you only wish to select the first worksheet, please remove the '-WorksheetName' parameter." ; return - } - - Write-Debug $sw.Elapsed.TotalMilliseconds - #region Get rows and columns - #If we are doing dataonly it is quicker to work out which rows to ignore before processing the cells. - if (-not $EndRow ) { $EndRow = $Worksheet.Dimension.End.Row } - if (-not $EndColumn) { $EndColumn = $Worksheet.Dimension.End.Column } - $endAddress = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[$EndRow]C[$EndColumn]", 0, 0) - if ($DataOnly) { - #If we are using headers startrow will be the header-row so examine data from startRow + 1, - if ($NoHeader) { $range = "A" + ($StartRow ) + ":" + $endAddress } - else { $range = "A" + ($StartRow + 1 ) + ":" + $endAddress } - #We're going to look at every cell and build 2 hash tables holding rows & columns which contain data. - #Want to Avoid 'select unique' operations & large Sorts, becuse time time taken increases with square - #of number of items (PS uses heapsort at large size). Instead keep a list of what we have seen, - #using Hash tables: "we've seen it" is all we need, no need to worry about "seen it before" / "Seen it many times". - $colHash = @{ } - $rowHash = @{ } - foreach ($cell in $Worksheet.Cells[$range]) { - if ($null -ne $cell.Value ) { $colHash[$cell.Start.Column] = 1; $rowHash[$cell.Start.row] = 1 } - } - $rows = ( $StartRow..$EndRow ).Where( { $rowHash[$_] }) - $columns = ($StartColumn..$EndColumn).Where( { $colHash[$_] }) - } - else { - $Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." } - if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } } - elseif ($HeaderName) { $Rows = $StartRow..$EndRow } - else { $Rows = (1 + $StartRow)..$EndRow } # ; if ($StartRow -ge $EndRow) { Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results." } } - } - #endregion - #region Create property names - if ((-not $Columns) -or (-not ($PropertyNames = Get-PropertyNames -Columns $Columns -StartRow $StartRow))) { - throw "No column headers found on top row '$StartRow'. If column headers in the worksheet are not a requirement then please use the '-NoHeader' or '-HeaderName' parameter."; return - } - if ($Duplicates = $PropertyNames | Group-Object Value | Where-Object Count -GE 2) { - throw "Duplicate column headers found on row '$StartRow' in columns '$($Duplicates.Group.Column)'. Column headers must be unique, if this is not a requirement please use the '-NoHeader' or '-HeaderName' parameter."; return - } - #endregion - Write-Debug $sw.Elapsed.TotalMilliseconds - if (-not $Rows) { - Write-Warning "Worksheet '$WorksheetName' in workbook '$Path' contains no data in the rows after top row '$StartRow'" - } - else { - #region Create one object per row - if ($AsText) { - <#join items in AsText together with ~~~ . Escape any regex special characters... - # which turns * into \* make it .*. Convert ~~~ to $|^ and top and tail with ^%; - So if we get "Week", "[Time]" and "*date*" ; make the expression ^week$|^\[Time\]$|^.*Date.*$ - $make a regex for this which is case insensitive (option 1) and compiled (option 8) - #> - $TextColExpression = "^" + [regex]::Escape($AsText -join "~~~").replace("\*", ".*").replace("~~~", "$|^") + "$" - $TextColRegEx = New-Object -TypeName regex -ArgumentList $TextColExpression , 9 - } - foreach ($R in $Rows) { - #Disabled write-verbose for speed - # Write-Verbose "Import row '$R'" - $NewRow = [Ordered]@{ } - if ($TextColRegEx) { - foreach ($P in $PropertyNames) { - if ($TextColRegEx.IsMatch($P.Value)) { - $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Text - } - else { $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Value } - } - } - else { - foreach ($P in $PropertyNames) { - $NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Value - # Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'." - } - } - [PSCustomObject]$NewRow - } - #endregion - } - Write-Debug $sw.Elapsed.TotalMilliseconds - } - catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$Worksheetname': $_"; return } - finally { - if ($Path) { $stream.close(); $ExcelPackage.Dispose() } - } - } -} - -function ConvertFrom-ExcelSheet { - <# - .Synopsis - Reads an Excel file an converts the data to a delimited text file. - - .Example - ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data - Reads each sheet in TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt. - - .Example - ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data sheet?0 - Reads and outputs sheets like Sheet10 and Sheet20 form TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt. - #> - - [CmdletBinding()] - param - ( - [Alias("FullName")] - [Parameter(Mandatory = $true)] - [String] - $Path, - [String] - $OutputPath = '.\', - [String] - $SheetName = "*", - [ValidateSet('ASCII', 'BigEndianUniCode', 'Default', 'OEM', 'UniCode', 'UTF32', 'UTF7', 'UTF8')] - [string] - $Encoding = 'UTF8', - [ValidateSet('.txt', '.log', '.csv')] - [string] - $Extension = '.csv', - [ValidateSet(';', ',')] - [string] - $Delimiter = ';' - ) - - $Path = (Resolve-Path $Path).Path - $Stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, "Open", "Read", "ReadWrite" - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Stream - $workbook = $xl.Workbook - - $targetSheets = $workbook.Worksheets | Where-Object { $_.Name -like $SheetName } - - $params = @{ } + $PSBoundParameters - $params.Remove("OutputPath") - $params.Remove("SheetName") - $params.Remove('Extension') - $params.NoTypeInformation = $true - - Foreach ($sheet in $targetSheets) { - Write-Verbose "Exporting sheet: $($sheet.Name)" - - $params.Path = "$OutputPath\$($Sheet.Name)$Extension" - - Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params - } - - $Stream.Close() - $Stream.Dispose() - $xl.Dispose() -} - -function Export-MultipleExcelSheets { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] - param( - [Parameter(Mandatory = $true)] - $Path, - [Parameter(Mandatory = $true)] - [hashtable]$InfoMap, - [string]$Password, - [Switch]$Show, - [Switch]$AutoSize - ) - - $parameters = @{ } + $PSBoundParameters - $parameters.Remove("InfoMap") - $parameters.Remove("Show") - - $parameters.Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - - foreach ($entry in $InfoMap.GetEnumerator()) { - Write-Progress -Activity "Exporting" -Status "$($entry.Key)" - $parameters.WorkSheetname = $entry.Key - - & $entry.Value | Export-Excel @parameters - } - - if ($Show) { Invoke-Item $Path } -} - -Function WorksheetArgumentCompleter { - param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) - $xlPath = $fakeBoundParameter['Path'] - if (Test-Path -Path $xlPath) { - $xlpkg = Open-ExcelPackage -ReadOnly -Path $xlPath - $WorksheetNames = $xlPkg.Workbook.Worksheets.Name - Close-ExcelPackage -nosave -ExcelPackage $xlpkg - $WorksheetNames.where( { $_ -like "*$wordToComplete*" }) | foreach-object { - New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'", - $_ , ([System.Management.Automation.CompletionResultType]::ParameterValue) , $_ - } - } -} -If (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { - Register-ArgumentCompleter -CommandName 'Import-Excel' -ParameterName 'WorksheetName' -ScriptBlock $Function:WorksheetArgumentCompleter -} +. $PSScriptRoot\ArgumentCompletion.ps1 \ No newline at end of file diff --git a/InferData.ps1 b/InferData/InferData.ps1 similarity index 100% rename from InferData.ps1 rename to InferData/InferData.ps1 diff --git a/InferData/Invoke-AllTests.md b/InferData/Invoke-AllTests.md new file mode 100644 index 0000000..efe8455 --- /dev/null +++ b/InferData/Invoke-AllTests.md @@ -0,0 +1,87 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Invoke-AllTests + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Invoke-AllTests [[-target] ] [-OnlyPassing] [-FirstOne] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -FirstOne +{{ Fill FirstOne Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OnlyPassing +{{ Fill OnlyPassing Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -target +{{ Fill target Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/InferData/Test-Boolean.md b/InferData/Test-Boolean.md new file mode 100644 index 0000000..fe57b1f --- /dev/null +++ b/InferData/Test-Boolean.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Test-Boolean + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Test-Boolean [[-p] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -p +{{ Fill p Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/InferData/Test-Date.md b/InferData/Test-Date.md new file mode 100644 index 0000000..74c8d35 --- /dev/null +++ b/InferData/Test-Date.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Test-Date + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Test-Date [[-p] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -p +{{ Fill p Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/InferData/Test-Integer.md b/InferData/Test-Integer.md new file mode 100644 index 0000000..33ae133 --- /dev/null +++ b/InferData/Test-Integer.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Test-Integer + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Test-Integer [[-p] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -p +{{ Fill p Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/InferData/Test-Number.md b/InferData/Test-Number.md new file mode 100644 index 0000000..0df805d --- /dev/null +++ b/InferData/Test-Number.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Test-Number + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Test-Number [[-p] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -p +{{ Fill p Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/InferData/Test-String.md b/InferData/Test-String.md new file mode 100644 index 0000000..73c4f19 --- /dev/null +++ b/InferData/Test-String.md @@ -0,0 +1,57 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Test-String + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Test-String [[-p] ] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -p +{{ Fill p Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Merge-Worksheet.ps1 b/Merge-Worksheet.ps1 deleted file mode 100644 index 331c339..0000000 --- a/Merge-Worksheet.ps1 +++ /dev/null @@ -1,539 +0,0 @@ -Function Merge-Worksheet { - <# - .Synopsis - Merges two Worksheets (or other objects) into a single Worksheet with differences marked up. - .Description - The Compare-Worksheet command takes two Worksheets and marks differences in the source document, and optionally outputs a grid showing the changes. - By contrast the Merge-Worksheet command takes the Worksheets and combines them into a single sheet showing the old and new data side by side. - Although it is designed to work with Excel data it can work with arrays of any kind of object; so it can be a merge *of* Worksheets, or a merge *to* a Worksheet. - .Example - Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -show - The workbooks contain audit information for two servers, one sheet contains - a list of services. This command creates a worksheet named "54-55" in a - workbook named "services.xlsx" which shows all the services and their - differences, and opens the new workbook in Excel. - .Example - Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -HideEqual -AddBackgroundColor LightBlue -show - This modifies the previous command to hide the equal rows in the output - sheet and changes the color used to mark rows added to the second file. - .Example - Merge-Worksheet -OutputFile .\j1.xlsx -OutputSheetName test11 -ReferenceObject (dir .\ImportExcel\4.0.7) -DifferenceObject (dir .\ImportExcel\4.0.8) -Property Length -Show - This version compares two directories, and marks what has changed. - Because no "Key" property is given, "Name" is assumed to be the key - and the only other property examined is length. Files which are added - or deleted or have changed size will be highlighed in the output sheet. - Changes to dates or other attributes will be ignored. - .Example - Merge-Worksheet -RefO (dir .\ImportExcel\4.0.7) -DiffO (dir .\ImportExcel\4.0.8) -Pr Length | Out-GridView - This time no file is written and the results - which include all properties, - not just length, are output and sent to Out-Gridview. This version uses - aliases to shorten the parameters, (OutputFileName can be "outFile" and - the Sheet can be"OutSheet"; DifferenceObject & ReferenceObject can be - DiffObject & RefObject respectively). - #> - [cmdletbinding(SupportsShouldProcess=$true)] - Param( - #First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. - [parameter(ParameterSetName='A',Mandatory=$true,Position=0)] #A = Compare two files default headers - [parameter(ParameterSetName='B',Mandatory=$true,Position=0)] #B = Compare two files user supplied headers - [parameter(ParameterSetName='C',Mandatory=$true,Position=0)] #C = Compare two files headers P1, P2, P3 etc - $Referencefile , - - #Second Excel file to compare. - [parameter(ParameterSetName='A',Mandatory=$true,Position=1)] - [parameter(ParameterSetName='B',Mandatory=$true,Position=1)] - [parameter(ParameterSetName='C',Mandatory=$true,Position=1)] - [parameter(ParameterSetName='E',Mandatory=$true,Position=1)] #D Compare two objects; E = Compare one object one file that uses default headers - [parameter(ParameterSetName='F',Mandatory=$true,Position=1)] #F = Compare one object one file that uses user supplied headers - [parameter(ParameterSetName='G',Mandatory=$true,Position=1)] #G Compare one object one file that uses headers P1, P2, P3 etc - $Differencefile , - - #Name(s) of Worksheets to compare. - [parameter(ParameterSetName='A',Position=2)] #Applies to all sets EXCEPT D which is two objects (no sheets) - [parameter(ParameterSetName='B',Position=2)] - [parameter(ParameterSetName='C',Position=2)] - [parameter(ParameterSetName='E',Position=2)] - [parameter(ParameterSetName='F',Position=2)] - [parameter(ParameterSetName='G',Position=2)] - $WorksheetName = "Sheet1", - - #The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. - [parameter(ParameterSetName='A')] #Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) - [parameter(ParameterSetName='B')] - [parameter(ParameterSetName='C')] - [parameter(ParameterSetName='E')] - [parameter(ParameterSetName='F')] - [parameter(ParameterSetName='G')] - [int]$Startrow = 1, - - #Specifies custom property names to use, instead of the values defined in the column headers of the Start ROw. - [Parameter(ParameterSetName='B',Mandatory=$true)] #Compare object + sheet or 2 sheets with user supplied headers - [Parameter(ParameterSetName='F',Mandatory=$true)] - [String[]]$Headername, - - #Automatically generate property names (P1, P2, P3, ..) instead of using the values the top row of the sheet. - [Parameter(ParameterSetName='C',Mandatory=$true)] #Compare object + sheet or 2 sheets with headers of P1, P2, P3 ... - [Parameter(ParameterSetName='G',Mandatory=$true)] - [switch]$NoHeader, - - #Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object - [parameter(ParameterSetName='D',Mandatory=$true)] - [parameter(ParameterSetName='E',Mandatory=$true)] - [parameter(ParameterSetName='F',Mandatory=$true)] - [parameter(ParameterSetName='G',Mandatory=$true)] - [Alias('RefObject')] - $ReferenceObject , - #Difference object to compare if a Worksheet is NOT being used for either half. Can't have a reference sheet and difference object. - [parameter(ParameterSetName='D',Mandatory=$true,Position=1)] - [Alias('DiffObject')] - $DifferenceObject , - [parameter(ParameterSetName='D',Position=2)] - [parameter(ParameterSetName='E',Position=2)] - [parameter(ParameterSetName='F',Position=2)] - [parameter(ParameterSetName='G',Position=2)] - #If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" - $DiffPrefix = "=>" , - #File to hold merged data. - [parameter(Position=3)] - [Alias('OutFile')] - $OutputFile , - #Name of Worksheet to output - if none specified will use the reference Worksheet name. - [parameter(Position=4)] - [Alias('OutSheet')] - $OutputSheetName = "Sheet1", - #Properties to include in the DIFF - supports wildcards, default is "*". - $Property = "*" , - #Properties to exclude from the the search - supports wildcards. - $ExcludeProperty , - #Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". - $Key = "Name" , - #Sets the font color for the "key" field; this means you can filter by color to get only changed rows. - $KeyFontColor = [System.Drawing.Color]::DarkRed , - #Sets the background color for changed rows. - $ChangeBackgroundColor = [System.Drawing.Color]::Orange, - #Sets the background color for rows in the reference but deleted from the difference sheet. - $DeleteBackgroundColor = [System.Drawing.Color]::LightPink, - #Sets the background color for rows not in the reference but added to the difference sheet. - $AddBackgroundColor = [System.Drawing.Color]::PaleGreen, - #if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. - [switch]$HideEqual , - #If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). - [switch]$Passthru , - #If specified, opens the output workbook. - [Switch]$Show - ) - - #region Read Excel data - if ($Differencefile -is [System.IO.FileInfo]) {$Differencefile = $Differencefile.FullName} - if ($Referencefile -is [System.IO.FileInfo]) {$Referencefile = $Referencefile.FullName} - if ($Referencefile -and $Differencefile) { - #if the filenames don't resolve, give up now. - try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} - Catch { Write-Warning -Message "Could not Resolve the filenames." ; return } - - #If we have one file , we must have two different Worksheet names. If we have two files $WorksheetName can be a single string or two strings. - if ($onefile -and ( ($WorksheetName.count -ne 2) -or $WorksheetName[0] -eq $WorksheetName[1] ) ) { - Write-Warning -Message "If both the Reference and difference file are the same then Worksheet name must provide 2 different names" - return - } - if ($WorksheetName.count -eq 2) {$Worksheet2 = $DiffPrefix = $WorksheetName[1] ; $Worksheet1 = $WorksheetName[0] ; } - elseif ($WorksheetName -is [string]) {$Worksheet2 = $Worksheet1 = $WorksheetName ; - $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" } - else {Write-Warning -Message "You must provide either a single Worksheet name or two names." ; return } - - $params= @{ ErrorAction = [System.Management.Automation.ActionPreference]::Stop } - foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} - try { - $ReferenceObject = Import-Excel -Path $Referencefile -WorksheetName $Worksheet1 @params - $DifferenceObject = Import-Excel -Path $Differencefile -WorksheetName $Worksheet2 @Params - } - Catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return } - if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} - } - elseif ( $Differencefile) { - if ($WorksheetName -isnot [string]) {Write-Warning -Message "You must provide a single Worksheet name." ; return } - $params = @{WorksheetName=$WorksheetName; Path=$Differencefile; ErrorAction=[System.Management.Automation.ActionPreference]::Stop } - foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} - try {$DifferenceObject = Import-Excel @Params } - Catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return } - if ($DiffPrefix -eq "=>" ) { - $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" - } - if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} - } - else { $firstDataRow = 1 } - #endregion - - #region Set lists of properties and row numbers - #Make a list of properties/headings using the Property (default "*") and ExcludeProperty parameters - $propList = @() - $DifferenceObject = $DifferenceObject | Update-FirstObjectProperties - $headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using get-member would sort them alphabetically! There may be extra properties in - if ($NoHeader -and "Name" -eq $Key) {$Key = "p1"} - if ($headings -notcontains $Key -and - ('*' -ne $Key)) {Write-Warning -Message "You need to specify one of the headings in the sheet '$Worksheet1' as a key." ; return } - foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )} - foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) } - if (($propList -notcontains $Key) -and - ('*' -ne $Key)) { $propList += $Key} #If $key isn't one of the headings we will have bailed by now - $propList = $propList | Select-Object -Unique #so, prolist must contain at least $key if nothing else - - #If key is "*" we treat it differently , and we will create a script property which concatenates all the Properties in $Proplist - $ConCatblock = [scriptblock]::Create( ($proplist | ForEach-Object {'$this."' + $_ + '"'}) -join " + ") - - #Build the list of the properties to output, in order. - $diffpart = @() - $refpart = @() - foreach ($p in $proplist.Where({$key -ne $_}) ) {$refPart += $p ; $diffPart += "$DiffPrefix $p" } - $lastRefColNo = $proplist.count - $FirstDiffColNo = $lastRefColNo + 1 - - if ($key -ne '*') { - $outputProps = @($key) + $refpart + $diffpart - #If we are using a single column as the key, don't duplicate it, so the last difference column will be A if there is one property, C if there are two, E if there are 3 - $lastDiffColNo = (2 * $proplist.count) - 1 - } - else { - $outputProps = @( ) + $refpart + $diffpart - #If we not using a single column as a key all columns are duplicated so, the Last difference column will be B if there is one property, D if there are two, F if there are 3 - $lastDiffColNo = (2 * $proplist.count ) - } - - #Add RowNumber to every row - #If one sheet has extra rows we can get a single "==" result from compare, with the row from the reference sheet, but - #the row in the other sheet might be different so we will look up the row number from the key field - build a hash table for that here - #If we have "*" as the key ad the script property to concatenate the [selected] properties. - - $Rowhash = @{} - $rowNo = $firstDataRow - foreach ($row in $ReferenceObject) { - if ($null -eq $row._row) {Add-Member -InputObject $row -MemberType NoteProperty -Value ($rowNo ++) -Name "_Row" } - else {$rowNo++ } - if ($Key -eq '*' ) {Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All" } - } - $rowNo = $firstDataRow - foreach ($row in $DifferenceObject) { - Add-Member -InputObject $row -MemberType NoteProperty -Value $rowNo -Name "$DiffPrefix Row" -Force - if ($Key -eq '*' ) { - Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All" - $Rowhash[$row._All] = $rowNo - } - else {$Rowhash[$row.$key] = $rowNo } - $rowNo ++ - } - if ($DifferenceObject.count -gt $Rowhash.Keys.Count) { - Write-Warning -Message "Difference object has $($DifferenceObject.Count) rows; but only $($Rowhash.keys.count) unique keys" - } - if ($Key -eq '*') {$key = "_ALL"} - #endregion - #We need to know all the properties we've met on the objects we've diffed - $eDiffProps = [ordered]@{} - #When we do a compare object changes will result in two rows so we group them and join them together. - $expandedDiff = Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property $propList -PassThru -IncludeEqual | - Group-Object -Property $key | ForEach-Object { - #The value of the key column is the name of the Group. - $keyval = $_.name - #we're going to create a custom object from a hash table. - $hash = [ordered]@{} - foreach ($result in $_.Group) { - if ($result.SideIndicator -ne "=>") {$hash["_Row"] = $result._Row } - elseif (-not $hash["$DiffPrefix Row"]) {$hash["_Row"] = "" } - #if we have already set the side, this must be the second record, so set side to indicate "changed"; if we got two "Same" indicators we may have a classh of keys - if ($hash.Side) { - if ($hash.Side -eq $result.SideIndicator) {Write-Warning -Message "'$keyval' may be a duplicate."} - $hash.Side = "<>" - } - else {$hash["Side"] = $result.SideIndicator} - switch ($hash.side) { - '==' { $hash["$DiffPrefix is"] = 'Same' } - '=>' { $hash["$DiffPrefix is"] = 'Added' } - '<>' { if (-not $hash["_Row"]) { - $hash["$DiffPrefix is"] = 'Added' - } - else { - $hash["$DiffPrefix is"] = 'Changed' - } - } - '<=' { $hash["$DiffPrefix is"] = 'Removed'} - } - #find the number of the row in the the "difference" object which has this key. If it is the object is only in the reference this will be blank. - $hash["$DiffPrefix Row"] = $Rowhash[$keyval] - $hash[$key] = $keyval - #Create FieldName and/or =>FieldName columns - foreach ($p in $result.psobject.Properties.name.where({$_ -ne $key -and $_ -ne "SideIndicator" -and $_ -ne "$DiffPrefix Row" })) { - if ($result.SideIndicator -eq "==" -and $p -in $propList) - {$hash[("$p")] = $hash[("$DiffPrefix $p")] = $result.$P} - elseif ($result.SideIndicator -eq "==" -or $result.SideIndicator -eq "<=") - {$hash[("$p")] = $result.$P} - elseif ($result.SideIndicator -eq "=>") { $hash[("$DiffPrefix $p")] = $result.$P} - } - } - - foreach ($k in $hash.keys) {$eDiffProps[$k] = $true} - [Pscustomobject]$hash - } | Sort-Object -Property "_row" - - #Already sorted by reference row number, fill in any blanks in the difference-row column. - for ($i = 1; $i -lt $expandedDiff.Count; $i++) {if (-not $expandedDiff[$i]."$DiffPrefix Row") {$expandedDiff[$i]."$DiffPrefix Row" = $expandedDiff[$i-1]."$DiffPrefix Row" } } - - #Now re-Sort by difference row number, and fill in any blanks in the reference-row column. - $expandedDiff = $expandedDiff | Sort-Object -Property "$DiffPrefix Row" - for ($i = 1; $i -lt $expandedDiff.Count; $i++) {if (-not $expandedDiff[$i]."_Row") {$expandedDiff[$i]."_Row" = $expandedDiff[$i-1]."_Row" } } - - $AllProps = @("_Row") + $OutputProps + $eDiffProps.keys.where({$_ -notin ($outputProps + @("_row","side","SideIndicator","_ALL" ))}) - - if ($PassThru -or -not $OutputFile) {return ($expandedDiff | Select-Object -Property $allprops | Sort-Object -Property "_row", "$DiffPrefix Row" ) } - elseif ($PSCmdlet.ShouldProcess($OutputFile,"Write Output to Excel file")) { - $expandedDiff = $expandedDiff | Sort-Object -Property "_row", "$DiffPrefix Row" - $xl = $expandedDiff | Select-Object -Property $OutputProps | Update-FirstObjectProperties | - Export-Excel -Path $OutputFile -Worksheetname $OutputSheetName -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -PassThru - $ws = $xl.Workbook.Worksheets[$OutputSheetName] - for ($i = 0; $i -lt $expandedDiff.Count; $i++ ) { - if ( $expandedDiff[$i].side -ne "==" ) { - Set-ExcelRange -Worksheet $ws -Range ("A" + ($i + 2 )) -FontColor $KeyFontColor - } - elseif ( $HideEqual ) {$ws.row($i+2).hidden = $true } - if ( $expandedDiff[$i].side -eq "<>" ) { - $range = $ws.Dimension -replace "\d+", ($i + 2 ) - Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $ChangeBackgroundColor - } - elseif ( $expandedDiff[$i].side -eq "<=" ) { - $rangeR1C1 = "R[{0}]C[1]:R[{0}]C[{1}]" -f ($i + 2 ) , $lastRefColNo - $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) - Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $DeleteBackgroundColor - } - elseif ( $expandedDiff[$i].side -eq "=>" ) { - if ($propList.count -gt 1) { - $rangeR1C1 = "R[{0}]C[{1}]:R[{0}]C[{2}]" -f ($i + 2 ) , $FirstDiffColNo , $lastDiffColNo - $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) - Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $AddBackgroundColor - } - Set-ExcelRange -Worksheet $ws -Range ("A" + ($i + 2 )) -BackgroundColor $AddBackgroundColor - } - } - Close-ExcelPackage -ExcelPackage $xl -Show:$Show - } -} - -Function Merge-MultipleSheets { - <# - .Synopsis - Merges Worksheets into a single Worksheet with differences marked up. - .Description - The Merge Worksheet command combines two sheets. Merge-MultipleSheets is - designed to merge more than two. So if asked to merge sheets A,B,C which - contain Services, with a Name, Displayname and Start mode, where "Name" is - treated as the key, Merge-MultipleSheets calls Merge-Worksheet to merge - "Name", "Displayname" and "Startmode" from sheets A and C; the result has - column headings "_Row", "Name", "DisplayName", "Startmode", "C-DisplayName", - "C-StartMode", "C-Is" and "C-Row". - Merge-MultipleSheets then calls Merge-Worksheet again passing it the - intermediate result and sheet B, comparing "Name", "Displayname" and - "Start mode" columns on each side, and gets a result with columns "_Row", - "Name", "DisplayName", "Startmode", "B-DisplayName", "B-StartMode", "B-Is", - "B-Row", "C-DisplayName", "C-StartMode", "C-Is" and "C-Row". Any columns on - the "reference" side which are not used in the comparison are added on the - right, which is why we compare the sheets in reverse order. - - The "Is" columns hold "Same", "Added", "Removed" or "Changed" and is used for - conditional formatting in the output sheet (these columns are hidden by default), - and when the data is written to Excel the "reference" columns, in this case - "DisplayName" and "Start" are renamed to reflect their source, so become - "A-DisplayName" and "A-Start". - - Conditional formatting is also applied to the Key column ("Name" in this - case) so the view can be filtered to rows with changes by filtering this - column on color. - - Note: the processing order can affect what is seen as a change. For example - if there is an extra item in sheet B in the example above, Sheet C will be - processed and that row and will not be seen to be missing. When sheet B is - processed it is marked as an addition, and the conditional formatting marks - the entries from sheet A to show that a values were added in at least one - sheet. However if Sheet B is the reference sheet, A and C will be seen to - have an item removed; and if B is processed before C, the extra item is - known when C is processed and so C is considered to be missing that item. - .Example - dir Server*.xlsx | Merge-MulipleSheets -WorksheetName Services -OutputFile Test2.xlsx -OutputSheetName Services -Show - Here we are auditing servers and each one has a workbook in the current - directory which contains a "Services" Worksheet (the result of - Get-WmiObject -Class win32_service | Select-Object -Property Name, Displayname, Startmode) - No key is specified so the key is assumed to be the "Name" column. - The files are merged and the result is opened on completion. - .Example - dir Serv*.xlsx | Merge-MulipleSheets -WorksheetName Software -Key "*" -ExcludeProperty Install* -OutputFile Test2.xlsx -OutputSheetName Software -Show - The server audit files in the previous example also have "Software" worksheet, - but no single field on that sheet works as a key. Specifying "*" for the key - produces a compound key using all non-excluded fields (and the installation - date and file location are excluded). - .Example - Merge-MulipleSheets -Path hotfixes.xlsx -WorksheetName Serv* -Key hotfixid -OutputFile test2.xlsx -OutputSheetName hotfixes -HideRowNumbers -Show - This time all the servers have written their hotfix information to their own - worksheets in a shared Excel workbook named "Hotfixes.xlsx" (the information was - obtained by running Get-Hotfix | Sort-Object -Property description,hotfixid | Select-Object -Property Description,HotfixID) - This ignores any sheets which are not named "Serv*", and uses the HotfixID as - the key; in this version the row numbers are hidden. - #> - [cmdletbinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")] - #[Alias("Merge-MulipleSheets")] #There was a spelling error in the first release. This was there to ensure things didn't break but intelisense gave the alias first. - param ( - #Paths to the files to be merged. Files are also accepted - [Parameter(Mandatory=$true,ValueFromPipeline=$true)] - $Path , - #The row from where we start to import data, all rows above the Start row are disregarded. By default this is the first row. - [int]$Startrow = 1, - - #Specifies custom property names to use, instead of the values defined in the column headers of the Start row. - [String[]]$Headername, - - #If specified, property names will be automatically generated (P1, P2, P3, ..) instead of using the values from the start row. - [switch]$NoHeader, - - #Name(s) of Worksheets to compare. - $WorksheetName = "Sheet1", - #File to write output to. - [Alias('OutFile')] - $OutputFile = ".\temp.xlsx", - #Name of Worksheet to output - if none specified will use the reference Worksheet name. - [Alias('OutSheet')] - $OutputSheetName = "Sheet1", - #Properties to include in the comparison - supports wildcards, default is "*". - $Property = "*" , - #Properties to exclude from the the comparison - supports wildcards. - $ExcludeProperty , - #Name of a column which is unique used to pair up rows from the reference and difference sides, default is "Name". - $Key = "Name" , - #Sets the font color for the Key field; this means you can filter by color to get only changed rows. - $KeyFontColor = [System.Drawing.Color]::Red, - #Sets the background color for changed rows. - $ChangeBackgroundColor = [System.Drawing.Color]::Orange, - #Sets the background color for rows in the reference but deleted from the difference sheet. - $DeleteBackgroundColor = [System.Drawing.Color]::LightPink, - #Sets the background color for rows not in the reference but added to the difference sheet. - $AddBackgroundColor = [System.Drawing.Color]::Orange, - #If specified, hides the columns in the spreadsheet that contain the row numbers. - [switch]$HideRowNumbers , - #If specified, outputs the data to the pipeline (you can add -whatif so it the command only outputs to the pipeline). - [switch]$Passthru , - #If specified, opens the output workbook. - [Switch]$Show - ) - begin { $filestoProcess = @() } - process { $filestoProcess += $Path} - end { - if ($filestoProcess.Count -eq 1 -and $WorksheetName -match '\*') { - Write-Progress -Activity "Merging sheets" -CurrentOperation "Expanding * to names of sheets in $($filestoProcess[0]). " - $excel = Open-ExcelPackage -Path $filestoProcess - $WorksheetName = $excel.Workbook.Worksheets.Name.where({$_ -like $WorksheetName}) - Close-ExcelPackage -NoSave -ExcelPackage $excel - } - - #Merge identically named sheets in different work books; - if ($filestoProcess.Count -ge 2 -and $WorksheetName -is "string" ) { - Get-Variable -Name 'HeaderName','NoHeader','StartRow','Key','Property','ExcludeProperty','WorksheetName' -ErrorAction SilentlyContinue | - Where-Object {$_.Value} | ForEach-Object -Begin {$params= @{} } -Process {$params[$_.Name] = $_.Value} - - Write-Progress -Activity "Merging sheets" -CurrentOperation "comparing '$WorksheetName' in $($filestoProcess[-1]) against $($filestoProcess[0]). " - $merged = Merge-Worksheet @params -Referencefile $filestoProcess[0] -Differencefile $filestoProcess[-1] - $nextFileNo = 2 - while ($nextFileNo -lt $filestoProcess.count -and $merged) { - Write-Progress -Activity "Merging sheets" -CurrentOperation "comparing '$WorksheetName' in $($filestoProcess[-$nextFileNo]) against $($filestoProcess[0]). " - $merged = Merge-Worksheet @params -ReferenceObject $merged -Differencefile $filestoProcess[-$nextFileNo] - $nextFileNo ++ - - } - } - #Merge different sheets from one workbook - elseif ($filestoProcess.Count -eq 1 -and $WorksheetName.Count -ge 2 ) { - Get-Variable -Name 'HeaderName','NoHeader','StartRow','Key','Property','ExcludeProperty' -ErrorAction SilentlyContinue | - Where-Object {$_.Value} | ForEach-Object -Begin {$params= @{} } -Process {$params[$_.Name] = $_.Value} - - Write-Progress -Activity "Merging sheets" -CurrentOperation "Comparing $($WorksheetName[-1]) against $($WorksheetName[0]). " - $merged = Merge-Worksheet @params -Referencefile $filestoProcess[0] -Differencefile $filestoProcess[0] -WorksheetName $WorksheetName[0,-1] - $nextSheetNo = 2 - while ($nextSheetNo -lt $WorksheetName.count -and $merged) { - Write-Progress -Activity "Merging sheets" -CurrentOperation "Comparing $($WorksheetName[-$nextSheetNo]) against $($WorksheetName[0]). " - $merged = Merge-Worksheet @params -ReferenceObject $merged -Differencefile $filestoProcess[0] -WorksheetName $WorksheetName[-$nextSheetNo] -DiffPrefix $WorksheetName[-$nextSheetNo] - $nextSheetNo ++ - } - } - #We either need one Worksheet name and many files or one file and many sheets. - else { Write-Warning -Message "Need at least two files to process" ; return } - #if the process didn't return data then abandon now. - if (-not $merged) {Write-Warning -Message "The merge operation did not return any data."; return } - - $orderByProperties = $merged[0].psobject.properties.where({$_.name -match "row$"}).name - Write-Progress -Activity "Merging sheets" -CurrentOperation "creating output sheet '$OutputSheetName' in $OutputFile" - $excel = $merged | Sort-Object -Property $orderByProperties | - Export-Excel -Path $OutputFile -Worksheetname $OutputSheetName -ClearSheet -BoldTopRow -AutoFilter -PassThru - $sheet = $excel.Workbook.Worksheets[$OutputSheetName] - - #We will put in a conditional format for "if all the others are not flagged as 'same'" to mark rows where something is added, removed or changed - $sameChecks = @() - - #All the 'difference' columns in the sheet are labeled with the file they came from, 'reference' columns need their - #headers prefixed with the ref file name, $colnames is the basis of a regular expression to identify what should have $refPrefix appended - $colNames = @("^_Row$") - if ($key -ne "*") - {$colnames += "^$Key$"} - if ($filesToProcess.Count -ge 2) { - $refPrefix = (Split-Path -Path $filestoProcess[0] -Leaf) -replace "\.xlsx$"," " - } - else {$refPrefix = $WorksheetName[0] } - Write-Progress -Activity "Merging sheets" -CurrentOperation "applying formatting to sheet '$OutputSheetName' in $OutputFile" - #Find the column headings which are in the form "diffFile is"; which will hold 'Same', 'Added' or 'Changed' - foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "\sIS$"}) ) { - #Work leftwards across the headings applying conditional formatting which says - # 'Format this cell if the "IS" column has a value of ...' until you find a heading which doesn't have the prefix. - $prefix = $cell.value -replace "\sIS$","" - $columnNo = $cell.start.Column -1 - $cellAddr = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R1C$columnNo",1,$columnNo) - while ($sheet.cells[$cellAddr].value -match $prefix) { - $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='Solid'; Worksheet=$sheet; StopIfTrue=$true; Range=$([OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[1]C[$columnNo]:R[1048576]C[$columnNo]",0,0)) } - Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Added"' ) -BackgroundColor $AddBackgroundColor - Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Changed"') -BackgroundColor $ChangeBackgroundColor - Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Removed"') -BackgroundColor $DeleteBackgroundColor - $columnNo -- - $cellAddr = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R1C$columnNo",1,$columnNo) - } - #build up a list of prefixes in $colnames - we'll use that to set headers on rows from the reference file; and build up the "if the 'is' cell isn't same" list - $colNames += $prefix - $sameChecks += (($cell.Address -replace "1","2") +'<>"Same"') - } - - #For all the columns which don't match one of the Diff-file prefixes or "_Row" or the 'Key' columnn name; add the reference file prefix to their header. - $nameRegex = $colNames -Join '|' - foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -Notmatch $nameRegex}) ) { - $cell.Value = $refPrefix + $cell.Value - $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='Solid'; Worksheet=$sheet; StopIfTrue=$true; Range=[OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[2]C[$($cell.start.column)]:R[1048576]C[$($cell.start.column)]",0,0)} - Add-ConditionalFormatting @condFormattingParams -ConditionValue ("OR(" +(($sameChecks -join ",") -replace '<>"Same"','="Added"' ) +")" ) -BackgroundColor $DeleteBackgroundColor - Add-ConditionalFormatting @condFormattingParams -ConditionValue ("AND(" +(($sameChecks -join ",") -replace '<>"Same"','="Changed"') +")" ) -BackgroundColor $ChangeBackgroundColor - } - #We've made a bunch of things wider so now is the time to autofit columns. Any hiding has to come AFTER this, because it unhides things - if ($env:NoAutoSize) {Write-Warning "Autofit is not available with this OS configuration."} - else {$sheet.Cells.AutoFitColumns()} - - #if we have a key field (we didn't concatenate all fields) use what we built up in $sameChecks to apply conditional formatting to it (Row no will be in column A, Key in Column B) - if ($Key -ne '*') { - Add-ConditionalFormatting -Worksheet $sheet -Range "B2:B1048576" -ForeGroundColor $KeyFontColor -BackgroundPattern 'None' -RuleType Expression -ConditionValue ("OR(" +($sameChecks -join ",") +")" ) - $sheet.view.FreezePanes(2, 3) - } - else {$sheet.view.FreezePanes(2, 2) } - #Go back over the headings to find and hide the "is" columns; - foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "\sIS$"}) ) { - $sheet.Column($cell.start.Column).HIDDEN = $true - } - - #If specified, look over the headings for "row" and hide the columns which say "this was in row such-and-such" - if ($HideRowNumbers) { - foreach ($cell in $sheet.Cells[($sheet.Dimension.Address -replace "\d+$","1")].Where({$_.value -match "Row$"}) ) { - $sheet.Column($cell.start.Column).HIDDEN = $true - } - } - if ($Passthru) {$excel} - else {Close-ExcelPackage -ExcelPackage $excel -Show:$Show} - Write-Progress -Activity "Merging sheets" -Completed - } -} diff --git a/New-ConditionalText.ps1 b/New-ConditionalText.ps1 deleted file mode 100644 index a0fb189..0000000 --- a/New-ConditionalText.ps1 +++ /dev/null @@ -1,84 +0,0 @@ -function New-ConditionalText { - <# - .SYNOPSIS - Creates an object which describes a conditional formatting rule for single valued rules. - .DESCRIPTION - Some Conditional formatting rules don't apply styles to a cell (IconSets and Databars). - Some take two parameters (Between). - Some take none (ThisWeek, ContainsErrors, AboveAverage etc). - The others take a single parameter (Top, BottomPercent, GreaterThan, Contains etc). - This command creates an object to describe the last two categories, which can then be passed to Export-Excel. - .PARAMETER Range - The range of cells that the conditional format applies to; if none is specified the range will be apply to all the data in the sheet. - .PARAMETER ConditionalType - One of the supported rules; by default "ContainsText" is selected. - .PARAMETER Text - The text (or other value) to use in the rule. Note that Equals, GreaterThan/LessThan rules require text to wrapped in double quotes. - .PARAMETER ConditionalTextColor - The font color for the cell - by default: "DarkRed". - .PARAMETER BackgroundColor - The fill color for the cell - by default: "LightPink". - .PARAMETER PatternType - The background pattern for the cell - by default: "Solid" - .EXAMPLE - > - $ct = New-ConditionalText -Text 'Ferrari' - Export-Excel -ExcelPackage $excel -ConditionalTest $ct -show - - The first line creates a definition object which will highlight the word - "Ferrari" in any cell. and the second uses Export-Excel with an open package - to apply the format and save and open the file. - .EXAMPLE - > - $ct = New-ConditionalText -Text "Ferrari" - $ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalTextColor Red -BackgroundColor White - Export-Excel -ExcelPackage $excel -ConditionalText $ct,$ct2 -show - - This builds on the previous example, and specifies a condition of <=3 with - a format of red text on a white background; this applies to a named range - "Finish Position". The range could be written -Range "C:C" to specify a - named column, or -Range "C2:C102" to specify certain cells in the column. - .Link - Add-ConditionalFormatting - New-ConditionalFormattingIconSet - #> - [cmdletbinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] - param( - #[Parameter(Mandatory=$true)] - [Alias("ConditionValue")] - $Text, - [Alias("ForeGroundColor")] - $ConditionalTextColor=[System.Drawing.Color]::DarkRed, - $BackgroundColor=[System.Drawing.Color]::LightPink, - [String]$Range, - [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid, - [ValidateSet( - "LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual", - "Equal", "NotEqual", - "Top", "TopPercent", "Bottom", "BottomPercent", - "ContainsText", "NotContainsText", "BeginsWith", "EndsWith", - "ContainsBlanks", "NotContainsBlanks", "ContainsErrors", "NotContainsErrors", - "DuplicateValues", "UniqueValues", - "Tomorrow", "Today", "Yesterday", "Last7Days", - "NextWeek", "ThisWeek", "LastWeek", - "NextMonth", "ThisMonth", "LastMonth", - "AboveAverage", "AboveOrEqualAverage", "BelowAverage", "BelowOrEqualAverage" - )] - [Alias("RuleType")] - $ConditionalType="ContainsText" - ) - - $obj = [PSCustomObject]@{ - Text = $Text - ConditionalTextColor = $ConditionalTextColor - ConditionalType = $ConditionalType - PatternType = $PatternType - Range = $Range - BackgroundColor = $BackgroundColor - } - - $obj.pstypenames.Clear() - $obj.pstypenames.Add("ConditionalText") - $obj -} \ No newline at end of file diff --git a/New-ExcelChart.ps1 b/New-ExcelChart.ps1 deleted file mode 100644 index 2a1c98b..0000000 --- a/New-ExcelChart.ps1 +++ /dev/null @@ -1,471 +0,0 @@ -function New-ExcelChartDefinition { - <# - .SYNOPSIS - Creates a Definition of a chart which can be added using Export-Excel, or Add-PivotTable - .DESCRIPTION - All the parameters which are passed to Add-ExcelChart can be added to an object and - passed to Export-Excel with the -ExcelChartDefinition parameter, - or to Add-PivotTable with the -PivotChartDefinition parameter. - This command sets up those definitions. - .PARAMETER Title - The title for the chart. - .PARAMETER TitleBold - Sets the title in bold face. - .PARAMETER TitleSize - Sets the point size for the title. - .PARAMETER ChartType - One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". - .PARAMETER XRange - The range of cells containing values for the X-Axis - usually labels. - .PARAMETER YRange - The range(s) of cells holding values for the Y-Axis - usually "data". - .PARAMETER Width - Width of the chart in pixels. Defaults to 500. - .PARAMETER Height - Height of the chart in pixels. Defaults to 350. - .PARAMETER Row - Row position of the top left corner of the chart. 0 places at the top of the sheet, 1 below row 1 and so on. - .PARAMETER RowOffSetPixels - Offset to position the chart by a fraction of a row. - .PARAMETER Column - Column position of the top left corner of the chart. 0 places at the edge of the sheet 1 to the right of column A and so on. - .PARAMETER ColumnOffSetPixels - Offset to position the chart by a fraction of a column. - .PARAMETER NoLegend - If specified, turns off display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. - .PARAMETER SeriesHeader - Specifies explicit name(s) for the data series, which will appear in the legend/key - .PARAMETER LegendPosition - Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". - .PARAMETER LegendSize - Font size for the key. - .PARAMETER LegendBold - Sets the key in bold type. - .PARAMETER ShowCategory - Attaches a category label in charts which support this. - .PARAMETER ShowPercent - Attaches a percentage label in charts which support this. - .PARAMETER XAxisTitleText - Specifies a title for the X-axis. - .PARAMETER XAxisTitleBold - Sets the X-axis title in bold face. - .PARAMETER XAxisTitleSize - Sets the font size for the axis title. - .PARAMETER XAxisNumberformat - A number formatting string, like "#,##0.00", for numbers along the X-axis. - .PARAMETER XMajorUnit - Spacing for the major gridlines / tick marks along the X-axis. - .PARAMETER XMinorUnit - Spacing for the minor gridlines / tick marks along the X-axis. - .PARAMETER XMaxValue - Maximum value for the scale along the X-axis. - .PARAMETER XMinValue - Minimum value for the scale along the X-axis. - .PARAMETER xAxisPosition - Position for the X-axis ("Top" or" Bottom"). - .PARAMETER YAxisTitleText - Specifies a title for the Y-axis. - .PARAMETER YAxisTitleBold - Sets the Y-axis title in bold face. - .PARAMETER YAxisTitleSize - Sets the font size for the Y-axis title. - .PARAMETER YAxisNumberformat - A number formatting string, like "#,##0.00", for numbers on the Y-axis - .PARAMETER YMajorUnit - Spacing for the major gridlines / tick marks on the Y-axis. - .PARAMETER YMinorUnit - Spacing for the minor gridlines / tick marks on the Y-axis. - .PARAMETER YMaxValue - Maximum value on the Y-axis. - .PARAMETER YMinValue - Minimum value on the Y-axis. - .PARAMETER YAxisPosition - Position for the Y-axis ("Left" or "Right"). - .PARAMETER Header - No longer used. This may be removed in future versions. - .Example - > - PS> $cDef = New-ExcelChartDefinition -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 ` - -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" ` - -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 ` - -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom - - 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -now -WorkSheetname SinX -ExcelChartDefinition $cDef -Show - - This reworks an example from Add-Excel-Chart but here the chart is defined - and the defintion stored in $cDef and then Export-Excel uses $cDef . - #> - [Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook. - [cmdletbinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] - param( - $Title = "Chart Title", - $Header, - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked", - [OfficeOpenXml.Drawing.Chart.eTrendLine[]]$ChartTrendLine, - $XRange, - $YRange, - $Width = 500, - $Height = 350, - $Row = 0, - $RowOffSetPixels = 10, - $Column = 6, - $ColumnOffSetPixels = 5, - [OfficeOpenXml.Drawing.Chart.eLegendPosition]$LegendPosition, - $LegendSize, - [Switch]$LegendBold, - [Switch]$NoLegend, - [Switch]$ShowCategory, - [Switch]$ShowPercent, - $SeriesHeader, - [Switch]$TitleBold, - [Int]$TitleSize , - [String]$XAxisTitleText, - [Switch]$XAxisTitleBold, - $XAxisTitleSize , - [string]$XAxisNumberformat, - $XMajorUnit, - $XMinorUnit, - $XMaxValue, - $XMinValue, - [OfficeOpenXml.Drawing.Chart.eAxisPosition]$XAxisPosition , - [String]$YAxisTitleText, - [Switch]$YAxisTitleBold, - $YAxisTitleSize, - [string]$YAxisNumberformat, - $YMajorUnit, - $YMinorUnit, - $YMaxValue, - $YMinValue, - [OfficeOpenXml.Drawing.Chart.eAxisPosition]$YAxisPosition - ) - if ( $Header ) { Write-Warning "The header parameter is ignored." } #Nothing was done with it when creating a chart. - #might be able to do [PSCustomObject]$PsboundParameters, the defaults here match those in Add-Excel Chart - [PSCustomObject]@{ - Title = $Title - ChartType = $ChartType - ChartTrendLine = $ChartTrendLine - XRange = $XRange - YRange = $YRange - Width = $Width - Height = $Height - Row = $Row - RowOffSetPixels = $RowOffSetPixels - Column = $Column - ColumnOffSetPixels = $ColumnOffSetPixels - LegendPosition = $LegendPosition - LegendSize = $LegendSize - Legendbold = $LegendBold - NoLegend = $NoLegend -as [Boolean] - ShowCategory = $ShowCategory -as [Boolean] - ShowPercent = $ShowPercent -as [Boolean] - SeriesHeader = $SeriesHeader - TitleBold = $TitleBold -as [Boolean] - TitleSize = $TitleSize - XAxisTitleText = $XAxisTitleText - XAxisTitleBold = $XAxisTitleBold -as [Boolean] - XAxisTitleSize = $XAxisTitleSize - XAxisNumberformat = $XAxisNumberformat - XMajorUnit = $XMajorUnit - XMinorUnit = $XMinorUnit - XMaxValue = $XMaxValue - XMinValue = $XMinValue - XAxisPosition = $XAxisPosition - YAxisTitleText = $YAxisTitleText - YAxisTitleBold = $YAxisTitleBold -as [Boolean] - YAxisTitleSize = $YAxisTitleSize - YAxisNumberformat = $YAxisNumberformat - YMajorUnit = $YMajorUnit - YMinorUnit = $YMinorUnit - YMaxValue = $YMaxValue - YMinValue = $YMinValue - YAxisPosition = $YAxisPosition - } -} - -function Add-ExcelChart { - <# - .SYNOPSIS - Creates a chart in an existing Excel worksheet. - .DESCRIPTION - Creates a chart. It is possible to configure the type of chart, the range of X values (labels) and Y values. - the title, the legend, the ranges for both axes, the format and position of the axes. - Normally the command does not return anything, but if -passthru is specified the chart is returned so that it can be customized. - .PARAMETER Worksheet - An existing Sheet where the chart will be created. - .PARAMETER Title - The title for the chart. - .PARAMETER TitleBold - Sets the title in bold face. - .PARAMETER TitleSize - Sets the point size for the title. - .PARAMETER ChartType - One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". - .PARAMETER XRange - The range of cells containing values for the X-Axis - usually labels. - .PARAMETER YRange - The range(s) of cells holding values for the Y-Axis - usually "data". - .PARAMETER PivotTable - Instead of specify X and Y ranges, get data from a PivotTable by passing a PivotTable Object. - .PARAMETER Width - Width of the chart in Pixels. Defaults to 500. - .PARAMETER Height - Height of the chart in Pixels. Defaults to 350. - .PARAMETER Row - Row position of the top left corner of the chart. 0 places at the top of the sheet, 1 below row 1 and so on. - .PARAMETER RowOffSetPixels - Offset to position the chart by a fraction of a row. - .PARAMETER Column - Column position of the top left corner of the chart. 0 places at the edge of the sheet 1 to the right of column A and so on. - .PARAMETER ColumnOffSetPixels - Offset to position the chart by a fraction of a column. - .PARAMETER NoLegend - If specified, turns of display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. - .PARAMETER SeriesHeader - Specify explicit name(s) for the data series, which will appear in the legend/key. The contents of a cell can be specified in the from =Sheet9!Z10 . - .PARAMETER LegendPosition - Location of the key, either left, right, top, bottom or TopRight. - .PARAMETER LegendSize - Font size for the key. - .PARAMETER LegendBold - Sets the key in bold type. - .PARAMETER ShowCategory - Attaches a category label in charts which support this. - .PARAMETER ShowPercent - Attaches a percentage label in charts which support this. - .PARAMETER XAxisTitleText - Specifies a title for the X-axis. - .PARAMETER XAxisTitleBold - Sets the X-axis title in bold face. - .PARAMETER XAxisTitleSize - Sets the font size for the axis title. - .PARAMETER XAxisNumberformat - A number formatting string, like "#,##0.00", for numbers along the X-axis. - .PARAMETER XMajorUnit - Spacing for the major gridlines / tick marks along the X-axis. - .PARAMETER XMinorUnit - Spacing for the minor gridlines / tick marks along the X-axis. - .PARAMETER XMaxValue - Maximum value for the scale along the X-axis. - .PARAMETER XMinValue - Minimum value for the scale along the X-axis. - .PARAMETER xAxisPosition - Position for the X-axis (Top or Bottom). - .PARAMETER YAxisTitleText - Specifies a title for the Y-axis. - .PARAMETER YAxisTitleBold - Sets the Y-axis title in bold face. - .PARAMETER YAxisTitleSize - Sets the font size for the Y-axis title - .PARAMETER YAxisNumberformat - A number formatting string, like "#,##0.00", for numbers on the Y-axis. - .PARAMETER YMajorUnit - Spacing for the major gridlines / tick marks on the Y-axis. - .PARAMETER YMinorUnit - Spacing for the minor gridlines / tick marks on the Y-axis. - .PARAMETER YMaxValue - Maximum value on the Y-axis. - .PARAMETER YMinValue - Minimum value on the Y-axis. - .PARAMETER YAxisPosition - Position for the Y-axis (Left or Right). - .PARAMETER PassThru - Add-Excel chart doesn't normally return anything, but if -PassThru is specified it returns the newly created chart to allow it to be fine tuned. - .EXAMPLE - > - PS> $Excel = ConvertFrom-Csv @" - Product, City, Sales - Apple, London , 300 - Orange, London , 400 - Banana, London , 300 - Orange, Paris, 600 - Banana, Paris, 300 - Apple, New York, 1200 - "@ | Export-Excel -Path test.xlsx -PassThru - Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -ChartType "Doughnut" -XRange "A2:B7" -YRange "C2:C7" -width 500 - Close-ExcelPackage -Show $Excel - - The first command expands a multi-line string into 6 rows of data which is exported to new Excel file; leaving an ExcelPackage object in $excel - The second command adds a chart - the cell ranges are explicitly specified. Note that the XRange (labels) is TWO columns wide and the chart will - combine the name of the product and the name of the City to create the label. - The width of the chart is set explictly, the default legend is used and there is no Chart title. - .EXAMPLE - > - PS> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel $path -AutoSize -ExcelChartDefinition $c -AutoNameRange -PassThru - Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title "VM use" -ChartType PieExploded3D -XRange "Name" -YRange "VirtualMemorySize" -NoLegend -ShowCategory - Close-ExcelPackage $Excel -Show - - The first line exports information and creates named ranges for each column. - The Second line uses the ranges to specify a chart - the labels come from the range "Name" and the data from the range "VirtualMemorySize" - The chart is specified as a 3D exploded PIE chart, with a title of "VM Use" and instead of a legend the the pie slices are identified with a label. - .EXAMPLE - > - PS> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel test.xlsx -TableName Processes -PassThru - Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title Stats -ChartType LineMarkersStacked -XRange "Processes[Name]" -YRange "Processes[PM]", "Processes[VirtualMemorySize]" -SeriesHeader 'PM', 'VMSize' - Close-ExcelPackage $Excel -Show - - The first line exports information to a table in new file; and captures the excel Package object in $Excel - The second line creates a chart on the first page of the work sheet, using the notation "TableName[ColumnnName]" to refer to the data, - the labels come Name column in the table, and the data series from its PM and VirtualMemorySize columns. The display names for these in the header are set to PM and VMSize - .EXAMPLE - > - PS> $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path Text.xlsx -WorkSheetname SinX -PassThru - Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 ` - -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" ` - -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 ` - -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom - Close-ExcelPackage $Excel -Show - - The first line puts numbers from 0 to 360 into a sheet, as the first column, and - a formula to calculate the Sine of that number of number of degrees in the second column. - It creates named-ranges for the two columns - "X" and "SinX" respectively - The Add-ExcelChart command adds a chart to that worksheet, specifying a line chart - with the X values coming from named-range "X" and the Y values coming from named-range "SinX". - The chart has a title, and is positioned to the right of column 2 and sized 800 pixels wide - The X-axis is labelled "Degrees", in bold 12 point type and runs from 0 to 361 with labels every 30, - and minor tick marks every 10. Degrees are shown padded to 3 digits. - The Y-axis is labelled "Sine" and to allow some room above and below its scale runs from -1.25 to 1.25, - and is marked off in units of 0.25 shown to two decimal places. - The key will for the chart will be at the bottom in 8 point bold type and the line will be named "Sin(x)". - #> - [cmdletbinding(DefaultParameterSetName = 'Worksheet')] - [OutputType([OfficeOpenXml.Drawing.Chart.ExcelChart])] - param( - [Parameter(ParameterSetName = 'Workshet', Mandatory = $true)] - [OfficeOpenXml.ExcelWorksheet]$Worksheet, - [Parameter(ParameterSetName = 'PivotTable', Mandatory = $true)] - [OfficeOpenXml.Table.PivotTable.ExcelPivotTable]$PivotTable , - [String]$Title, - #$Header, Not used but referenced previously - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked", - [OfficeOpenXml.Drawing.Chart.eTrendLine[]]$ChartTrendLine, - $XRange, - $YRange, - [int]$Width = 500, - [int]$Height = 350, - [int]$Row = 0, - [int]$RowOffSetPixels = 10, - [int]$Column = 6, - [int]$ColumnOffSetPixels = 5, - [OfficeOpenXml.Drawing.Chart.eLegendPosition]$LegendPosition, - $LegendSize, - [Switch]$LegendBold, - [Switch]$NoLegend, - [Switch]$ShowCategory, - [Switch]$ShowPercent, - [String[]]$SeriesHeader, - [Switch]$TitleBold, - [Int]$TitleSize , - [String]$XAxisTitleText, - [Switch]$XAxisTitleBold, - $XAxisTitleSize , - [string]$XAxisNumberformat, - $XMajorUnit, - $XMinorUnit, - $XMaxValue, - $XMinValue, - [OfficeOpenXml.Drawing.Chart.eAxisPosition]$XAxisPosition , - [String]$YAxisTitleText, - [Switch]$YAxisTitleBold, - $YAxisTitleSize, - [string]$YAxisNumberformat, - $YMajorUnit, - $YMinorUnit, - $YMaxValue, - $YMinValue, - [OfficeOpenXml.Drawing.Chart.eAxisPosition]$YAxisPosition, - [Switch]$PassThru - ) - try { - if ($PivotTable) { - $Worksheet = $PivotTable.WorkSheet - $chart = $Worksheet.Drawings.AddChart(("Chart" + $PivotTable.Name ), $ChartType, $PivotTable) - } - else { - $ChartName = 'Chart' + (Split-Path -Leaf ([System.IO.path]::GetTempFileName())) -replace 'tmp|\.', '' - $chart = $Worksheet.Drawings.AddChart($ChartName, $ChartType) - $chartDefCount = @($YRange).Count - if ($chartDefCount -eq 1) { - $Series = $chart.Series.Add($YRange, $XRange) - if ($ChartTrendLine) { - if ($ChartType -notmatch "stacked|3D$|pie|Doughnut|Cone|Cylinder|Pyramid") { - foreach ($trendLine in $ChartTrendLine) { - $null = $Series.TrendLines.Add($trendLine) - } - } - else { - Write-Warning "Chart trend line is not supported for chart type: $ChartType" - } - } - if ($SeriesHeader) { $Series.Header = $SeriesHeader } - else { $Series.Header = 'Series 1' } - } - else { - for ($idx = 0; $idx -lt $chartDefCount; $idx += 1) { - if ($Yrange.count -eq $xrange.count) { - $Series = $chart.Series.Add($YRange[$idx], $XRange[$idx]) - } - else { - $Series = $chart.Series.Add($YRange[$idx], $XRange) - } - if ($SeriesHeader.Count -gt 0) { - if ($SeriesHeader[$idx] -match '^=') { $Series.HeaderAddress = $SeriesHeader[$idx] -replace '^=', '' } - else { $Series.Header = $SeriesHeader[$idx] } - } - else { $Series.Header = "Series $($idx)" } - } - } - } - if ($Title) { - $chart.Title.Text = $Title - if ($TitleBold) { $chart.Title.Font.Bold = $true } - if ($TitleSize) { $chart.Title.Font.Size = $TitleSize } - } - if ($NoLegend) { $chart.Legend.Remove() } - else { - if ($PSBoundParameters.ContainsKey('LegendPosition')) { $chart.Legend.Position = $LegendPosition } - if ($PSBoundParameters.ContainsKey('LegendBold')) { $chart.Legend.Font.Bold = [boolean]$LegendBold } - if ($LegendSize) { $chart.Legend.Font.Size = $LegendSize } - } - - if ($XAxisTitleText) { - $chart.XAxis.Title.Text = $XAxisTitleText - if ($PSBoundParameters.ContainsKey('XAxisTitleBold')) { - $chart.XAxis.Title.Font.Bold = [boolean]$XAxisTitleBold - } - if ($XAxisTitleSize) { $chart.XAxis.Title.Font.Size = $XAxisTitleSize } - } - if ($XAxisPosition) { Write-Warning "X-axis position is not being set propertly at the moment, parameter ignored" } - #$chart.ChartXml.chartSpace.chart.plotArea.catAx.axPos.val = $XAxisPosition.ToString().substring(0,1)} - if ($XMajorUnit) { $chart.XAxis.MajorUnit = $XMajorUnit } - if ($XMinorUnit) { $chart.XAxis.MinorUnit = $XMinorUnit } - if ($null -ne $XMinValue) { $chart.XAxis.MinValue = $XMinValue } - if ($null -ne $XMaxValue) { $chart.XAxis.MaxValue = $XMaxValue } - if ($XAxisNumberformat) { $chart.XAxis.Format = (Expand-NumberFormat $XAxisNumberformat) } - - if ($YAxisTitleText) { - $chart.YAxis.Title.Text = $YAxisTitleText - if ($PSBoundParameters.ContainsKey('YAxisTitleBold')) { - $chart.YAxis.Title.Font.Bold = [boolean]$YAxisTitleBold - } - if ($YAxisTitleSize) { $chart.YAxis.Title.Font.Size = $YAxisTitleSize } - } - if ($YAxisPosition) { Write-Warning "Y-axis position is not being set propertly at the moment, parameter ignored" } - #$chart.ChartXml.chartSpace.chart.plotArea.valAx.axPos.val= $YAxisPosition.ToString().substring(0,1)} - if ($YMajorUnit) { $chart.YAxis.MajorUnit = $YMajorUnit } - if ($YMinorUnit) { $chart.YAxis.MinorUnit = $YMinorUnit } - if ($null -ne $YMinValue) { $chart.YAxis.MinValue = $YMinValue } - if ($null -ne $YMaxValue) { $chart.YAxis.MaxValue = $YMaxValue } - if ($YAxisNumberformat) { $chart.YAxis.Format = (Expand-NumberFormat $YAxisNumberformat) } - if ($null -ne $chart.Datalabel) { - $chart.Datalabel.ShowCategory = [boolean]$ShowCategory - $chart.Datalabel.ShowPercent = [boolean]$ShowPercent - } - - $chart.SetPosition($Row, $RowOffsetPixels, $Column, $ColumnOffsetPixels) - $chart.SetSize($Width, $Height) - - if ($PassThru) { return $chart } - } - catch { Write-Warning -Message "Failed adding Chart to worksheet '$($WorkSheet).name': $_" } -} diff --git a/New-Plot.md b/New-Plot.md new file mode 100644 index 0000000..0c233b4 --- /dev/null +++ b/New-Plot.md @@ -0,0 +1,42 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-Plot + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +New-Plot +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Open-ExcelPackage.ps1 b/Open-ExcelPackage.ps1 deleted file mode 100644 index 3c5a7b2..0000000 --- a/Open-ExcelPackage.ps1 +++ /dev/null @@ -1,129 +0,0 @@ -Function Open-ExcelPackage { -<# -.Synopsis - Returns an ExcelPackage object for the specified XLSX fil.e -.Description - Import-Excel and Export-Excel open an Excel file, carry out their tasks and close it again. - Sometimes it is necessary to open a file and do other work on it. - Open-ExcelPackage allows the file to be opened for these tasks. - It takes a -KillExcel switch to make sure Excel is not holding the file open; - a -Password parameter for existing protected files, - and a -Create switch to set-up a new file if no file already exists. -.Example - > - PS> $excel = Open-ExcelPackage -Path "$env:TEMP\test99.xlsx" -Create - $ws = Add-WorkSheet -ExcelPackage $excel - - This will create a new file in the temp folder if it doesn't already exist. - It then adds a worksheet - because no name is specified it will use the - default name of "Sheet1" -.Example - > - PS> $excel = Open-ExcelPackage -path "$xlPath" -Password $password - $sheet1 = $excel.Workbook.Worksheets["sheet1"] - Set-ExcelRange -Range $sheet1.Cells["E1:S1048576"], $sheet1.Cells["V1:V1048576"] -NFormat ([cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern) - Close-ExcelPackage $excel -Show - - This will open the password protected file at $xlPath using the password stored - in $Password. Sheet1 is selected and formatting applied to two blocks of the sheet; - then the file is and saved and loaded into Excel. -#> - [CmdLetBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] - [OutputType([OfficeOpenXml.ExcelPackage])] - Param ( - #The path to the file to open. - [Parameter(Mandatory=$true)]$Path, - #If specified, any running instances of Excel will be terminated before opening the file. - [switch]$KillExcel, - #The password for a protected worksheet, as a [normal] string (not a secure string). - [String]$Password, - #By default Open-ExcelPackage will only opens an existing file; -Create instructs it to create a new file if required. - [switch]$Create - ) - - if($KillExcel) { - Get-Process -Name "excel" -ErrorAction Ignore | Stop-Process - while (Get-Process -Name "excel" -ErrorAction Ignore) {} - } - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - #If -Create was not specified only open the file if it exists already (send a warning if it doesn't exist). - if ($Create -and -not (Test-Path -Path $path)) { - #Create the directory if required. - $targetPath = Split-Path -Parent -Path $Path - if (!(Test-Path -Path $targetPath)) { - Write-Debug "Base path $($targetPath) does not exist, creating" - $null = New-item -ItemType Directory -Path $targetPath -ErrorAction Ignore - } - New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path - } - elseif (Test-Path -Path $path) { - if ($Password) {$pkgobj = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path , $Password } - else {$pkgobj = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path } - if ($pkgobj) { - foreach ($w in $pkgobj.Workbook.Worksheets) { - $sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $w.name)) - Add-Member -InputObject $pkgobj -MemberType ScriptProperty -Name $w.name -Value $sb - } - return $pkgobj - } - } - else {Write-Warning "Could not find $path" } - } - -Function Close-ExcelPackage { - <# - .Synopsis - Closes an Excel Package, saving, saving under a new name or abandoning changes and opening the file in Excel as required. - .Description - When working with an ExcelPackage object, the Workbook is held in memory and not saved until the .Save() method of the package is called. - Close-ExcelPackage saves and disposes of the Package object. It can be called with -NoSave to abandon the file without saving, with a new "SaveAs" filename, - and/or with a password to protect the file. And -Show will open the file in Excel; - -Calculate will try to update the workbook, although not everything can be recalculated - .Example - Close-ExcelPackage -show $excel - $excel holds a package object, this saves the workbook and loads it into Excel. - .Example - Close-ExcelPackage -NoSave $excel - $excel holds a package object, this disposes of it without writing it to disk. - #> - [CmdLetBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] - Param ( - #Package to close. - [parameter(Mandatory=$true, ValueFromPipeline=$true)] - [OfficeOpenXml.ExcelPackage]$ExcelPackage, - #Open the file in Excel. - [switch]$Show, - #Abandon the file without saving. - [Switch]$NoSave, - #Save file with a new name (ignored if -NoSave Specified). - $SaveAs, - #Password to protect the file. - [ValidateNotNullOrEmpty()] - [String]$Password, - #Attempt to recalculation the workbook before saving - [switch]$Calculate - ) - if ( $NoSave) {$ExcelPackage.Dispose()} - else { - if ($Calculate) { - try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) } - Catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."} - } - if ($SaveAs) { - $SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs) - if ($Password) {$ExcelPackage.SaveAs( $SaveAs, $Password ) } - else {$ExcelPackage.SaveAs( $SaveAs)} - } - Else { - if ($Password) {$ExcelPackage.Save($Password) } - else {$ExcelPackage.Save() } - $SaveAs = $ExcelPackage.File.FullName - } - $ExcelPackage.Dispose() - if ($Show) {Start-Process -FilePath $SaveAs } - } -} - diff --git a/Pivot/Pivot.md b/Pivot/Pivot.md new file mode 100644 index 0000000..1ff8fcd --- /dev/null +++ b/Pivot/Pivot.md @@ -0,0 +1,107 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Pivot + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Pivot [[-targetData] ] [[-pivotRows] ] [[-pivotData] ] [[-ChartType] ] + [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ChartType +{{ Fill ChartType Description }} + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -pivotData +{{ Fill pivotData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -pivotRows +{{ Fill pivotRows Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -targetData +{{ Fill targetData Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Pivot.ps1 b/Pivot/Pivot.ps1 similarity index 100% rename from Pivot.ps1 rename to Pivot/Pivot.ps1 diff --git a/PivotTable.ps1 b/PivotTable.ps1 deleted file mode 100644 index 5eca5dd..0000000 --- a/PivotTable.ps1 +++ /dev/null @@ -1,420 +0,0 @@ -function Add-PivotTable { - <# - .Synopsis - Adds a PivotTable (and optional PivotChart) to a workbook. - .Description - If the PivotTable already exists, the source data will be updated. - .Example - > - PS> $excel = Get-Service | Export-Excel -Path test.xlsx -WorksheetName Services -PassThru -AutoSize -DisplayPropertySet -TableName ServiceTable -Title "Services on $Env:COMPUTERNAME" - Add-PivotTable -ExcelPackage $excel -PivotTableName ServiceSummary -SourceRange $excel.Workbook.Worksheets[1].Tables[0].Address -PivotRows Status -PivotData Name -NoTotalsInPivot -Activate - Close-ExcelPackage $excel -Show - - This exports data to new workbook and creates a table with the data in. - The Pivot table is added on its own page, the table created in the first command is used as the source for the PivotTable; which counts the service names in for each Status. At the end the Pivot page is made active. - .Example - > - PS> $chartdef = New-ExcelChartDefinition -Title "Gross and net by city and product" -ChartType ColumnClustered ` - -Column 11 -Width 500 -Height 360 -YMajorUnit 500 -YMinorUnit 100 -YAxisNumberformat "$#,##0" -LegendPosition Bottom - - $excel = ConvertFrom-Csv @" - Product, City, Gross, Net - Apple, London , 300, 250 - Orange, London , 400, 350 - Banana, London , 300, 200 - Orange, Paris, 600, 500 - Banana, Paris, 300, 200 - Apple, New York, 1200,700 - "@ | Export-Excel -Path "test.xlsx" -TableStyle Medium13 -tablename "RawData" -PassThru - - Add-PivotTable -PivotTableName Sales -Address $excel.Workbook.Worksheets[1].Cells["F1"] ` - -SourceWorkSheet $excel.Workbook.Worksheets[1] -PivotRows City -PivotColumns Product -PivotData @{Gross="Sum";Net="Sum"} ` - -PivotNumberFormat "$#,##0.00" -PivotTotals Both -PivotTableStyle Medium12 -PivotChartDefinition $chartdef - Close-ExcelPackage -show $excel - - - This script starts by defining a chart. Then it exports some data to an XLSX file and keeps the file open. - The next step is to add the pivot table, normally this would be on its own sheet in the workbook, - but here -Address is specified to place it beside the data. The Add-Pivot table is given the chart definition and told to create a tale - using the City field to create rows, the Product field to create columns and the data should be the sum of the gross field and the sum of the net field; - grand totals for both gross and net are included for rows (Cities) and columns (product) and the data is explicitly formatted as a currency. - Note that in the chart definition the number format for the axis does not include any fraction part. - .Example - > - $excel = Convertfrom-csv @" - Location,OrderDate,quantity - Boston,1/1/2017,100 - New York,1/21/2017,200 - Boston,1/11/2017,300 - New York,1/9/2017,400 - Boston,1/18/2017,500 - Boston,2/1/2017,600 - New York,2/21/2017,700 - New York,2/11/2017,800 - Boston,2/9/2017,900 - Boston,2/18/2017,1000 - New York,1/1/2018,100 - Boston,1/21/2018,200 - New York,1/11/2018,300 - Boston,1/9/2018,400 - New York,1/18/2018,500 - Boston,2/1/2018,600 - Boston,2/21/2018,700 - New York,2/11/2018,800 - New York,2/9/2018,900 - Boston,2/18/2018,1000 - "@ | Select-Object -Property @{n="OrderDate";e={[datetime]::ParseExact($_.OrderDate,"M/d/yyyy",(Get-Culture))}}, - Location, Quantity | Export-Excel "test2.xlsx" -PassThru -AutoSize - - Set-ExcelColumn -Worksheet $excel.sheet1 -Column 1 -NumberFormat 'Short Date' - - $pt = Add-PivotTable -PassThru -PivotTableName "ByDate" -Address $excel.Sheet1.cells["F1"] -SourceWorkSheet $excel.Sheet1 -PivotRows location,orderdate -PivotData @{'quantity'='sum'} -GroupDateRow orderdate -GroupDatePart 'Months,Years' -PivotTotals None - $pt.RowFields[0].SubtotalTop=$false - $pt.RowFields[0].Compact=$false - Close-ExcelPackage $excel -Show - - Here the data contains dates formatted as strings using US format. These - are converted to DateTime objects before being exported to Excel; the - "OrderDate" column is formatted with the local short-date style. Then - the PivotTable is added; it groups information by date and location, the - date is split into years and then months. No grand totals are displayed. - The Pivot table object is caught in a variable, and the "Location" - column has its subtotal moved from the top to the bottom of each location - section, and the "Compact" option is disabled to prevent "Year" moving - into the same column as location. - Finally the workbook is saved and shown in Excel. - #> - [cmdletbinding(defaultParameterSetName = 'ChartbyParams')] - [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] - param ( - #Name for the new PivotTable - this will be the name of a sheet in the Workbook. - [Parameter(Mandatory = $true)] - [string]$PivotTableName, - #By default, a PivotTable will be created on its own sheet, but it can be created on an existing sheet by giving the address where the top left corner of the table should go. (Allow two rows for the filter if one is used.) - [OfficeOpenXml.ExcelAddressBase] - $Address, - #An excel package object for the workbook. - $ExcelPackage, - #Worksheet where the data is found. - $SourceWorkSheet, - #Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used. - $SourceRange, - #Fields to set as rows in the PivotTable. - $PivotRows, - #A hash table in form "FieldName"="Function", where function is one of - #Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. - $PivotData, - #Fields to set as columns in the PivotTable. - $PivotColumns, - #Fields to use to filter in the PivotTable. - $PivotFilter, - #If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. - [Switch]$PivotDataToColumn, - #Define whether totals should be added to rows, columns neither, or both (the default is both). - [ValidateSet("Both", "Columns", "Rows", "None")] - [String]$PivotTotals = "Both", - #Included for compatibility - equivalent to -PivotTotals "None". - [Switch]$NoTotalsInPivot, - #The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) - [String]$GroupDateRow, - #The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) - [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, - #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) - [String]$GroupNumericRow, - #The starting point for grouping - [double]$GroupNumericMin = 0 , - #The endpoint for grouping - [double]$GroupNumericMax = [Double]::MaxValue , - #The interval for grouping - [double]$GroupNumericInterval = 100 , - #Number format to apply to the data cells in the PivotTable. - [string]$PivotNumberFormat, - #Apply a table style to the PivotTable. - [OfficeOpenXml.Table.TableStyles]$PivotTableStyle, - #Use a chart definition instead of specifying chart settings one by one. - [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)] - $PivotChartDefinition, - #If specified, a chart will be included. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$IncludePivotChart, - #Optional title for the pivot chart, by default the title omitted. - [Parameter(ParameterSetName = 'ChartbyParams')] - [String]$ChartTitle = "", - #Height of the chart in Pixels (400 by default). - [Parameter(ParameterSetName = 'ChartbyParams')] - [int]$ChartHeight = 400 , - #Width of the chart in Pixels (600 by default). - [Parameter(ParameterSetName = 'ChartbyParams')] - [int]$ChartWidth = 600, - #Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartRow = 0 , - #Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E). - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartColumn = 4, - #Vertical offset of the chart from the cell corner. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartRowOffSetPixels = 0 , - [Parameter(ParameterSetName = 'ChartbyParams')] - #Horizontal offset of the chart from the cell corner. - [Int]$ChartColumnOffSetPixels = 0, - #Type of chart; defaults to "Pie". - [Parameter(ParameterSetName = 'ChartbyParams')] - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', - #If specified hides the chart legend. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$NoLegend, - #If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$ShowCategory, - #If specified attaches percentages to slices in a pie chart. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$ShowPercent, - #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. - [switch]$Activate, - #Return the PivotTable so it can be customized. - [Switch]$PassThru - ) - if ($PivotTableName.length -gt 250) { - Write-warning -Message "PivotTable name will be truncated" - $PivotTableName = $PivotTableName.Substring(0, 250) - } - if ($Address) { - [OfficeOpenXml.ExcelWorksheet]$wsPivot = $address.Worksheet - } - else { - try { - if (-not $ExcelPackage) {Write-Warning -message "This combination of Parameters needs to include the ExcelPackage." ; return } - [OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-WorkSheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate - if ($wsPivot.Name -ne $PivotTableName) {Write-Warning -Message "The Worksheet name for the PivotTable does not match the table name '$PivotTableName'; probably because excess or illegal characters were removed." } - if ($PivotFilter) {$Address = $wsPivot.Cells["A3"]} else { $Address = $wsPivot.Cells["A1"]} - } - catch {throw "Could not create the sheet for the PivotTable. $_" } - } - #if the pivot doesn't exist, create it. - if (-not $wsPivot) {throw "There was a problem getting the worksheet for the PivotTable"} - if (-not $wsPivot.PivotTables[$pivotTableName] ) { - try { - #Accept a string or a worksheet object as $SourceWorksheet - we don't need a worksheet if we have a Rangebase . - if ( $SourceWorkSheet -is [string]) { - $SourceWorkSheet = $ExcelPackage.Workbook.Worksheets.where( {$_.name -Like $SourceWorkSheet})[0] - } - elseif ( $SourceWorkSheet -is [int] ) { - $SourceWorkSheet = $ExcelPackage.Workbook.Worksheets[$SourceWorkSheet] - } - if ( $SourceRange -is [OfficeOpenXml.Table.ExcelTable]) {$SourceRange = $SourceRange.Address } - if ( $sourceRange -is [OfficeOpenXml.ExcelRange] -or - $SourceRange -is [OfficeOpenXml.ExcelAddress]) { - $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceRange, $pivotTableName) - } - elseif (-not $SourceRange) { - $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.cells[$SourceWorkSheet.Dimension.Address], $pivotTableName) - } - elseif ($SourceWorkSheet -isnot [OfficeOpenXml.ExcelWorksheet] ) { - Write-Warning -Message "Could not find source Worksheet for pivot-table '$pivotTableName'." ; return - } - elseif ( $SourceRange -is [String] -or $SourceRange -is [OfficeOpenXml.ExcelAddress]) { - $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.Cells[$SourceRange], $pivotTableName) - } - else {Write-warning "Could not create a PivotTable with the Source Range provided."; return} - foreach ($Row in $PivotRows) { - try {$null = $pivotTable.RowFields.Add($pivotTable.Fields[$Row]) } - catch {Write-Warning -message "Could not add '$row' to Rows in PivotTable $pivotTableName." } - } - foreach ($Column in $PivotColumns) { - try {$null = $pivotTable.ColumnFields.Add($pivotTable.Fields[$Column])} - catch {Write-Warning -message "Could not add '$Column' to Columns in PivotTable $pivotTableName." } - } - if ($PivotData -is [HashTable] -or $PivotData -is [System.Collections.Specialized.OrderedDictionary]) { - $PivotData.Keys | ForEach-Object { - try { - $df = $pivotTable.DataFields.Add($pivotTable.Fields[$_]) - $df.Function = $PivotData.$_ - if ($PivotNumberFormat) {$df.Format = (Expand-NumberFormat -NumberFormat $PivotNumberFormat)} - } - catch {Write-Warning -message "Problem adding data fields to PivotTable $pivotTableName." } - } - } - else { - foreach ($field in $PivotData) { - try { - $df = $pivotTable.DataFields.Add($pivotTable.Fields[$field]) - $df.Function = 'Count' - } - catch {Write-Warning -message "Problem adding data field '$field' to PivotTable $pivotTableName." } - } - } - foreach ( $pFilter in $PivotFilter) { - try { $null = $pivotTable.PageFields.Add($pivotTable.Fields[$pFilter])} - catch {Write-Warning -message "Could not add '$pFilter' to Filter/Page fields in PivotTable $pivotTableName." } - } - if ($NoTotalsInPivot) {$PivotTotals = "None" } - if ($PivotTotals -eq "None" -or $PivotTotals -eq "Columns") { $pivotTable.RowGrandTotals = $false } - elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Rows") { $pivotTable.RowGrandTotals = $true } - if ($PivotTotals -eq "None" -or $PivotTotals -eq "Rows") { $pivotTable.ColumGrandTotals = $false } # Epplus spelling mistake, not mine! - elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Columns") { $pivotTable.ColumGrandTotals = $true } - if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false } - if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle} - if ($GroupNumericRow) { - $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupNumericRow }) - if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupNumericRow'; no numeric grouping will be done."} - else {$r.AddNumericGrouping($GroupNumericMin, $GroupNumericMax, $GroupNumericInterval)} - } - if ($GroupDateRow -and $PSBoundParameters.ContainsKey("GroupDatePart")) { - $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupDateRow }) - if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupDateRow'; no date grouping will be done."} - else {$r.AddDateGrouping($GroupDatePart)} - } - } - catch {Write-Warning -Message "Failed adding PivotTable '$pivotTableName': $_"} - } - else { - Write-Warning -Message "PivotTable defined in $($pivotTableName) already exists, only the data range will be changed." - $pivotTable = $wsPivot.PivotTables[$pivotTableName] - if (-not $SourceRange) { $SourceRange = $SourceWorkSheet.Dimension.Address} - $pivotTable.CacheDefinition.SourceRange = $SourceWorkSheet.cells[$SourceRange] - #change for epPlus 4.5 - Previously needed to hack the xml - # $pivotTable.CacheDefinition.CacheDefinitionXml.pivotCacheDefinition.cacheSource.worksheetSource.ref = $SourceRange - - } - - #Create the chart if it doesn't exist, leave alone if it does. - if ($IncludePivotChart -and -not $wsPivot.Drawings["Chart$pivotTableName"] ) { - try {Add-ExcelChart -PivotTable $pivotTable -ChartType $ChartType -Width $ChartWidth -Height $ChartHeight -Row $ChartRow -Column $ChartColumn -RowOffSetPixels $ChartRowOffSetPixels -ColumnOffSetPixels $ChartColumnOffSetPixels -Title $ChartTitle -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent } - catch {Write-Warning -Message "Failed adding chart for pivotable '$pivotTableName': $_"} - } - elseif ($PivotChartDefinition -and -not $wsPivot.Drawings["Chart$pivotTableName"]) { - if ($PivotChartDefinition -is [System.Management.Automation.PSCustomObject]) { - $params = @{PivotTable = $pivotTable } - $PivotChartDefinition.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}} - Add-ExcelChart @params - } - elseif ($PivotChartDefinition -is [hashtable] -or $PivotChartDefinition -is [System.Collections.Specialized.OrderedDictionary]) { - Add-ExcelChart -PivotTable $pivotTable @PivotChartDefinition - } - } - if ($PassThru) {return $pivotTable} -} - -function New-PivotTableDefinition { - <# - .Synopsis - Creates PivotTable definitons for Export-Excel - .Description - Export-Excel allows a single PivotTable to be defined using the parameters -IncludePivotTable, -PivotColumns -PivotRows, - -PivotData, -PivotFilter, -PivotTotals, -PivotDataToColumn, -IncludePivotChart and -ChartType. - Its -PivotTableDefintion paramater allows multiple PivotTables to be defined, with additional parameters. - New-PivotTableDefinition is a convenient way to build these definitions. - .Example - > - PS> $pt = New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet "Sheet1" -PivotRows "Status" -PivotData @{Status='Count' } -PivotFilter 'StartType' -IncludePivotChart -ChartType BarClustered3D - $Pt += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet "Sheet2" -PivotRows "Company" -PivotData @{Company='Count'} -IncludePivotChart -ChartType PieExploded3D -ShowPercent -ChartTitle "Breakdown of processes by company" - Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize - Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' - $excel = Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show - - This is a re-work of one of the examples in Export-Excel - instead of writing out the pivot definition hash table it is built by calling New-PivotTableDefinition. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] - param( - [Parameter(Mandatory)] - [Alias("PivtoTableName")]#Previous typo - use alias to avoid breaking scripts - $PivotTableName, - #Worksheet where the data is found - $SourceWorkSheet, - #Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used/ - $SourceRange, - #Fields to set as rows in the PivotTable - $PivotRows, - #A hash table in form "FieldName"="Function", where function is one of - #Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP - [hashtable]$PivotData, - #Fields to set as columns in the PivotTable - $PivotColumns, - #Fields to use to filter in the PivotTable - $PivotFilter, - #If there are multiple datasets in a PivotTable, by default they are shown seperatate rows under the given row heading; this switch makes them seperate columns. - [Switch]$PivotDataToColumn, - #By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. - #Define whther totals should be added to rows, columns neither, or both (the default is both) - [ValidateSet("Both", "Columns", "Rows", "None")] - [String]$PivotTotals = "Both", - #Included for compatibility - equivalent to -PivotTotals "None" - [Switch]$NoTotalsInPivot, - #The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) - [String]$GroupDateRow, - #The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) - [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, - #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) - [String]$GroupNumericRow, - #The starting point for grouping - [double]$GroupNumericMin = 0 , - #The endpoint for grouping - [double]$GroupNumericMax = [Double]::MaxValue , - #The interval for grouping - [double]$GroupNumericInterval = 100 , - #Number format to apply to the data cells in the PivotTable - [string]$PivotNumberFormat, - #Apply a table style to the PivotTable - [OfficeOpenXml.Table.TableStyles]$PivotTableStyle, - #Use a chart definition instead of specifying chart settings one by one - [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)] - $PivotChartDefinition, - #If specified a chart Will be included. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$IncludePivotChart, - #Optional title for the pivot chart, by default the title omitted. - [Parameter(ParameterSetName = 'ChartbyParams')] - [String]$ChartTitle, - #Height of the chart in Pixels (400 by default) - [Parameter(ParameterSetName = 'ChartbyParams')] - [int]$ChartHeight = 400 , - #Width of the chart in Pixels (600 by default) - [Parameter(ParameterSetName = 'ChartbyParams')] - [int]$ChartWidth = 600, - #Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartRow = 0 , - #Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E) - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartColumn = 4, - #Vertical offset of the chart from the cell corner. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartRowOffSetPixels = 0 , - #Horizontal offset of the chart from the cell corner. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Int]$ChartColumnOffSetPixels = 0, - #Type of chart - [Parameter(ParameterSetName = 'ChartbyParams')] - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', - #If specified hides the chart legend - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$NoLegend, - #if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$ShowCategory, - #If specified attaches percentages to slices in a pie chart. - [Parameter(ParameterSetName = 'ChartbyParams')] - [Switch]$ShowPercent, - #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified - [switch]$Activate - ) - $validDataFuntions = [system.enum]::GetNames([OfficeOpenXml.Table.PivotTable.DataFieldFunctions]) - - if ($PivotData.values.Where( {$_ -notin $validDataFuntions}) ) { - Write-Warning -Message ("Pivot data functions might not be valid, they should be one of " + ($validDataFuntions -join ", ") + ".") - } - - $parameters = @{} + $PSBoundParameters - if ($NoTotalsInPivot) { - $parameters.Remove('NoTotalsInPivot') - $parameters["PivotTotals"] = "None" - } - $parameters.Remove('PivotTableName') - if ($PivotChartDefinition) { - $parameters.PivotChartDefinition.XRange = $null - $parameters.PivotChartDefinition.YRange = $null - $parameters.PivotChartDefinition.SeriesHeader = $null - } - @{$PivotTableName = $parameters} -} diff --git a/SetFormat.ps1 b/SetFormat.ps1 deleted file mode 100644 index 272be88..0000000 --- a/SetFormat.ps1 +++ /dev/null @@ -1,496 +0,0 @@ -function Set-ExcelRange { - <# - .SYNOPSIS - Applies number, font, alignment and/or color formatting, values or formulas to a range of Excel cells. - .DESCRIPTION - Set-ExcelRange was created to set the style elements for a range of cells, - this includes auto-sizing and hiding, setting font elements (Name, Size, - Bold, Italic, Underline & UnderlineStyle and Subscript & SuperScript), - font and background colors, borders, text wrapping, rotation, alignment - within cells, and number format. - It was orignally named "Set-Format", but it has been extended to set - Values, Formulas and ArrayFormulas (sometimes called Ctrl-shift-Enter - [CSE] formulas); because of this, the name has become Set-ExcelRange - but the old name of Set-Format is preserved as an alias. - .EXAMPLE - $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NumberFormat "#,###" -AutoFit - - Selects column 3 from a sheet object (within a workbook object, which - is a child of the ExcelPackage object) and passes it to Set-ExcelRange - which formats numbers as a integers with comma-separated groups, - aligns it right, and auto-fits the column to the contents. - .EXAMPLE - Set-ExcelRange -Range $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###" - - Instead of piping the address, this version specifies a block of cells - and applies similar formatting. - .EXAMPLE - Set-ExcelRange $excel.Workbook.Worksheets[1].Tables["Processes"] -Italic - - This time instead of specifying a range of cells, a table is selected - by name and formatted as italic. - #> - [cmdletbinding()] - [Alias("Set-Format")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] - Param ( - #One or more row(s), Column(s) and/or block(s) of cells to format. - [Parameter(ValueFromPipeline = $true,Position=0)] - [Alias("Address")] - $Range , - #The worksheet where the format is to be applied. - [OfficeOpenXml.ExcelWorksheet]$WorkSheet , - #Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. - [Alias("NFormat")] - $NumberFormat, - #Style of border to draw around the range. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, - #Color of the border. - $BorderColor=[System.Drawing.Color]::Black, - #Style for the bottom border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom, - #Style for the top border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop, - #Style for the left border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft, - #Style for the right border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight, - #Colour for the text - if none is specified it will be left as it is. - [Alias('ForegroundColor')] - $FontColor, - #Value for the cell. - $Value, - #Formula for the cell. - $Formula, - #Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). - [Switch]$ArrayFormula, - #Clear Bold, Italic, StrikeThrough and Underline and set color to Black. - [Switch]$ResetFont, - #Make text bold; use -Bold:$false to remove bold. - [Switch]$Bold, - #Make text italic; use -Italic:$false to remove italic. - [Switch]$Italic, - #Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. - [Switch]$Underline, - #Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". - [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, - #Strike through text; use -Strikethru:$false to remove Strike through - [Switch]$StrikeThru, - #Subscript or Superscript (or none). - [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, - #Font to use - Excel defaults to Calibri. - [String]$FontName, - #Point size for the text. - [float]$FontSize, - #Change background color. - $BackgroundColor, - #Background pattern - Solid by default. - [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , - #Secondary color for background pattern. - [Alias("PatternColour")] - $PatternColor, - #Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. - [Switch]$WrapText, - #Position cell contents to Left, Right, Center etc. default is 'General'. - [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, - #Position cell contents to Top, Bottom or Center. - [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, - #Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. - [ValidateRange(-90, 90)] - [int]$TextRotation , - #Autofit cells to width (columns or ranges only). - [Alias("AutoFit")] - [Switch]$AutoSize, - #Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. - [float]$Width, - #Set cells to a fixed height (rows or ranges only). - [float]$Height, - #Hide a row or column (not a range); use -Hidden:$false to unhide. - [Switch]$Hidden, - #Locks cells. Cells are locked by default use -locked:$false on the whole sheet and then lock specific ones, and enable protection on the sheet. - [Switch]$Locked, - #Merges cells - it is recommended that you explicitly set -HorizontalAlignment - [Switch]$Merge - ) - process { - if ($Range -is [Array]) { - $null = $PSBoundParameters.Remove("Range") - $Range | Set-ExcelRange @PSBoundParameters - } - else { - #We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ] - if ($Range -is [OfficeOpenXml.Table.ExcelTable]) {$Range = $Range.Address} - elseif ($WorkSheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) { - $Range = $WorkSheet.Cells[$Range] - } - elseif ($Range -is [string]) {Write-Warning -Message "The range pararameter you have specified also needs a worksheet parameter." ;return} - #else we assume $Range is a range. - if ($ClearAll) { - $Range.Clear() - } - if ($ResetFont) { - $Range.Style.Font.Color.SetColor( ([System.Drawing.Color]::Black)) - $Range.Style.Font.Bold = $false - $Range.Style.Font.Italic = $false - $Range.Style.Font.UnderLine = $false - $Range.Style.Font.Strike = $false - $Range.Style.Font.VerticalAlign = [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]::None - } - if ($PSBoundParameters.ContainsKey('Underline')) { - $Range.Style.Font.UnderLine = [boolean]$Underline - $Range.Style.Font.UnderLineType = $UnderLineType - } - if ($PSBoundParameters.ContainsKey('Bold')) { - $Range.Style.Font.Bold = [boolean]$bold - } - if ($PSBoundParameters.ContainsKey('Italic')) { - $Range.Style.Font.Italic = [boolean]$italic - } - if ($PSBoundParameters.ContainsKey('StrikeThru')) { - $Range.Style.Font.Strike = [boolean]$StrikeThru - } - if ($PSBoundParameters.ContainsKey('FontSize')){ - $Range.Style.Font.Size = $FontSize - } - if ($PSBoundParameters.ContainsKey('FontName')){ - $Range.Style.Font.Name = $FontName - } - if ($PSBoundParameters.ContainsKey('FontShift')){ - $Range.Style.Font.VerticalAlign = $FontShift - } - if ($PSBoundParameters.ContainsKey('FontColor')){ - if ($FontColor -is [string]) {$FontColor = [System.Drawing.Color]::$FontColor } - $Range.Style.Font.Color.SetColor( $FontColor) - } - if ($PSBoundParameters.ContainsKey('TextRotation')) { - $Range.Style.TextRotation = $TextRotation - } - if ($PSBoundParameters.ContainsKey('WrapText')) { - $Range.Style.WrapText = [boolean]$WrapText - } - if ($PSBoundParameters.ContainsKey('HorizontalAlignment')) { - $Range.Style.HorizontalAlignment = $HorizontalAlignment - } - if ($PSBoundParameters.ContainsKey('VerticalAlignment')) { - $Range.Style.VerticalAlignment = $VerticalAlignment - } - if ($PSBoundParameters.ContainsKey('Merge')) { - $Range.Merge = [boolean]$Merge - } - if ($PSBoundParameters.ContainsKey('Value')) { - if ($Value -match '^=') {$PSBoundParameters["Formula"] = $Value -replace '^=','' } - else { - $Range.Value = $Value - if ($Value -is [datetime]) { $Range.Style.Numberformat.Format = 'm/d/yy h:mm' }# This is not a custom format, but a preset recognized as date and localized. It might be overwritten in a moment - if ($Value -is [timespan]) { $Range.Style.Numberformat.Format = '[h]:mm:ss' } - } - } - if ($PSBoundParameters.ContainsKey('Formula')) { - if ($ArrayFormula) {$Range.CreateArrayFormula(($Formula -replace '^=','')) } - else {$Range.Formula = ($Formula -replace '^=','') } - } - if ($PSBoundParameters.ContainsKey('NumberFormat')) { - $Range.Style.Numberformat.Format = (Expand-NumberFormat $NumberFormat) - } - if ($BorderColor -is [string]) {$BorderColor = [System.Drawing.Color]::$BorderColor } - if ($PSBoundParameters.ContainsKey('BorderAround')) { - $Range.Style.Border.BorderAround($BorderAround, $BorderColor) - } - if ($PSBoundParameters.ContainsKey('BorderBottom')) { - $Range.Style.Border.Bottom.Style=$BorderBottom - $Range.Style.Border.Bottom.Color.SetColor($BorderColor) - } - if ($PSBoundParameters.ContainsKey('BorderTop')) { - $Range.Style.Border.Top.Style=$BorderTop - $Range.Style.Border.Top.Color.SetColor($BorderColor) - } - if ($PSBoundParameters.ContainsKey('BorderLeft')) { - $Range.Style.Border.Left.Style=$BorderLeft - $Range.Style.Border.Left.Color.SetColor($BorderColor) - } - if ($PSBoundParameters.ContainsKey('BorderRight')) { - $Range.Style.Border.Right.Style=$BorderRight - $Range.Style.Border.Right.Color.SetColor($BorderColor) - } - if ($PSBoundParameters.ContainsKey('BackgroundColor')) { - $Range.Style.Fill.PatternType = $BackgroundPattern - if ($BackgroundColor -is [string]) {$BackgroundColor = [System.Drawing.Color]::$BackgroundColor } - $Range.Style.Fill.BackgroundColor.SetColor($BackgroundColor) - if ($PatternColor) { - if ($PatternColor -is [string]) {$PatternColor = [System.Drawing.Color]::$PatternColor } - $Range.Style.Fill.PatternColor.SetColor( $PatternColor) - } - } - if ($PSBoundParameters.ContainsKey('Height')) { - if ($Range -is [OfficeOpenXml.ExcelRow] ) {$Range.Height = $Height } - elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { - ($Range.Start.Row)..($Range.Start.Row + $Range.Rows) | - ForEach-Object {$Range.WorkSheet.Row($_).Height = $Height } - } - else {Write-Warning -Message ("Can set the height of a row or a range but not a {0} object" -f ($Range.GetType().name)) } - } - if ($Autosize -and -not $env:NoAutoSize) { - try { - if ($Range -is [OfficeOpenXml.ExcelColumn]) {$Range.AutoFit() } - elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { - $Range.AutoFitColumns() - - } - else {Write-Warning -Message ("Can autofit a column or a range but not a {0} object" -f ($Range.GetType().name)) } - } - catch {Write-Warning -Message "Failed autosizing columns of worksheet '$WorksheetName': $_"} - } - elseif ($AutoSize) {Write-Warning -Message "Auto-fitting columns is not available with this OS configuration." } - elseif ($PSBoundParameters.ContainsKey('Width')) { - if ($Range -is [OfficeOpenXml.ExcelColumn]) {$Range.Width = $Width} - elseif ($Range -is [OfficeOpenXml.ExcelRange] ) { - ($Range.Start.Column)..($Range.Start.Column + $Range.Columns - 1) | - ForEach-Object { - #$ws.Column($_).Width = $Width - $Range.Worksheet.Column($_).Width = $Width - } - } - else {Write-Warning -Message ("Can set the width of a column or a range but not a {0} object" -f ($Range.GetType().name)) } - } - if ($PSBoundParameters.ContainsKey('Hidden')) { - if ($Range -is [OfficeOpenXml.ExcelRow] -or - $Range -is [OfficeOpenXml.ExcelColumn] ) {$Range.Hidden = [boolean]$Hidden} - else {Write-Warning -Message ("Can hide a row or a column but not a {0} object" -f ($Range.GetType().name)) } - } - if ($PSBoundParameters.ContainsKey('Locked')) { - $Range.Style.Locked=$Locked - } - } - } -} - -function NumberFormatCompletion { - param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) - $numformats = [ordered]@{ - "General" = "General" # format ID 0 - "Number" = "0.00" # format ID 2 - "Percentage" = "0.00%" # format ID 10 - "Scientific" = "0.00E+00" # format ID 11 - "Fraction" = "# ?/?" # format ID 12 - "Short Date" = "Localized" # format ID 14 - will be translated to "mm-dd-yy" which is localized on load by Excel. - "Short Time" = "Localized" # format ID 20 - will be translated to "h:mm" which is localized on load by Excel. - "Long Time" = "Localized" # format ID 21 - will be translated to "h:mm:ss" which is localized on load by Excel. - "Date-Time" = "Localized" # format ID 22 - will be translated to "m/d/yy h:mm" which is localized on load by Excel. - "Currency" = [cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol + "#,##0.00" - "Text" = "@" # format ID 49 - "h:mm AM/PM" = "h:mm AM/PM" # format ID 18 - "h:mm:ss AM/PM" = "h:mm:ss AM/PM" # format ID 19 - "mm:ss" = "mm:ss" # format ID 45 - "[h]:mm:ss" = "Elapsed hours" # format ID 46 - "mm:ss.0" = "mm:ss.0" # format ID 47 - "d-mmm-yy" = "Localized" # format ID 15 which is localized on load by Excel. - "d-mmm" = "Localized" # format ID 16 which is localized on load by Excel. - "mmm-yy" = "mmm-yy" # format ID 17 which is localized on load by Excel. - "0" = "Whole number" # format ID 1 - "0.00" = "Number, 2 decimals" # format ID 2 or "number" - "#,##0" = "Thousand separators" # format ID 3 - "#,##0.00" = "Thousand separators and 2 decimals" # format ID 4 - "#," = "Whole thousands" - "#.0,," = "Millions, 1 Decimal" - "0%" = "Nearest whole percentage" # format ID 9 - "0.00%" = "Percentage with decimals" # format ID 10 or "Percentage" - "00E+00" = "Scientific" # format ID 11 or "Scientific" - "# ?/?" = "One Digit fraction" # format ID 12 or "Fraction" - "# ??/??" = "Two Digit fraction" # format ID 13 - "@" = "Text" # format ID 49 or "Text" - } - $numformats.keys.where({$_ -like "$wordToComplete*"} ) | ForEach-Object { - New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'" , $_ , - ([System.Management.Automation.CompletionResultType]::ParameterValue) , $numformats[$_] - } -} -if (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { - Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Export-Excel -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName NumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Add-PivotTable -ParameterName PivotNumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName New-PivotTableDefinition -ParameterName PivotNumberFormat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName New-ExcelChartDefinition -ParameterName XAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName New-ExcelChartDefinition -ParameterName YAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Add-ExcelChart -ParameterName XAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion - Register-ArgumentCompleter -CommandName Add-ExcelChart -ParameterName YAxisNumberformat -ScriptBlock $Function:NumberFormatCompletion -} - -function ListFonts { - param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) - if (-not $script:FontFamilies) { - $script:FontFamilies = @("","") - try { - $script:FontFamilies = (New-Object System.Drawing.Text.InstalledFontCollection).Families.Name - } - catch {} - } - $script:FontFamilies.where({$_ -Gt "" -and $_ -like "$wordToComplete*"} ) | ForEach-Object { - New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList "'$_'" , $_ , - ([System.Management.Automation.CompletionResultType]::ParameterValue) , $_ - } -} -if (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { - Register-ArgumentCompleter -CommandName New-ExcelStyle -ParameterName FontName -ScriptBlock $Function:ListFonts - Register-ArgumentCompleter -CommandName Set-ExcelColumn -ParameterName FontName -ScriptBlock $Function:ListFonts - Register-ArgumentCompleter -CommandName Set-ExcelRange -ParameterName FontName -ScriptBlock $Function:ListFonts - Register-ArgumentCompleter -CommandName Set-ExcelRow -ParameterName FontName -ScriptBlock $Function:ListFonts -} - -function Expand-NumberFormat { - <# - .SYNOPSIS - Converts short names for number formats to the formatting strings used in Excel - .DESCRIPTION - Where you can type a number format you can write, for example, 'Short-Date' - and the module will translate it into the format string used by Excel. - Some formats, like Short-Date change how they are presented when Excel - loads (so date will use the local ordering of year, month and Day). Other - formats change how they appear when loaded with different cultures - (depending on the country "," or "." or " " may be the thousand seperator - although Excel always stores it as ",") - .EXAMPLE - Expand-NumberFormat percentage - - Returns "0.00%" - .EXAMPLE - Expand-NumberFormat Currency - - Returns the currency format specified in the local regional settings. This - may not be the same as Excel uses. The regional settings set the currency - symbol and then whether it is before or after the number and separated with - a space or not; for negative numbers the number may be wrapped in parentheses - or a - sign might appear before or after the number and symbol. - So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00- - for French. (Note some Eurozone countries write €1,23 and others 1,23€ ) - In French the decimal point will be rendered as a "," and the thousand - separator as a space. - #> - [cmdletbinding()] - [OutputType([String])] - param ( - #the format string to Expand - $NumberFormat - ) - switch ($NumberFormat) { - "Currency" { - #https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern(v=vs.110).aspx - $sign = [cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol - switch ([cultureinfo]::CurrentCulture.NumberFormat.CurrencyPositivePattern) { - 0 {$pos = "$Sign#,##0.00" ; break } - 1 {$pos = "#,##0.00$Sign" ; break } - 2 {$pos = "$Sign #,##0.00" ; break } - 3 {$pos = "#,##0.00 $Sign" ; break } - } - switch ([cultureinfo]::CurrentCulture.NumberFormat.CurrencyPositivePattern) { - 0 {return "$pos;($Sign#,##0.00)" } - 1 {return "$pos;-$Sign#,##0.00" } - 2 {return "$pos;$Sign-#,##0.00" } - 3 {return "$pos;$Sign#,##0.00-" } - 4 {return "$pos;(#,##0.00$Sign)" } - 5 {return "$pos;-#,##0.00$Sign" } - 6 {return "$pos;#,##0.00-$Sign" } - 7 {return "$pos;#,##0.00$Sign-" } - 8 {return "$pos;-#,##0.00 $Sign" } - 9 {return "$pos;-$Sign #,##0.00" } - 10 {return "$pos;#,##0.00 $Sign-" } - 11 {return "$pos;$Sign #,##0.00-" } - 12 {return "$pos;$Sign -#,##0.00" } - 13 {return "$pos;#,##0.00- $Sign" } - 14 {return "$pos;($Sign #,##0.00)" } - 15 {return "$pos;(#,##0.00 $Sign)" } - } - } - "Number" {return "0.00" } # format id 2 - "Percentage" {return "0.00%" } # format id 10 - "Scientific" {return "0.00E+00" } # format id 11 - "Fraction" {return "# ?/?" } # format id 12 - "Short Date" {return "mm-dd-yy" } # format id 14 localized on load by Excel. - "Short Time" {return "h:mm" } # format id 20 localized on load by Excel. - "Long Time" {return "h:mm:ss" } # format id 21 localized on load by Excel. - "Date-Time" {return "m/d/yy h:mm"} # format id 22 localized on load by Excel. - "Text" {return "@" } # format ID 49 - Default {return $NumberFormat} - } -} - -function New-ExcelStyle { - param ( - [Alias("Address")] - $Range , - #Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. - [Alias("NFormat")] - $NumberFormat, - #Style of border to draw around the range. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround, - #Color of the border. - $BorderColor=[System.Drawing.Color]::Black, - #Style for the bottom border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderBottom, - #Style for the top border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderTop, - #Style for the left border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderLeft, - #Style for the right border. - [OfficeOpenXml.Style.ExcelBorderStyle]$BorderRight, - #Colour for the text - if none is specified it will be left as it is. - [Alias('ForegroundColor')] - $FontColor, - #Value for the cell. - $Value, - #Formula for the cell. - $Formula, - #Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). - [Switch]$ArrayFormula, - #Clear Bold, Italic, StrikeThrough and Underline and set color to Black. - [Switch]$ResetFont, - #Make text bold; use -Bold:$false to remove bold. - [Switch]$Bold, - #Make text italic; use -Italic:$false to remove italic. - [Switch]$Italic, - #Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. - [Switch]$Underline, - #Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". - [OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single, - #Strike through text; use -Strikethru:$false to remove Strike through - [Switch]$StrikeThru, - #Subscript or Superscript (or none). - [OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift, - #Font to use - Excel defaults to Calibri. - [String]$FontName, - #Point size for the text. - [float]$FontSize, - #Change background color. - $BackgroundColor, - #Background pattern - Solid by default. - [OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid , - #Secondary color for background pattern. - [Alias("PatternColour")] - $PatternColor, - #Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. - [Switch]$WrapText, - #Position cell contents to Left, Right, Center etc. default is 'General'. - [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, - #Position cell contents to Top, Bottom or Center. - [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, - #Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. - [ValidateRange(-90, 90)] - [int]$TextRotation , - #Autofit cells to width (columns or ranges only). - [Alias("AutoFit")] - [Switch]$AutoSize, - #Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. - [float]$Width, - #Set cells to a fixed height (rows or ranges only). - [float]$Height, - #Hide a row or column (not a range); use -Hidden:$false to unhide. - [Switch]$Hidden, - #Locks cells. Cells are locked by default use -locked:$false on the whole sheet and then lock specific ones, and enable protection on the sheet. - [Switch]$Locked, - [Switch]$Merge - ) - $PSBoundParameters -} \ No newline at end of file diff --git a/Update-FirstObjectProperties.ps1 b/Update-FirstObjectProperties.ps1 deleted file mode 100644 index b053337..0000000 --- a/Update-FirstObjectProperties.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Update*', Justification='Does not change system state')] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Scope='Function', Target='Update*', Justification='Property would be incorrect')] - -param() - -Function Update-FirstObjectProperties { - <# - .SYNOPSIS - Updates the first object to contain all the properties of the object with the most properties in the array. - - .DESCRIPTION - Updates the first object to contain all the properties of the object with the most properties in the array. This is usefull when not all objects have the same quantity of properties and CmdLets like Out-GridView or Export-Excel are not able to show all the properties because the first object doesn't have them all. - - .EXAMPLE - $Array = @() - - $Obj1 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - } - - $Obj2 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - } - - $Obj3 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - Member4 = 'Fourth' - } - - $Array = $Obj1, $Obj2, $Obj3 - $Array | Out-GridView -Title 'Not showing Member3 and Member4' - $Array | Update-FirstObjectProperties | Out-GridView -Title 'All properties are visible' - - Updates the fist object of the array by adding Member3 and Member4. - - .EXAMPLE - $ExcelParams = @{ - Path = $env:TEMP + '\Excel.xlsx' - Show = $true - Verbose = $true - } - Remove-Item -Path $ExcelParams.Path -Force -EA Ignore - - $Array = @() - - $Obj1 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - } - - $Obj2 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - } - - $Obj3 = [PSCustomObject]@{ - Member1 = 'First' - Member2 = 'Second' - Member3 = 'Third' - Member4 = 'Fourth' - } - - $Array = $Obj1, $Obj2, $Obj3 - $Array | Out-GridView -Title 'Not showing Member3 and Member4' - $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorkSheetname Numbers - - Updates the first object of the array by adding property 'Member3' and 'Member4'. Afterwards. all objects are exported to an Excel file and all column headers are visible. - - .LINK - https://github.com/dfinke/ImportExcel - - .NOTES - CHANGELOG - 2017/06/08 Function born - #> - - Try { - $Union = @() - $Input | ForEach-Object { - If ($Union.Count) { - $_ | Get-Member | Where-Object {-not ($Union[0] | Get-Member $_.Name)} | ForEach-Object { - $Union[0] | Add-Member -MemberType NoteProperty -Name $_.Name -Value $Null - } - } - $Union += $_ - } - $Union - } - Catch { - throw "Failed updating the properties of the first object: $_" - } -} \ No newline at end of file diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index 962a08e..d85d67c 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -21,18 +21,6 @@ Sebastian Vettel,/wiki/Sebastian_Vettel,1987-07-03 Describe "Number format expansion and setting" { - Context "Argmument Completer for NumberFormat" { - it "Returned at least 20 items " { - (NumberFormatCompletion ).count | Should beGreaterThan 20 - } - It "Resolved percent to 'percentage' " { - $x = (NumberFormatCompletion -wordToComplete Percent) - $x.count | Should be 1 - $x.CompletionText | Should match "^'.*'$" - $x.ToolTip | Should be "0.00%" - $x.ListItemText | Should be "Percentage" - } - } Context "Expand-NumberFormat function" { It "Expanded named number formats as expected " { $r = [regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol) diff --git a/en-US/ImportExcel-help.xml b/en-US/ImportExcel-help.xml new file mode 100644 index 0000000..a7eb2b6 --- /dev/null +++ b/en-US/ImportExcel-help.xml @@ -0,0 +1,23342 @@ + + + + + Add-ConditionalFormatting + Add + ConditionalFormatting + + Adds conditional formatting to all or part of a worksheet. + + + + Conditional formatting allows Excel to: + * Mark cells with icons depending on their value + * Show a databar whose length indicates the value or a two or three color scale where the color indicates the relative value + * Change the color, font, or number format of cells which meet given criteria + Add-ConditionalFormatting allows these parameters to be set; for fine tuning of the rules, the -PassThru switch will return the rule so that you can modify things which are specific to that type of rule, example, the values which correspond to each icon in an Icon-Set. + + + + Add-ConditionalFormatting + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + RuleType + + A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc. + + + AboveAverage + AboveOrEqualAverage + BelowAverage + BelowOrEqualAverage + AboveStdDev + BelowStdDev + Bottom + BottomPercent + Top + TopPercent + Last7Days + LastMonth + LastWeek + NextMonth + NextWeek + ThisMonth + ThisWeek + Today + Tomorrow + Yesterday + BeginsWith + Between + ContainsBlanks + ContainsErrors + ContainsText + DuplicateValues + EndsWith + Equal + Expression + GreaterThan + GreaterThanOrEqual + LessThan + LessThanOrEqual + NotBetween + NotContains + NotContainsBlanks + NotContainsErrors + NotContainsText + NotEqual + UniqueValues + ThreeColorScale + TwoColorScale + ThreeIconSet + FourIconSet + FiveIconSet + DataBar + + eExcelConditionalFormattingRuleType + + eExcelConditionalFormattingRuleType + + + None + + + ConditionValue + + A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" ) + + Object + + Object + + + None + + + ConditionValue2 + + A second value for the conditions like "Between X and Y" + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + ForegroundColor + + Text color for matching objects + + Object + + Object + + + None + + + Reverse + + Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + + + SwitchParameter + + + False + + + BackgroundColor + + Background color for matching items + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern for matching items + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + None + + + PatternColor + + Secondary color when a background pattern requires it + + Object + + Object + + + None + + + NumberFormat + + Sets the numeric format for matching items + + Object + + Object + + + None + + + Bold + + Put matching items in bold face + + + SwitchParameter + + + False + + + Italic + + Put matching items in italic + + + SwitchParameter + + + False + + + Underline + + Underline matching items + + + SwitchParameter + + + False + + + StrikeThru + + Strikethrough text of matching items + + + SwitchParameter + + + False + + + StopIfTrue + + Prevent the processing of subsequent rules + + + SwitchParameter + + + False + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + + SwitchParameter + + + False + + + + Add-ConditionalFormatting + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + DataBarColor + + Color for databar type charts + + Object + + Object + + + None + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + + SwitchParameter + + + False + + + + Add-ConditionalFormatting + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + ThreeIconsSet + + One of the three-icon set types (e.g. Traffic Lights) + + + Arrows + ArrowsGray + Flags + Signs + Symbols + Symbols2 + TrafficLights1 + TrafficLights2 + + eExcelconditionalFormatting3IconsSetType + + eExcelconditionalFormatting3IconsSetType + + + None + + + Reverse + + Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + + + SwitchParameter + + + False + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + + SwitchParameter + + + False + + + + Add-ConditionalFormatting + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + FourIconsSet + + A four-icon set name + + + Arrows + ArrowsGray + Rating + RedToBlack + TrafficLights + + eExcelconditionalFormatting4IconsSetType + + eExcelconditionalFormatting4IconsSetType + + + None + + + Reverse + + Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + + + SwitchParameter + + + False + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + + SwitchParameter + + + False + + + + Add-ConditionalFormatting + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + FiveIconsSet + + A five-icon set name + + + Arrows + ArrowsGray + Quarters + Rating + + eExcelconditionalFormatting5IconsSetType + + eExcelconditionalFormatting5IconsSetType + + + None + + + Reverse + + Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + + + SwitchParameter + + + False + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + + SwitchParameter + + + False + + + + + + Address + + A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied + + ExcelWorksheet + + ExcelWorksheet + + + None + + + RuleType + + A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc. + + eExcelConditionalFormattingRuleType + + eExcelConditionalFormattingRuleType + + + None + + + ForegroundColor + + Text color for matching objects + + Object + + Object + + + None + + + DataBarColor + + Color for databar type charts + + Object + + Object + + + None + + + ThreeIconsSet + + One of the three-icon set types (e.g. Traffic Lights) + + eExcelconditionalFormatting3IconsSetType + + eExcelconditionalFormatting3IconsSetType + + + None + + + FourIconsSet + + A four-icon set name + + eExcelconditionalFormatting4IconsSetType + + eExcelconditionalFormatting4IconsSetType + + + None + + + FiveIconsSet + + A five-icon set name + + eExcelconditionalFormatting5IconsSetType + + eExcelconditionalFormatting5IconsSetType + + + None + + + Reverse + + Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + + SwitchParameter + + SwitchParameter + + + False + + + ConditionValue + + A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" ) + + Object + + Object + + + None + + + ConditionValue2 + + A second value for the conditions like "Between X and Y" + + Object + + Object + + + None + + + BackgroundColor + + Background color for matching items + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern for matching items + + ExcelFillStyle + + ExcelFillStyle + + + None + + + PatternColor + + Secondary color when a background pattern requires it + + Object + + Object + + + None + + + NumberFormat + + Sets the numeric format for matching items + + Object + + Object + + + None + + + Bold + + Put matching items in bold face + + SwitchParameter + + SwitchParameter + + + False + + + Italic + + Put matching items in italic + + SwitchParameter + + SwitchParameter + + + False + + + Underline + + Underline matching items + + SwitchParameter + + SwitchParameter + + + False + + + StrikeThru + + Strikethrough text of matching items + + SwitchParameter + + SwitchParameter + + + False + + + StopIfTrue + + Prevent the processing of subsequent rules + + SwitchParameter + + SwitchParameter + + + False + + + Priority + + Set the sequence for rule processing + + Int32 + + Int32 + + + 0 + + + PassThru + + If specified pass the rule back to the caller to allow additional customization. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru + Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "b2:b1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "2003" + Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "i2:i1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "Disabled" + $excel.Workbook.Worksheets[1].Cells["D1:G1048576"].Style.Numberformat.Format = [cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern + $excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true + $excel.Save() ; $excel.Dispose() + + Here Export-Excel is called with the -PassThru parameter, so the ExcelPackage object representing Machines.XLSX is stored in $Excel.The desired worksheet is selected, and then columns" B" and "I" are conditionally formatted (excluding the top row) to show red text if they contain "2003" or "Disabled" respectively. + A fixed date format is then applied to columns D to G, and the top row is formatted. + Finally the workbook is saved and the Excel package object is closed. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $r = Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Range "B1:B100" -ThreeIconsSet Flags -Passthru + $r.Reverse = $true ; $r.Icon1.Type = "Num"; $r.Icon2.Type = "Num" ; $r.Icon2.value = 100 ; $r.Icon3.type = "Num" ;$r.Icon3.value = 1000 + + Again Export-Excel has been called with -PassThru leaving a package object in $Excel. + This time B1:B100 has been conditionally formatted with 3 icons, using the "Flags" Icon-Set. + Add-ConditionalFormatting does not provide accessto every option in the formatting rule, so -PassThru has been used and the rule is modified to apply the flags in reverse order, and transitions between flags are set to 100 and 1000. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red + + This time $sheet holds an ExcelWorkshseet object and databars are added to column D, excluding the top row. + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue + + In this example a named range is used to select the cells where the condition should apply, and instead of specifying a sheet and range within the sheet as separate parameters, the cells where the format should apply are specified directly. + If a cell in the "FinishPosition" range is 1, then the text is turned to Bold & Purple. + This rule is moved to first in the priority list, and where cells have a value of 1, no other rules will be processed. + + + + -------------------------- EXAMPLE 5 -------------------------- + PS\> $excel = Get-ChildItem | Select-Object -Property Name,Length,LastWriteTime,CreationTime | Export-Excel "$env:temp\test43.xlsx" -PassThru -AutoSize + $ws = $excel.Workbook.Worksheets["Sheet1"] + $ws.Cells["E1"].Value = "SavedAt" + $ws.Cells["F1"].Value = [datetime]::Now + $ws.Cells["F1"].Style.Numberformat.Format = (Expand-NumberFormat -NumberFormat 'Date-Time') + $lastRow = $ws.Dimension.End.Row + Add-ConditionalFormatting -WorkSheet $ws -address "A2:A$Lastrow" -RuleType LessThan -ConditionValue "A" -ForeGroundColor Gray + Add-ConditionalFormatting -WorkSheet $ws -address "B2:B$Lastrow" -RuleType GreaterThan -ConditionValue 1000000 -NumberFormat '#,###,,.00"M"' + Add-ConditionalFormatting -WorkSheet $ws -address "C2:C$Lastrow" -RuleType GreaterThan -ConditionValue "=INT($F$1-7)" -ForeGroundColor Green -StopIfTrue + Add-ConditionalFormatting -WorkSheet $ws -address "D2:D$Lastrow" -RuleType Equal -ConditionValue "=C2" -ForeGroundColor Blue -StopIfTrue + Close-ExcelPackage -Show $excel + + The first few lines of code export a list of file and directory names, sizes and dates to a spreadsheet. + It puts the date of the export in cell F1. + The first Conditional format changes the color of files and folders that begin with a ".", "_" or anything else which sorts before "A". + The second Conditional format changes the Number format of numbers bigger than 1 million, for example 1,234,567,890 will dispay as "1,234.57M" + The third highlights datestamps of files less than a week old when the export was run; the = is necessary in the condition value otherwise the rule will look for the the text INT($F$1-7), and the cell address for the date is fixed using the standard Excel $ notation. + The final Conditional format looks for files which have not changed since they were created. Here the condition value is "=C2". The = sign means C2 is treated as a formula, not literal text. Unlike the file age, we want the cell used to change for each cell where the conditional format applies. + The first cell in the conditional format range is D2, which is compared against C2, then D3 is compared against C3 and so on. A common mistake is to include the title row in the range and accidentally apply conditional formatting to it, or to begin the range at row 2 but use row 1 as the starting point for comparisons. + + + + -------------------------- EXAMPLE 6 -------------------------- + PS\> Add-ConditionalFormatting $ws.Cells["B:B"] GreaterThan 10000000 -Fore Red -Stop -Pri 1 + + This version shows the shortest syntax - the Address, Ruletype, and Conditionvalue can be identified from their position, and ForegroundColor, StopIfTrue and Priority can all be shortend. + + + + + + + + Add-ExcelChart + Add + ExcelChart + + Creates a chart in an existing Excel worksheet. + + + + Creates a chart. + It is possible to configure the type of chart, the range of X values (labels) and Y values, the title, the legend, the ranges for both axes, the format and position of the axes. + Normally the command does not return anything, but if -passthru is specified the chart is returned so that it can be customized. + + + + Add-ExcelChart + + Worksheet + + An existing Sheet where the chart will be created. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + Title + + The title for the chart. + + String + + String + + + None + + + ChartType + + One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + ColumnStacked + + + ChartTrendLine + + {{ Fill ChartTrendLine Description }} + + + Exponential + Linear + Logarithmic + MovingAvgerage + Polynomial + Power + + eTrendLine[] + + eTrendLine[] + + + None + + + XRange + + The range of cells containing values for the X-Axis - usually labels. + + Object + + Object + + + None + + + YRange + + The range(s) of cells holding values for the Y-Axis - usually "data". + + Object + + Object + + + None + + + Width + + Width of the chart in Pixels; defaults to 500. + + Int32 + + Int32 + + + 500 + + + Height + + Height of the chart in Pixels; defaults to 350. + + Int32 + + Int32 + + + 350 + + + Row + + Row position of the top left corner of the chart. ) places at the top of the sheet, 1 below row 1 and so on. + + Int32 + + Int32 + + + 0 + + + RowOffSetPixels + + Offset to position the chart by a fraction of a row. + + Int32 + + Int32 + + + 10 + + + Column + + Column position of the top left corner of the chart; 0 places at the edge of the sheet 1 to the right of column A and so on. + + Int32 + + Int32 + + + 6 + + + ColumnOffSetPixels + + Offset to position the chart by a fraction of a column. + + Int32 + + Int32 + + + 5 + + + LegendPosition + + Location of the key, either left, right, top, bottom or TopRight. + + + Top + Left + Right + Bottom + TopRight + + eLegendPosition + + eLegendPosition + + + None + + + LegendSize + + Font size for the key. + + Object + + Object + + + None + + + LegendBold + + Sets the key in bold type. + + + SwitchParameter + + + False + + + NoLegend + + If specified, turns of display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + + + SwitchParameter + + + False + + + ShowCategory + + Attaches a category label, in charts which support this. + + + SwitchParameter + + + False + + + ShowPercent + + Attaches a percentage label, in charts which support this. + + + SwitchParameter + + + False + + + SeriesHeader + + Specify explicit name(s) for the data series, which will appear in the legend/key. The contents of a cell can be specified in the from =Sheet9!Z10 . + + String[] + + String[] + + + None + + + TitleBold + + Sets the title in bold face. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 0 + + + XAxisTitleText + + Specifies a title for the X-axis. + + String + + String + + + None + + + XAxisTitleBold + + Sets the X-axis title in bold face. + + + SwitchParameter + + + False + + + XAxisTitleSize + + Sets the font size for the axis title. + + Object + + Object + + + None + + + XAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers along the X-axis. + + String + + String + + + None + + + XMajorUnit + + Spacing for the major gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMinorUnit + + Spacing for the minor gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMaxValue + + Maximum value for the scale along the X-axis. + + Object + + Object + + + None + + + XMinValue + + Minimum value for the scale along the X-axis. + + Object + + Object + + + None + + + XAxisPosition + + Position for the X-axis (Top or Bottom). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + YAxisTitleText + + Specifies a title for the Y-axis. + + String + + String + + + None + + + YAxisTitleBold + + Sets the Y-axis title in bold face. + + + SwitchParameter + + + False + + + YAxisTitleSize + + Sets the font size for the Y-axis title + + Object + + Object + + + None + + + YAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers on the Y-axis. + + String + + String + + + None + + + YMajorUnit + + Spacing for the major gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMinorUnit + + Spacing for the minor gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMaxValue + + Maximum value on the Y-axis. + + Object + + Object + + + None + + + YMinValue + + Minimum value on the Y-axis. + + Object + + Object + + + None + + + YAxisPosition + + Position for the Y-axis (Left or Right). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + PassThru + + Add-Excel chart doesn't normally return anything, but if -PassThru is specified it returns the newly created chart to allow it to be fine tuned. + + + SwitchParameter + + + False + + + + Add-ExcelChart + + PivotTable + + Instead of specify X and Y ranges, get data from a PivotTable by passing a PivotTable Object. + + ExcelPivotTable + + ExcelPivotTable + + + None + + + Title + + The title for the chart. + + String + + String + + + None + + + ChartType + + One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + ColumnStacked + + + ChartTrendLine + + {{ Fill ChartTrendLine Description }} + + + Exponential + Linear + Logarithmic + MovingAvgerage + Polynomial + Power + + eTrendLine[] + + eTrendLine[] + + + None + + + XRange + + The range of cells containing values for the X-Axis - usually labels. + + Object + + Object + + + None + + + YRange + + The range(s) of cells holding values for the Y-Axis - usually "data". + + Object + + Object + + + None + + + Width + + Width of the chart in Pixels; defaults to 500. + + Int32 + + Int32 + + + 500 + + + Height + + Height of the chart in Pixels; defaults to 350. + + Int32 + + Int32 + + + 350 + + + Row + + Row position of the top left corner of the chart. ) places at the top of the sheet, 1 below row 1 and so on. + + Int32 + + Int32 + + + 0 + + + RowOffSetPixels + + Offset to position the chart by a fraction of a row. + + Int32 + + Int32 + + + 10 + + + Column + + Column position of the top left corner of the chart; 0 places at the edge of the sheet 1 to the right of column A and so on. + + Int32 + + Int32 + + + 6 + + + ColumnOffSetPixels + + Offset to position the chart by a fraction of a column. + + Int32 + + Int32 + + + 5 + + + LegendPosition + + Location of the key, either left, right, top, bottom or TopRight. + + + Top + Left + Right + Bottom + TopRight + + eLegendPosition + + eLegendPosition + + + None + + + LegendSize + + Font size for the key. + + Object + + Object + + + None + + + LegendBold + + Sets the key in bold type. + + + SwitchParameter + + + False + + + NoLegend + + If specified, turns of display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + + + SwitchParameter + + + False + + + ShowCategory + + Attaches a category label, in charts which support this. + + + SwitchParameter + + + False + + + ShowPercent + + Attaches a percentage label, in charts which support this. + + + SwitchParameter + + + False + + + SeriesHeader + + Specify explicit name(s) for the data series, which will appear in the legend/key. The contents of a cell can be specified in the from =Sheet9!Z10 . + + String[] + + String[] + + + None + + + TitleBold + + Sets the title in bold face. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 0 + + + XAxisTitleText + + Specifies a title for the X-axis. + + String + + String + + + None + + + XAxisTitleBold + + Sets the X-axis title in bold face. + + + SwitchParameter + + + False + + + XAxisTitleSize + + Sets the font size for the axis title. + + Object + + Object + + + None + + + XAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers along the X-axis. + + String + + String + + + None + + + XMajorUnit + + Spacing for the major gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMinorUnit + + Spacing for the minor gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMaxValue + + Maximum value for the scale along the X-axis. + + Object + + Object + + + None + + + XMinValue + + Minimum value for the scale along the X-axis. + + Object + + Object + + + None + + + XAxisPosition + + Position for the X-axis (Top or Bottom). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + YAxisTitleText + + Specifies a title for the Y-axis. + + String + + String + + + None + + + YAxisTitleBold + + Sets the Y-axis title in bold face. + + + SwitchParameter + + + False + + + YAxisTitleSize + + Sets the font size for the Y-axis title + + Object + + Object + + + None + + + YAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers on the Y-axis. + + String + + String + + + None + + + YMajorUnit + + Spacing for the major gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMinorUnit + + Spacing for the minor gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMaxValue + + Maximum value on the Y-axis. + + Object + + Object + + + None + + + YMinValue + + Minimum value on the Y-axis. + + Object + + Object + + + None + + + YAxisPosition + + Position for the Y-axis (Left or Right). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + PassThru + + Add-Excel chart doesn't normally return anything, but if -PassThru is specified it returns the newly created chart to allow it to be fine tuned. + + + SwitchParameter + + + False + + + + + + Worksheet + + An existing Sheet where the chart will be created. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + PivotTable + + Instead of specify X and Y ranges, get data from a PivotTable by passing a PivotTable Object. + + ExcelPivotTable + + ExcelPivotTable + + + None + + + Title + + The title for the chart. + + String + + String + + + None + + + ChartType + + One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + + eChartType + + eChartType + + + ColumnStacked + + + ChartTrendLine + + {{ Fill ChartTrendLine Description }} + + eTrendLine[] + + eTrendLine[] + + + None + + + XRange + + The range of cells containing values for the X-Axis - usually labels. + + Object + + Object + + + None + + + YRange + + The range(s) of cells holding values for the Y-Axis - usually "data". + + Object + + Object + + + None + + + Width + + Width of the chart in Pixels; defaults to 500. + + Int32 + + Int32 + + + 500 + + + Height + + Height of the chart in Pixels; defaults to 350. + + Int32 + + Int32 + + + 350 + + + Row + + Row position of the top left corner of the chart. ) places at the top of the sheet, 1 below row 1 and so on. + + Int32 + + Int32 + + + 0 + + + RowOffSetPixels + + Offset to position the chart by a fraction of a row. + + Int32 + + Int32 + + + 10 + + + Column + + Column position of the top left corner of the chart; 0 places at the edge of the sheet 1 to the right of column A and so on. + + Int32 + + Int32 + + + 6 + + + ColumnOffSetPixels + + Offset to position the chart by a fraction of a column. + + Int32 + + Int32 + + + 5 + + + LegendPosition + + Location of the key, either left, right, top, bottom or TopRight. + + eLegendPosition + + eLegendPosition + + + None + + + LegendSize + + Font size for the key. + + Object + + Object + + + None + + + LegendBold + + Sets the key in bold type. + + SwitchParameter + + SwitchParameter + + + False + + + NoLegend + + If specified, turns of display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + + SwitchParameter + + SwitchParameter + + + False + + + ShowCategory + + Attaches a category label, in charts which support this. + + SwitchParameter + + SwitchParameter + + + False + + + ShowPercent + + Attaches a percentage label, in charts which support this. + + SwitchParameter + + SwitchParameter + + + False + + + SeriesHeader + + Specify explicit name(s) for the data series, which will appear in the legend/key. The contents of a cell can be specified in the from =Sheet9!Z10 . + + String[] + + String[] + + + None + + + TitleBold + + Sets the title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 0 + + + XAxisTitleText + + Specifies a title for the X-axis. + + String + + String + + + None + + + XAxisTitleBold + + Sets the X-axis title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + XAxisTitleSize + + Sets the font size for the axis title. + + Object + + Object + + + None + + + XAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers along the X-axis. + + String + + String + + + None + + + XMajorUnit + + Spacing for the major gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMinorUnit + + Spacing for the minor gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMaxValue + + Maximum value for the scale along the X-axis. + + Object + + Object + + + None + + + XMinValue + + Minimum value for the scale along the X-axis. + + Object + + Object + + + None + + + XAxisPosition + + Position for the X-axis (Top or Bottom). + + eAxisPosition + + eAxisPosition + + + None + + + YAxisTitleText + + Specifies a title for the Y-axis. + + String + + String + + + None + + + YAxisTitleBold + + Sets the Y-axis title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + YAxisTitleSize + + Sets the font size for the Y-axis title + + Object + + Object + + + None + + + YAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers on the Y-axis. + + String + + String + + + None + + + YMajorUnit + + Spacing for the major gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMinorUnit + + Spacing for the minor gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMaxValue + + Maximum value on the Y-axis. + + Object + + Object + + + None + + + YMinValue + + Minimum value on the Y-axis. + + Object + + Object + + + None + + + YAxisPosition + + Position for the Y-axis (Left or Right). + + eAxisPosition + + eAxisPosition + + + None + + + PassThru + + Add-Excel chart doesn't normally return anything, but if -PassThru is specified it returns the newly created chart to allow it to be fine tuned. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.Drawing.Chart.ExcelChart + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $Excel = ConvertFrom-Csv @" + Product, City, Sales + Apple, London, 300 + Orange, London, 400 + Banana, London, 300 + Orange, Paris, 600 + Banana, Paris, 300 + Apple, New York, 1200 +"@ | Export-Excel -Path test.xlsx -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -ChartType "Doughnut" -XRange "A2:B7" -YRange "C2:C7" -width 500 + Close-ExcelPackage -Show $Excel + + The first command expands a multi-line string into 6 rows of data which is exported to new Excel file; leaving an ExcelPackage object in $excel The second command adds a chart - the cell ranges are explicitly specified. + Note that the XRange (labels) is TWO columns wide and the chart will combine the name of the product and the name of the City to create the label. + The width of the chart is set explictly, the default legend is used and there is no Chart title. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel $path -AutoSize -ExcelChartDefinition $c -AutoNameRange -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title "VM use" -ChartType PieExploded3D -XRange "Name" -YRange "VirtualMemorySize" -NoLegend -ShowCategory + Close-ExcelPackage $Excel -Show + + The first line exports information and creates named ranges for each column. + The Second line uses the ranges to specify a chart - the labels come from the range "Name" and the data from the range "VirtualMemorySize" + The chart is specified as a 3D exploded PIE chart, with a title of "VM Use" and instead of a legend the the pie slices are identified with a label. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel test.xlsx -TableName Processes -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title Stats -ChartType LineMarkersStacked -XRange "Processes[Name]" -YRange "Processes[PM]", "Processes[VirtualMemorySize]" -SeriesHeader 'PM', 'VMSize' + Close-ExcelPackage $Excel -Show + + The first line exports information to a table in new file; and captures the excel Package object in $Excel + The second line creates a chart on the first page of the work sheet, using the notation "TableName[ColumnnName]" to refer to the data, the labels come Name column in the table, and the data series from its PM and VirtualMemorySize columns. The display names for these in the header are set to 'PM' and 'VMSize'. + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path Text.xlsx -WorkSheetname SinX -PassThru +Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 \` + -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" \` + -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 \` + -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom +Close-ExcelPackage $Excel -Show + + The first line puts numbers from 0 to 360 into a sheet, as the first column, and a formula to calculate the Sine of that number of number of degrees in the second column. It creates named-ranges for the two columns - "X" and "SinX" respectively + The Add-ExcelChart command adds a chart to that worksheet, specifying a line chart with the X values coming from named-range "X" and the Y values coming from named-range "SinX". The chart has a title, and is positioned to the right of column 2 and sized 800 pixels wide + The X-axis is labelled "Degrees", in bold 12 point type and runs from 0 to 361 with labels every 30, and minor tick marks every 10. Degrees are shown padded to 3 digits. + The Y-axis is labelled "Sine" and to allow some room above and below its scale runs from -1.25 to 1.25, and is marked off in units of 0.25 shown to two decimal places. + The key will for the chart will be at the bottom in 8 point bold type and the line will be named "Sin(x)". + + + + + + + + Add-ExcelDataValidationRule + Add + ExcelDataValidationRule + + Adds data validation to a range of cells + + + + Excel supports the validation of user input, and ranges of cells can be marked to only contain numbers, or date, or Text up to a particular length, or selections from a list. This command adds validation rules to a worksheet. + + + + Add-ExcelDataValidationRule + + Range + + The range of cells to be validate, for example, "B2:C100" + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the cells should be validated + + ExcelWorksheet + + ExcelWorksheet + + + None + + + ValidationType + + An option corresponding to a choice from the 'Allow' pull down on the settings page in the Excel dialog. "Any" means "any allowed" - in other words, no Validation + + Object + + Object + + + None + + + Operator + + The operator to apply to Decimal, Integer, TextLength, DateTime and time fields, for example "equal" or "between" + + + between + notBetween + equal + notEqual + lessThan + lessThanOrEqual + greaterThan + greaterThanOrEqual + + ExcelDataValidationOperator + + ExcelDataValidationOperator + + + Equal + + + Value + + For Decimal, Integer, TextLength, DateTime the [first] data value + + Object + + Object + + + None + + + Value2 + + When using the between operator, the second data value + + Object + + Object + + + None + + + Formula + + The [first] data value as a formula. Use absolute formulas $A$1 if (e.g.) you want all cells to check against the same list + + Object + + Object + + + None + + + Formula2 + + When using the between operator, the second data value as a formula + + Object + + Object + + + None + + + ValueSet + + When using the list validation type, a set of values (rather than refering to Sheet!B$2:B$100 ) + + Object + + Object + + + None + + + ShowErrorMessage + + Corresponds to the the 'Show Error alert ...' check box on error alert page in the Excel dialog + + + SwitchParameter + + + False + + + ErrorStyle + + Stop, Warning, or Infomation, corresponding to to the style setting in the Excel dialog + + + undefined + stop + warning + information + + ExcelDataValidationWarningStyle + + ExcelDataValidationWarningStyle + + + None + + + ErrorTitle + + The title for the message box corresponding to to the title setting in the Excel dialog + + String + + String + + + None + + + ErrorBody + + The error message corresponding to to the Error message setting in the Excel dialog + + String + + String + + + None + + + ShowPromptMessage + + Corresponds to the the 'Show Input message ...' check box on input message page in the Excel dialog + + + SwitchParameter + + + False + + + PromptBody + + The prompt message corresponding to to the Input message setting in the Excel dialog + + String + + String + + + None + + + PromptTitle + + The title for the message box corresponding to to the title setting in the Excel dialog + + String + + String + + + None + + + NoBlank + + By default the 'Ignore blank' option will be selected, unless NoBlank is sepcified. + + String + + String + + + None + + + + + + Range + + The range of cells to be validate, for example, "B2:C100" + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the cells should be validated + + ExcelWorksheet + + ExcelWorksheet + + + None + + + ValidationType + + An option corresponding to a choice from the 'Allow' pull down on the settings page in the Excel dialog. "Any" means "any allowed" - in other words, no Validation + + Object + + Object + + + None + + + Operator + + The operator to apply to Decimal, Integer, TextLength, DateTime and time fields, for example "equal" or "between" + + ExcelDataValidationOperator + + ExcelDataValidationOperator + + + Equal + + + Value + + For Decimal, Integer, TextLength, DateTime the [first] data value + + Object + + Object + + + None + + + Value2 + + When using the between operator, the second data value + + Object + + Object + + + None + + + Formula + + The [first] data value as a formula. Use absolute formulas $A$1 if (e.g.) you want all cells to check against the same list + + Object + + Object + + + None + + + Formula2 + + When using the between operator, the second data value as a formula + + Object + + Object + + + None + + + ValueSet + + When using the list validation type, a set of values (rather than refering to Sheet!B$2:B$100 ) + + Object + + Object + + + None + + + ShowErrorMessage + + Corresponds to the the 'Show Error alert ...' check box on error alert page in the Excel dialog + + SwitchParameter + + SwitchParameter + + + False + + + ErrorStyle + + Stop, Warning, or Infomation, corresponding to to the style setting in the Excel dialog + + ExcelDataValidationWarningStyle + + ExcelDataValidationWarningStyle + + + None + + + ErrorTitle + + The title for the message box corresponding to to the title setting in the Excel dialog + + String + + String + + + None + + + ErrorBody + + The error message corresponding to to the Error message setting in the Excel dialog + + String + + String + + + None + + + ShowPromptMessage + + Corresponds to the the 'Show Input message ...' check box on input message page in the Excel dialog + + SwitchParameter + + SwitchParameter + + + False + + + PromptBody + + The prompt message corresponding to to the Input message setting in the Excel dialog + + String + + String + + + None + + + PromptTitle + + The title for the message box corresponding to to the title setting in the Excel dialog + + String + + String + + + None + + + NoBlank + + By default the 'Ignore blank' option will be selected, unless NoBlank is sepcified. + + String + + String + + + None + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'E2:E1001' -ValidationType Integer -Operator between -Value 0 -Value2 100 \` + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'Percentage must be a whole number between 0 and 100' + + This defines a validation rule on cells E2-E1001; it is an integer rule and requires a number between 0 and 100. If a value is input with a fraction, negative number, or positive number > 100 a stop dialog box appears. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'B2:B1001' -ValidationType List -Formula 'values!$a$2:$a$1000' + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'You must select an item from the list' + + This defines a list rule on Cells B2:1001, and the posible values are in a sheet named "values" at cells A2 to A1000 Blank cells in this range are ignored. + If $ signs were left out of the fomrmula B2 would be checked against A2-A1000, B3, against A3-A1001, B4 against A4-A1002 up to B1001 beng checked against A1001-A1999 + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'I2:N1001' -ValidationType List -ValueSet @('yes','YES','Yes') + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody "Select Yes or leave blank for no" + + Similar to the previous example but this time provides a value set; Excel comparisons are case sesnsitive, hence 3 versions of Yes. + + + + + + + + Add-ExcelName + Add + ExcelName + + Adds a named-range to an existing Excel worksheet. + + + + It is often helpful to be able to refer to sets of cells with a name rather than using their co-ordinates; Add-ExcelName sets up these names. + + + + Add-ExcelName + + Range + + The range of cells to assign as a name. + + ExcelRange + + ExcelRange + + + None + + + RangeName + + The name to assign to the range. If the name exists it will be updated to the new range. If no name is specified, the first cell in the range will be used as the name. + + String + + String + + + None + + + + + + Range + + The range of cells to assign as a name. + + ExcelRange + + ExcelRange + + + None + + + RangeName + + The name to assign to the range. If the name exists it will be updated to the new range. If no name is specified, the first cell in the range will be used as the name. + + String + + String + + + None + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $rangeName + + $WS is a worksheet, and $dataRange is a string describing a range of cells - for example "A1:Z10" - which will become a named range, using the name in $rangeName. + + + + + + + + Add-ExcelTable + Add + ExcelTable + + Adds Tables to Excel workbooks. + + + + Unlike named ranges, where the name only needs to be unique within a sheet, Table names must be unique in the workbook. + Tables carry formatting and by default have a filter. + The filter, header, totals, first and last column highlights can all be configured. + + + + Add-ExcelTable + + Range + + The range of cells to assign to a table. + + ExcelRange + + ExcelRange + + + None + + + TableName + + The name for the Table - this should be unqiue in the Workbook - auto generated names will be used if this is left empty. + + String + + String + + + None + + + TableStyle + + The Style for the table, by default "Medium6" is used + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + Medium6 + + + TotalSettings + + A HashTable in the form ColumnName = "Average"|"Count"|"CountNums"|"Max"|"Min"|"None"|"StdDev"|"Sum"|"Var" - if specified, -ShowTotal is not needed. + + Hashtable + + Hashtable + + + None + + + ShowHeader + + By default the header row is shown - it can be turned off with -ShowHeader:$false. + + + SwitchParameter + + + False + + + ShowFilter + + By default the filter is enabled - it can be turned off with -ShowFilter:$false. + + + SwitchParameter + + + False + + + ShowTotal + + Show total adds a totals row. This does not automatically sum the columns but provides a drop-down in each to select sum, average etc + + + SwitchParameter + + + False + + + ShowFirstColumn + + Highlights the first column in bold. + + + SwitchParameter + + + False + + + ShowLastColumn + + Highlights the last column in bold. + + + SwitchParameter + + + False + + + ShowRowStripes + + By default the table formats show striped rows, the can be turned off with -ShowRowStripes:$false + + + SwitchParameter + + + False + + + ShowColumnStripes + + Turns on column stripes. + + + SwitchParameter + + + False + + + PassThru + + If -PassThru is specified, the table object will be returned to allow additional changes to be made. + + + SwitchParameter + + + False + + + + + + Range + + The range of cells to assign to a table. + + ExcelRange + + ExcelRange + + + None + + + TableName + + The name for the Table - this should be unqiue in the Workbook - auto generated names will be used if this is left empty. + + String + + String + + + None + + + TableStyle + + The Style for the table, by default "Medium6" is used + + TableStyles + + TableStyles + + + Medium6 + + + ShowHeader + + By default the header row is shown - it can be turned off with -ShowHeader:$false. + + SwitchParameter + + SwitchParameter + + + False + + + ShowFilter + + By default the filter is enabled - it can be turned off with -ShowFilter:$false. + + SwitchParameter + + SwitchParameter + + + False + + + ShowTotal + + Show total adds a totals row. This does not automatically sum the columns but provides a drop-down in each to select sum, average etc + + SwitchParameter + + SwitchParameter + + + False + + + TotalSettings + + A HashTable in the form ColumnName = "Average"|"Count"|"CountNums"|"Max"|"Min"|"None"|"StdDev"|"Sum"|"Var" - if specified, -ShowTotal is not needed. + + Hashtable + + Hashtable + + + None + + + ShowFirstColumn + + Highlights the first column in bold. + + SwitchParameter + + SwitchParameter + + + False + + + ShowLastColumn + + Highlights the last column in bold. + + SwitchParameter + + SwitchParameter + + + False + + + ShowRowStripes + + By default the table formats show striped rows, the can be turned off with -ShowRowStripes:$false + + SwitchParameter + + SwitchParameter + + + False + + + ShowColumnStripes + + Turns on column stripes. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + If -PassThru is specified, the table object will be returned to allow additional changes to be made. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.Table.ExcelTable + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName + + $WS is a worksheet, and $dataRange is a string describing a range of cells - for example "A1:Z10". This range which will become a table, named $TableName + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName Musictable -ShowFilter:$false -ShowTotal -ShowFirstColumn + + Again $ws is a worksheet, range here is the whole of the active part of the worksheet. The table style and name are set, the filter is turned off, and a "Totals" row added, and first column is set in bold. + + + + + + + + Add-PivotTable + Add + PivotTable + + Adds a PivotTable (and optional PivotChart) to a workbook. + + + + If the PivotTable already exists, the source data will be updated. + + + + Add-PivotTable + + PivotTableName + + Name for the new PivotTable - this will be the name of a sheet in the Workbook. + + String + + String + + + None + + + Address + + By default, a PivotTable will be created on its own sheet, but it can be created on an existing sheet by giving the address where the top left corner of the table should go. (Allow two rows for the filter if one is used.) + + ExcelAddressBase + + ExcelAddressBase + + + None + + + ExcelPackage + + An Excel-package object for the workbook. + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found. + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable. + + Object + + Object + + + None + + + PivotData + + A hash table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. + + Object + + Object + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable. + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable. + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. + + + SwitchParameter + + + False + + + PivotTotals + + Define whether totals should be added to rows, columns neither, or both (the default is both). + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None". + + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + + Years + Quarters + Months + Days + Hours + Minutes + Seconds + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g. 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable. + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable. + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + None + + + PivotChartDefinition + + Use a chart definition instead of specifying chart settings one by one. + + Object + + Object + + + None + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. + + + SwitchParameter + + + False + + + PassThru + + Return the PivotTable so it can be customized. + + + SwitchParameter + + + False + + + + Add-PivotTable + + PivotTableName + + Name for the new PivotTable - this will be the name of a sheet in the Workbook. + + String + + String + + + None + + + Address + + By default, a PivotTable will be created on its own sheet, but it can be created on an existing sheet by giving the address where the top left corner of the table should go. (Allow two rows for the filter if one is used.) + + ExcelAddressBase + + ExcelAddressBase + + + None + + + ExcelPackage + + An Excel-package object for the workbook. + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found. + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable. + + Object + + Object + + + None + + + PivotData + + A hash table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. + + Object + + Object + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable. + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable. + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. + + + SwitchParameter + + + False + + + PivotTotals + + Define whether totals should be added to rows, columns neither, or both (the default is both). + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None". + + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + + Years + Quarters + Months + Days + Hours + Minutes + Seconds + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g. 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable. + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable. + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + None + + + IncludePivotChart + + If specified, a chart will be included. + + + SwitchParameter + + + False + + + ChartTitle + + Optional title for the pivot chart, by default the title omitted. + + String + + String + + + None + + + ChartHeight + + Height of the chart in Pixels (400 by default). + + Int32 + + Int32 + + + 400 + + + ChartWidth + + Width of the chart in Pixels (600 by default). + + Int32 + + Int32 + + + 600 + + + ChartRow + + Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + + Int32 + + Int32 + + + 0 + + + ChartColumn + + Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E). + + Int32 + + Int32 + + + 4 + + + ChartRowOffSetPixels + + Vertical offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartColumnOffSetPixels + + Horizontal offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartType + + Type of chart; defaults to "Pie". + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + Pie + + + NoLegend + + If specified hides the chart legend. + + + SwitchParameter + + + False + + + ShowCategory + + If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + + + SwitchParameter + + + False + + + ShowPercent + + If specified attaches percentages to slices in a pie chart. + + + SwitchParameter + + + False + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. + + + SwitchParameter + + + False + + + PassThru + + Return the PivotTable so it can be customized. + + + SwitchParameter + + + False + + + + + + PivotTableName + + Name for the new PivotTable - this will be the name of a sheet in the Workbook. + + String + + String + + + None + + + Address + + By default, a PivotTable will be created on its own sheet, but it can be created on an existing sheet by giving the address where the top left corner of the table should go. (Allow two rows for the filter if one is used.) + + ExcelAddressBase + + ExcelAddressBase + + + None + + + ExcelPackage + + An Excel-package object for the workbook. + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found. + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable. + + Object + + Object + + + None + + + PivotData + + A hash table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. + + Object + + Object + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable. + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable. + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. + + SwitchParameter + + SwitchParameter + + + False + + + PivotTotals + + Define whether totals should be added to rows, columns neither, or both (the default is both). + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None". + + SwitchParameter + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g. 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable. + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable. + + TableStyles + + TableStyles + + + None + + + PivotChartDefinition + + Use a chart definition instead of specifying chart settings one by one. + + Object + + Object + + + None + + + IncludePivotChart + + If specified, a chart will be included. + + SwitchParameter + + SwitchParameter + + + False + + + ChartTitle + + Optional title for the pivot chart, by default the title omitted. + + String + + String + + + None + + + ChartHeight + + Height of the chart in Pixels (400 by default). + + Int32 + + Int32 + + + 400 + + + ChartWidth + + Width of the chart in Pixels (600 by default). + + Int32 + + Int32 + + + 600 + + + ChartRow + + Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + + Int32 + + Int32 + + + 0 + + + ChartColumn + + Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E). + + Int32 + + Int32 + + + 4 + + + ChartRowOffSetPixels + + Vertical offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartColumnOffSetPixels + + Horizontal offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartType + + Type of chart; defaults to "Pie". + + eChartType + + eChartType + + + Pie + + + NoLegend + + If specified hides the chart legend. + + SwitchParameter + + SwitchParameter + + + False + + + ShowCategory + + If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + + SwitchParameter + + SwitchParameter + + + False + + + ShowPercent + + If specified attaches percentages to slices in a pie chart. + + SwitchParameter + + SwitchParameter + + + False + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + Return the PivotTable so it can be customized. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.Table.PivotTable.ExcelPivotTable + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $excel = Get-Service | Export-Excel -Path test.xlsx -WorksheetName Services -PassThru -AutoSize -DisplayPropertySet -TableName ServiceTable -Title "Services on $Env:COMPUTERNAME" + Add-PivotTable -ExcelPackage $excel -PivotTableName ServiceSummary -SourceRange $excel.Workbook.Worksheets\[1\].Tables\[0\].Address -PivotRows Status -PivotData Name -NoTotalsInPivot -Activate + Close-ExcelPackage $excel -Show + + This exports data to new workbook and creates a table with the data in it. + The Pivot table is added on its own page, the table created in the first command is used as the source for the PivotTable; which counts the service names in for each Status. + At the end the Pivot page is made active. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $chartdef = New-ExcelChartDefinition -Title "Gross and net by city and product" -ChartType ColumnClustered ` + -Column 11 -Width 500 -Height 360 -YMajorUnit 500 -YMinorUnit 100 -YAxisNumberformat "$#,##0" -LegendPosition Bottom + $excel = ConvertFrom-Csv @" +Product, City, Gross, Net +Apple, London , 300, 250 +Orange, London , 400, 350 +Banana, London , 300, 200 +Orange, Paris, 600, 500 +Banana, Paris, 300, 200 +Apple, New York, 1200,700 +"@ | Export-Excel -Path "test.xlsx" -TableStyle Medium13 -tablename "RawData" -PassThru + Add-PivotTable -PivotTableName Sales -Address $excel.Workbook.Worksheets[1].Cells["F1"] ` + -SourceWorkSheet $excel.Workbook.Worksheets[1] -PivotRows City -PivotColumns Product -PivotData @{Gross="Sum";Net="Sum"} ` + -PivotNumberFormat "$#,##0.00" -PivotTotals Both -PivotTableStyle Medium12 -PivotChartDefinition $chartdef + Close-ExcelPackage -show $excel + + This script starts by defining a chart. + Then it exports some data to an XLSX file and keeps the file open. + The next step is to add the pivot table, normally this would be on its own sheet in the workbook, but here -Address is specified to place it beside the data. + The Add-Pivot table is given the chart definition and told to create a tale using the City field to create rows, the Product field to create columns and the data should be the sum of the gross field and the sum of the net field; grand totals for both gross and net are included for rows (Cities) and columns (Products) and the data is explicitly formatted as a currency. + Note that in the chart definition the number format for the axis does not include any fraction part. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS> $excel = Convertfrom-csv @" +Location,OrderDate,quantity +Boston,1/1/2017,100 +New York,1/21/2017,200 +Boston,1/11/2017,300 +New York,1/9/2017,400 +Boston,1/18/2017,500 +Boston,2/1/2017,600 +New York,2/21/2017,700 +New York,2/11/2017,800 +Boston,2/9/2017,900 +Boston,2/18/2017,1000 +New York,1/1/2018,100 +Boston,1/21/2018,200 +New York,1/11/2018,300 +Boston,1/9/2018,400 +New York,1/18/2018,500 +Boston,2/1/2018,600 +Boston,2/21/2018,700 +New York,2/11/2018,800 +New York,2/9/2018,900 +Boston,2/18/2018,1000 +"@ | Select-Object -Property @{n="OrderDate";e={[datetime]::ParseExact($_.OrderDate,"M/d/yyyy",(Get-Culture))}}, + Location, Quantity | Export-Excel "test2.xlsx" -PassThru -AutoSize + Set-ExcelColumn -Worksheet $excel.sheet1 -Column 1 -NumberFormat 'Short Date' + $pt = Add-PivotTable -PassThru -PivotTableName "ByDate" -Address $excel.Sheet1.cells["F1"] -SourceWorkSheet $excel.Sheet1 -PivotRows location,orderdate -PivotData @{'quantity'='sum'} -GroupDateRow orderdate -GroupDatePart 'Months,Years' -PivotTotals None + $pt.RowFields[0].SubtotalTop=$false + $pt.RowFields[0].Compact=$false + Close-ExcelPackage $excel -Show + + Here the data contains dates formatted as strings using US format. + These are converted to DateTime objects before being exported to Excel; the "OrderDate" column is formatted with the local short-date style. + Then the PivotTable is added; it groups information by date and location, the date is split into years and then months. + No grand totals are displayed. + The Pivot table object is caught in a variable, and the "Location" column has its subtotal moved from the top to the bottom of each location section, and the "Compact" option is disabled to prevent "Year" moving into the same column as location. + Finally the workbook is saved and shown in Excel. + + + + + + + + Add-WorkSheet + Add + WorkSheet + + Adds a worksheet to an existing workbook. + + + + If the named worksheet already exists, the -Clearsheet parameter decides whether it should be deleted and a new one returned, or if not specified the existing sheet will be returned. + By default the sheet is created at the end of the work book, the -MoveXXXX switches allow the sheet to be [re]positioned at the start or before or after another sheet. + A new sheet will only be made the default sheet when excel opens if -Activate is specified. + + + + Add-WorkSheet + + ExcelPackage + + An object representing an Excel Package. + + ExcelPackage + + ExcelPackage + + + None + + + WorksheetName + + The name of the worksheet, 'Sheet1' by default. + + String + + String + + + None + + + ClearSheet + + If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. + + + SwitchParameter + + + False + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + MoveToStart takes precedence over MoveToEnd, Movebefore and MoveAfter if more than one is specified. + + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. + (This is the default position for newly created sheets, but it can be used to move existing sheets.) + + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be an index starting from 1, or a name). + MoveBefore takes precedence over MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be an index starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + Activate + + If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. + + + SwitchParameter + + + False + + + CopySource + + If worksheet is provided as a copy source the new worksheet will be a copy of it. The source can be in the same workbook, or in a different file. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + NoClobber + + Ignored but retained for backwards compatibility. + + + SwitchParameter + + + False + + + + Add-WorkSheet + + ExcelWorkbook + + An Excel Workbook to which the Worksheet will be added - a Package contains one Workbook, so you can use whichever fits at the time. + + ExcelWorkbook + + ExcelWorkbook + + + None + + + WorksheetName + + The name of the worksheet, 'Sheet1' by default. + + String + + String + + + None + + + ClearSheet + + If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. + + + SwitchParameter + + + False + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + MoveToStart takes precedence over MoveToEnd, Movebefore and MoveAfter if more than one is specified. + + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. + (This is the default position for newly created sheets, but it can be used to move existing sheets.) + + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be an index starting from 1, or a name). + MoveBefore takes precedence over MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be an index starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + Activate + + If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. + + + SwitchParameter + + + False + + + CopySource + + If worksheet is provided as a copy source the new worksheet will be a copy of it. The source can be in the same workbook, or in a different file. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + NoClobber + + Ignored but retained for backwards compatibility. + + + SwitchParameter + + + False + + + + + + ExcelPackage + + An object representing an Excel Package. + + ExcelPackage + + ExcelPackage + + + None + + + ExcelWorkbook + + An Excel Workbook to which the Worksheet will be added - a Package contains one Workbook, so you can use whichever fits at the time. + + ExcelWorkbook + + ExcelWorkbook + + + None + + + WorksheetName + + The name of the worksheet, 'Sheet1' by default. + + String + + String + + + None + + + ClearSheet + + If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. + + SwitchParameter + + SwitchParameter + + + False + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + MoveToStart takes precedence over MoveToEnd, Movebefore and MoveAfter if more than one is specified. + + SwitchParameter + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. + (This is the default position for newly created sheets, but it can be used to move existing sheets.) + + SwitchParameter + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be an index starting from 1, or a name). + MoveBefore takes precedence over MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be an index starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + Activate + + If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. + + SwitchParameter + + SwitchParameter + + + False + + + CopySource + + If worksheet is provided as a copy source the new worksheet will be a copy of it. The source can be in the same workbook, or in a different file. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + NoClobber + + Ignored but retained for backwards compatibility. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.ExcelWorksheet + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $WorksheetActors = $ExcelPackage | Add-WorkSheet -WorkSheetname Actors + + $ExcelPackage holds an Excel package object (returned by Open-ExcelPackage, or Export-Excel -passthru). This command will add a sheet named 'Actors', or return the sheet if it exists, and the result is stored in $WorkSheetActors. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $WorksheetActors = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname "Actors" -ClearSheet -MoveToStart + + This time the Excel package object is passed as a parameter instead of piped. + If the 'Actors' sheet already exists it is deleted and re-created. + The new sheet will be created last in the workbook, and -MoveToStart Moves it to the start. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationName -CopySource $sourceWs -Activate + + This time a workbook is used instead of a package, and a worksheet is copied - $SourceWs is a worksheet object, which can come from the same workbook or a different one. + Here the new copy of the data is made the active sheet when the workbook is opened. + + + + + + + + Close-ExcelPackage + Close + ExcelPackage + + Closes an Excel Package, saving, saving under a new name or abandoning changes and opening the file in Excel as required. + + + + When working with an ExcelPackage object, the Workbook is held in memory and not saved until the .Save() method of the package is called. + Close-ExcelPackage saves and disposes of the Package object. + It can be called with -NoSave to abandon the file without saving, with a new "SaveAs" filename, and/or with a password to protect the file. And -Show will open the file in Excel; -Calculate will try to update the workbook, although not everything can be recalculated + + + + Close-ExcelPackage + + ExcelPackage + + Package to close. + + ExcelPackage + + ExcelPackage + + + None + + + SaveAs + + Save file with a new name (ignored if -NoSave Specified). + + Object + + Object + + + None + + + Password + + Password to protect the file. + + String + + String + + + None + + + Show + + Open the file in Excel. + + + SwitchParameter + + + False + + + NoSave + + Abandon the file without saving. + + + SwitchParameter + + + False + + + Calculate + + Attempt to recalculation the workbook before saving + + + SwitchParameter + + + False + + + + + + ExcelPackage + + Package to close. + + ExcelPackage + + ExcelPackage + + + None + + + Show + + Open the file in Excel. + + SwitchParameter + + SwitchParameter + + + False + + + NoSave + + Abandon the file without saving. + + SwitchParameter + + SwitchParameter + + + False + + + SaveAs + + Save file with a new name (ignored if -NoSave Specified). + + Object + + Object + + + None + + + Password + + Password to protect the file. + + String + + String + + + None + + + Calculate + + Attempt to recalculation the workbook before saving + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + Close-ExcelPackage -show $excel + + $excel holds a package object, this saves the workbook and loads it into Excel. + + + + -------------------------- EXAMPLE 2 -------------------------- + Close-ExcelPackage -NoSave $excel + + $excel holds a package object, this disposes of it without writing it to disk. + + + + + + + + Compare-WorkSheet + Compare + WorkSheet + + Compares two worksheets and shows the differences. + + + + This command takes two file names, one or two worksheet names and a name for a "key" column. + It reads the worksheet from each file and decides the column names and builds a hashtable of the key-column values and the rows in which they appear. + It then uses PowerShell's Compare-Object command to compare the sheets (explicitly checking all the column names which have not been excluded). + For the difference rows it adds the row number for the key of that row - we have to add the key after doing the comparison, otherwise identical rows at different positions in the file will not be considered a match. + We also add the name of the file and sheet in which the difference occurs. + If -BackgroundColor is specified the difference rows will be changed to that background in the orginal file. + + + + Compare-WorkSheet + + Referencefile + + First file to compare. + + Object + + Object + + + None + + + Differencefile + + Second file to compare. + + Object + + Object + + + None + + + WorkSheetName + + Name(s) of worksheets to compare. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the comparison - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the comparison - supports wildcards. + + Object + + Object + + + None + + + Headername + + Specifies custom property names to use, instead of the values defined in the starting row of the sheet. + + String[] + + String[] + + + None + + + Startrow + + The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. + + Int32 + + Int32 + + + 1 + + + AllDataBackgroundColor + + If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. + + Object + + Object + + + None + + + BackgroundColor + + If specified, highlights the rows with differences. + + Object + + Object + + + None + + + TabColor + + If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). + + Object + + Object + + + None + + + Key + + Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". + + Object + + Object + + + Name + + + FontColor + + If specified, highlights the DIFF columns in rows which have the same key. + + Object + + Object + + + None + + + Show + + If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). + + + SwitchParameter + + + False + + + GridView + + If specified, the command tries to the show the DIFF in a Grid-View and not on the console (unless-PassThru is also specified). This works best with few columns selected, and requires a key. + + + SwitchParameter + + + False + + + PassThru + + If specified a full set of DIFF data is returned without filtering to the specified properties. + + + SwitchParameter + + + False + + + IncludeEqual + + If specified the result will include equal rows as well. By default only different rows are returned. + + + SwitchParameter + + + False + + + ExcludeDifferent + + If specified, the result includes only the rows where both are equal. + + + SwitchParameter + + + False + + + + Compare-WorkSheet + + Referencefile + + First file to compare. + + Object + + Object + + + None + + + Differencefile + + Second file to compare. + + Object + + Object + + + None + + + WorkSheetName + + Name(s) of worksheets to compare. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the comparison - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the comparison - supports wildcards. + + Object + + Object + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3 ...) instead of the using the values the starting row of the sheet. + + + SwitchParameter + + + False + + + Startrow + + The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. + + Int32 + + Int32 + + + 1 + + + AllDataBackgroundColor + + If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. + + Object + + Object + + + None + + + BackgroundColor + + If specified, highlights the rows with differences. + + Object + + Object + + + None + + + TabColor + + If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). + + Object + + Object + + + None + + + Key + + Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". + + Object + + Object + + + Name + + + FontColor + + If specified, highlights the DIFF columns in rows which have the same key. + + Object + + Object + + + None + + + Show + + If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). + + + SwitchParameter + + + False + + + GridView + + If specified, the command tries to the show the DIFF in a Grid-View and not on the console (unless-PassThru is also specified). This works best with few columns selected, and requires a key. + + + SwitchParameter + + + False + + + PassThru + + If specified a full set of DIFF data is returned without filtering to the specified properties. + + + SwitchParameter + + + False + + + IncludeEqual + + If specified the result will include equal rows as well. By default only different rows are returned. + + + SwitchParameter + + + False + + + ExcludeDifferent + + If specified, the result includes only the rows where both are equal. + + + SwitchParameter + + + False + + + + + + Referencefile + + First file to compare. + + Object + + Object + + + None + + + Differencefile + + Second file to compare. + + Object + + Object + + + None + + + WorkSheetName + + Name(s) of worksheets to compare. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the comparison - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the comparison - supports wildcards. + + Object + + Object + + + None + + + Headername + + Specifies custom property names to use, instead of the values defined in the starting row of the sheet. + + String[] + + String[] + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3 ...) instead of the using the values the starting row of the sheet. + + SwitchParameter + + SwitchParameter + + + False + + + Startrow + + The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. + + Int32 + + Int32 + + + 1 + + + AllDataBackgroundColor + + If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. + + Object + + Object + + + None + + + BackgroundColor + + If specified, highlights the rows with differences. + + Object + + Object + + + None + + + TabColor + + If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). + + Object + + Object + + + None + + + Key + + Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". + + Object + + Object + + + Name + + + FontColor + + If specified, highlights the DIFF columns in rows which have the same key. + + Object + + Object + + + None + + + Show + + If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). + + SwitchParameter + + SwitchParameter + + + False + + + GridView + + If specified, the command tries to the show the DIFF in a Grid-View and not on the console (unless-PassThru is also specified). This works best with few columns selected, and requires a key. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + If specified a full set of DIFF data is returned without filtering to the specified properties. + + SwitchParameter + + SwitchParameter + + + False + + + IncludeEqual + + If specified the result will include equal rows as well. By default only different rows are returned. + + SwitchParameter + + SwitchParameter + + + False + + + ExcludeDifferent + + If specified, the result includes only the rows where both are equal. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Compare-WorkSheet -Referencefile 'Server56.xlsx' -Differencefile 'Server57.xlsx' -WorkSheetName Products -key IdentifyingNumber -ExcludeProperty Install* | Format-Table + + The two workbooks in this example contain the result of redirecting a subset of properties from Get-WmiObject -Class win32_product to Export-Excel. + The command compares the "Products" pages in the two workbooks, but we don't want to register a difference if the software was installed on a different date or from a different place, and excluding Install* removes InstallDate and InstallSource. + This data doesn't have a "Name" column, so we specify the "IdentifyingNumber" column as the key. + The results will be presented as a table. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Compare-WorkSheet "Server54.xlsx" "Server55.xlsx" -WorkSheetName Services -GridView + + This time two workbooks contain the result of redirecting the command Get-WmiObject -Class win32_service to Export-Excel. + Here the -Differencefile and -Referencefile parameter switches are assumed and the default setting for -Key ("Name") works for services. + This will display the differences between the "Services" sheets using a grid view + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen + + This version of the command outputs the differences between the "services" pages and highlights any different rows in the spreadsheet files. + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen -FontColor Red -Show + + This example builds on the previous one: this time where two changed rows have the value in the "Name" column (the default value for -Key), this version adds highlighting of the changed cells in red; and then opens the Excel file. + + + + -------------------------- EXAMPLE 5 -------------------------- + PS\> Compare-WorkSheet 'Pester-tests.xlsx' 'Pester-tests.xlsx' -WorkSheetName 'Server1','Server2' -Property "full Description","Executed","Result" -Key "full Description" + + This time the reference file and the difference file are the same file and two different sheets are used. + Because the tests include the machine name and time the test was run, the command specifies that a limited set of columns should be used. + + + + -------------------------- EXAMPLE 6 -------------------------- + PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -GridView -ExcludeDifferent + + The "General" page in the two workbooks has a title and two unlabelled columns with a row each for CPU, Memory, Domain, Disk and so on. + So the command is told to start at row 2 in order to skip the title and given names for the columns: the first is "label" and the second "Value"; the label acts as the key. + This time we are interested in those rows which are the same in both sheets, and the result is displayed using grid view. + Note that grid view works best when the number of columns is small. + + + + -------------------------- EXAMPLE 7 -------------------------- + PS\>Compare-WorkSheet 'Server1.xlsx' 'Server2.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -BackgroundColor White -Show -AllDataBackgroundColor LightGray + + This version of the previous command highlights all the cells in LightGray and then sets the changed rows back to white. + Only the unchanged rows are highlighted. + + + + + + + + Convert-ExcelRangeToImage + Convert + ExcelRangeToImage + + Gets the specified part of an Excel file and exports it as an image + + + + Excel allows charts to be exported directly to a file, but it can't do this with the rest of a sheet. To work round this, this function + * Opens a copy of Excel and loads a file + * Selects a worksheet and then a range of cells in that worksheet + * Copies the select to the clipboard + * Saves the clipboard contents as an image file (it will save as .JPG unless the file name ends .BMP or .PNG) + * Copies a single cell to the clipboard (to prevent the "you have put a lot in the clipboard" message appearing) + * Closes Excel + Unlike most functions in the module it needs a local copy of Excel to be installed. + + + + Convert-ExcelRangeToImage + + Path + + Path to the Excel file + + Object + + Object + + + None + + + WorkSheetname + + Worksheet name - if none is specified "Sheet1" will be assumed + + Object + + Object + + + Sheet1 + + + Range + + Range of cells within the sheet, e.g "A1:Z99" + + Object + + Object + + + None + + + Destination + + A bmp, png or jpg file where the result will be saved + + Object + + Object + + + "$pwd\temp.png" + + + Show + + If specified opens the image in the default viewer. + + + SwitchParameter + + + False + + + + + + Path + + Path to the Excel file + + Object + + Object + + + None + + + WorkSheetname + + Worksheet name - if none is specified "Sheet1" will be assumed + + Object + + Object + + + Sheet1 + + + Range + + Range of cells within the sheet, e.g "A1:Z99" + + Object + + Object + + + None + + + Destination + + A bmp, png or jpg file where the result will be saved + + Object + + Object + + + "$pwd\temp.png" + + + Show + + If specified opens the image in the default viewer. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + + + + ConvertFrom-ExcelToSQLInsert + ConvertFrom + ExcelToSQLInsert + + Generate SQL insert statements from Excel spreadsheet. + + + + Generate SQL insert statements from Excel spreadsheet. + + + + ConvertFrom-ExcelToSQLInsert + + TableName + + Name of the target database table. + + Object + + Object + + + None + + + Path + + Path to an existing .XLSX file This parameter is passed to Import-Excel as is. + + Object + + Object + + + None + + + WorkSheetname + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. This parameter is passed to Import-Excel as is. + + Object + + Object + + + 1 + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 0 + + + Header + + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. If you provide fewr header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded. If you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blank as there is no data for them. + + String[] + + String[] + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + + + SwitchParameter + + + False + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + ConvertEmptyStringsToNull + + If specified, cells without any data are replaced with NULL, instead of an empty string. This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value. + + + SwitchParameter + + + False + + + UseMSSQLSyntax + + {{ Fill UseMSSQLSyntax Description }} + + + SwitchParameter + + + False + + + + + + TableName + + Name of the target database table. + + Object + + Object + + + None + + + Path + + Path to an existing .XLSX file This parameter is passed to Import-Excel as is. + + Object + + Object + + + None + + + WorkSheetname + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. This parameter is passed to Import-Excel as is. + + Object + + Object + + + 1 + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 0 + + + Header + + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. If you provide fewr header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded. If you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blank as there is no data for them. + + String[] + + String[] + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + + SwitchParameter + + SwitchParameter + + + False + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + SwitchParameter + + SwitchParameter + + + False + + + ConvertEmptyStringsToNull + + If specified, cells without any data are replaced with NULL, instead of an empty string. This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value. + + SwitchParameter + + SwitchParameter + + + False + + + UseMSSQLSyntax + + {{ Fill UseMSSQLSyntax Description }} + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings: + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Sheet1 | +---------------------------------------------------------- +| A B C | +|1 Movie Name Year Rating | +|2 The Bodyguard 1992 9 | +|3 The Matrix 1999 8 | +|4 Skyfall 2012 9 | +|5 The Avengers 2012 | +---------------------------------------------------------- + +PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path 'C:\Movies.xlsx' +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', ''); + + + + + + -------------------------- EXAMPLE 2 -------------------------- + Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string. + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Sheet1 | +---------------------------------------------------------- +| A B C | +|1 Movie Name Year Rating | +|2 The Bodyguard 1992 9 | +|3 The Matrix 1999 8 | +|4 Skyfall 2012 9 | +|5 The Avengers 2012 | +---------------------------------------------------------- + +PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path "C:\Movies.xlsx" -ConvertEmptyStringsToNull +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL); + + + + + + + + + + Copy-ExcelWorkSheet + Copy + ExcelWorkSheet + + Copies a worksheet between workbooks or within the same workbook. + + + + Copy-ExcelWorkSheet takes a Source object which is either a worksheet, or a package, Workbook or path, in which case the source worksheet can be specified by name or number (starting from 1). The destination worksheet can be explicitly named, or will follow the name of the source if no name is specified. The Destination workbook can be given as the path to an XLSx file, an ExcelPackage object or an ExcelWorkbook object. + + + + Copy-ExcelWorkSheet + + SourceObject + + An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found. + + Object + + Object + + + None + + + SourceWorkSheet + + Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1). + + Object + + Object + + + 1 + + + DestinationWorkbook + + An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied. + + Object + + Object + + + None + + + DestinationWorksheet + + Name of the worksheet in the destination workbook; by default the same as the source worksheet's name. If the sheet exists it will be deleted and re-copied. + + Object + + Object + + + None + + + Show + + if the destination is an excel package or a path, launch excel and open the file on completion. + + + SwitchParameter + + + False + + + + + + SourceObject + + An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found. + + Object + + Object + + + None + + + SourceWorkSheet + + Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1). + + Object + + Object + + + 1 + + + DestinationWorkbook + + An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied. + + Object + + Object + + + None + + + DestinationWorksheet + + Name of the worksheet in the destination workbook; by default the same as the source worksheet's name. If the sheet exists it will be deleted and re-copied. + + Object + + Object + + + None + + + Show + + if the destination is an excel package or a path, launch excel and open the file on completion. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + Copy-ExcelWorkSheet -SourceWorkbook Test1.xlsx -DestinationWorkbook Test2.xlsx + + This is the simplest version of the command: no source worksheet is specified so Copy-ExcelWorksheet uses the first sheet in the workbook No Destination sheet is specified so the new worksheet will be the same as the one which is being copied. + + + + -------------------------- EXAMPLE 2 -------------------------- + Copy-ExcelWorkSheet -SourceWorkbook Server1.xlsx -sourceWorksheet "Settings" -DestinationWorkbook Settings.xlsx -DestinationWorksheet "Server1" + + Here the Settings page from Server1's workbook is copied to the 'Server1" page of a "Settings" workbook. + + + + -------------------------- EXAMPLE 3 -------------------------- + $excel = Open-ExcelPackage .\test.xlsx + + C:\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet "first" -DestinationWorkbook $excel -Show -DestinationWorksheet Duplicate This opens the workbook test.xlsx and copies the worksheet named "first" to a new worksheet named "Duplicate", because -Show is specified the file is saved and opened in Excel + + + + -------------------------- EXAMPLE 4 -------------------------- + $excel = Open-ExcelPackage .\test.xlsx + + C:\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet 1 -DestinationWorkbook $excel -DestinationWorksheet Duplicate C:\> Close-ExcelPackage $excel This is almost the same as the previous example, except source sheet is specified by position rather than name and because -Show is not specified, so other steps can be carried using the package object, at the end the file is saved by Close-ExcelPackage + + + + + + + + Expand-NumberFormat + Expand + NumberFormat + + Converts short names for number formats to the formatting strings used in Excel + + + + Where you can type a number format you can write, for example, 'Short-Date' and the module will translate it into the format string used by Excel. Some formats, like Short-Date, change when Excel loads (so date will use the local ordering of year, month and Day). Excel also changes how markers in the are presented different cultures "," is used in the format string to mean "local thousand seperator" but depending on the country "," or "." or " " may used as the thousand seperator. + + + + Expand-NumberFormat + + NumberFormat + + The format string to Expand + + Object + + Object + + + None + + + + + + NumberFormat + + The format string to Expand + + Object + + Object + + + None + + + + + + + System.String + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + Expand-NumberFormat percentage + + Returns "0.00%" + + + + -------------------------- EXAMPLE 2 -------------------------- + Expand-NumberFormat Currency + + Returns the currency format specified in the local regional settings, which may not be the same as Excel uses. + The regional settings set the currency symbol and then whether it is before or after the number and separated with a space or not; for negative numbers the number may be wrapped in parentheses or a - sign might appear before or after the number and symbol. + So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00- for French. + Note some Eurozone countries write €1,23 and others 1,23€. In French the decimal point will be rendered as a "," and the thousand separator as a space. + + + + + + + + Export-Excel + Export + Excel + + Exports data to an Excel worksheet. + + + + Exports data to an Excel file and where possible tries to convert numbers in text fields so Excel recognizes them as numbers instead of text. After all: Excel is a spreadsheet program used for number manipulation and calculations. The parameter -NoNumberConversion * can be used if number conversion is not desired. + + + + Export-Excel + + Path + + Path to a new or existing .XLSX file. + + String + + String + + + None + + + InputObject + + Date is usually piped into Export-Excel, but it also accepts data through the InputObject parameter + + Object + + Object + + + None + + + Calculate + + If specified, a recalculation of the worksheet will be requested before saving. + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation; convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + WorksheetName + + The name of a sheet within the workbook - "Sheet1" by default. + + String + + String + + + Sheet1 + + + Password + + Sets password protection on the workbook. + + String + + String + + + None + + + ClearSheet + + If specified Export-Excel will remove any existing worksheet with the selected name. + The default behaviour is to overwrite cells in this sheet as needed (but leaving non-overwritten ones in place). + + + SwitchParameter + + + False + + + Append + + If specified data will be added to the end of an existing sheet, using the same column headings. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in the top left cell. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + IncludePivotTable + + Adds a PivotTable using the data in the worksheet. + + + SwitchParameter + + + False + + + PivotTableName + + If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". + + String + + String + + + None + + + PivotRows + + Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotColumns + + Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotData + + In a PivotTable created from command line parameters, the fields to use in the table body are given as a Hash-table in the form + ColumnName = Average|Count|CountNums|Max|Min|Product|None|StdDev|StdDevP|Sum|Var|VarP. + + Object + + Object + + + None + + + PivotFilter + + Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown as separate rows under the given row heading; this switch makes them separate columns. + + + SwitchParameter + + + False + + + PivotTableDefinition + + Instead of describing a single PivotTable with multiple command-line parameters; you can use a HashTable in the form PivotTableName = Definition; + In this table Definition is itself a Hashtable with Sheet, PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values. The New-PivotTableDefinition command will create the definition from a command line. + + Hashtable + + Hashtable + + + None + + + IncludePivotChart + + Include a chart with the PivotTable - implies -IncludePivotTable. + + + SwitchParameter + + + False + + + ChartType + + The type for PivotChart (one of Excel's defined chart types). + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + Pie + + + NoLegend + + Exclude the legend from the PivotChart. + + + SwitchParameter + + + False + + + ShowCategory + + Add category labels to the PivotChart. + + + SwitchParameter + + + False + + + ShowPercent + + Add percentage labels to the PivotChart. + + + SwitchParameter + + + False + + + AutoSize + + Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. + + + SwitchParameter + + + False + + + MaxAutoSizeRows + + Autosizing can be time consuming, so this sets a maximum number of rows to look at for the Autosize operation. Default is 1000; If 0 is specified ALL rows will be checked + + Object + + Object + + + 1000 + + + NoClobber + + Not used. Left in to avoid problems with older scripts, it may be removed in future versions. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. + + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + NoHeader + + Specifies that field names should not be put at the top of columns. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name, and applies a style to it. The name must not contain spaces. If the -Tablestyle parameter is specified without Tablename, "table1", "table2" etc. will be used. + + Object + + Object + + + None + + + TableStyle + + Selects the style for the named table - if the Tablename parameter is specified without giving a style, 'Medium6' is used as a default. + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + Medium6 + + + Barchart + + Creates a "quick" bar chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + PieChart + + Creates a "quick" pie chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + LineChart + + Creates a "quick" line chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + ColumnChart + + Creates a "quick" column chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + ExcelChartDefinition + + A hash-table containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-Pivot] charts. This can be created with the New-ExcelChartDefinition command. + + Object[] + + Object[] + + + None + + + HideSheet + + Name(s) of Sheet(s) to hide in the workbook, supports wildcards. If the selection would cause all sheets to be hidden, the sheet being worked on will be revealed. + + String[] + + String[] + + + None + + + UnHideSheet + + Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. + + String[] + + String[] + + + None + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + -MoveToStart takes precedence over -MoveToEnd, -Movebefore and -MoveAfter if more than one is specified. + + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. (This is the default position for newly created sheets, but the option can be specified to move existing sheets.) + + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be a position starting from 1, or a name). + -MoveBefore takes precedence over -MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be a position starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + KillExcel + + Closes Excel without stopping to ask if work should be saved - prevents errors writing to the file because Excel has it open. + + + SwitchParameter + + + False + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + StartRow + + Row to start adding data. 1 by default. Row 1 will contain the title, if any is specifed. Then headers will appear (Unless -No header is specified) then the data appears. + + Int32 + + Int32 + + + 1 + + + StartColumn + + Column to start adding data - 1 by default. + + Int32 + + Int32 + + + 1 + + + PassThru + + If specified, Export-Excel returns an object representing the Excel package without saving the package first. To save, you must either use the Close-ExcelPackage command, or send the package object back to Export-Excel which will save and close the file, or use the object's .Save() or SaveAs() method. + + + SwitchParameter + + + False + + + Numberformat + + Formats all values that can be converted to a number to the format specified. For examples: + + '0' integer (not really needed unless you need to round numbers, Excel will use default cell properties). + '#' integer without displaying the number 0 in the cell. + '0.0' number with 1 decimal place. + '0.00' number with 2 decimal places. + '#,##0.00' number with 2 decimal places and thousand-separator. + '€#,##0.00' number with 2 decimal places and thousand-separator and money-symbol. + '0%' number with 2 decimal places and thousand-separator and money-symbol. + '[Blue]$#,##0.00;[Red]-$#,##0.00' + blue for positive numbers and red for negative numbers; Both proceeded by a '$' sign + + String + + String + + + General + + + ExcludeProperty + + Specifies properties which may exist in the target data but should not be placed on the worksheet. + + String[] + + String[] + + + None + + + NoAliasOrScriptPropeties + + Some objects in PowerShell duplicate existing properties by adding aliases, or have Script properties which may take a long time to return a value and slow the export down, if specified this option removes these properties + + + SwitchParameter + + + False + + + DisplayPropertySet + + Many (but not all) objects in PowerShell have a hidden property named psStandardmembers with a child property DefaultDisplayPropertySet ; this parameter reduces the properties exported to those in this set. + + + SwitchParameter + + + False + + + NoNumberConversion + + By default the command will convert all values to numbers if possible, but this isn't always desirable. -NoNumberConversion allows you to add exceptions for the conversion. + The only Wildcard allowed is * for all properties + + String[] + + String[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. + + Object[] + + Object[] + + + None + + + Style + + Takes style settings as a hash-table (which may be built with the New-ExcelStyle command) and applies them to the worksheet. If the hash-table contains a range the settings apply to the range, otherewise they apply to the whole sheet. + + Object[] + + Object[] + + + None + + + CellStyleSB + + A script block which is run at the end of the export to apply styles to cells (although it can be used for other purposes). The script block is given three paramaters; an object containing the current worksheet, the Total number of Rows and the number of the last column. + + ScriptBlock + + ScriptBlock + + + None + + + Activate + + If there is already content in the workbook, a new sheet will not be active UNLESS Activate is specified; when a PivotTable is created its sheet will be activated by this switch. + + + SwitchParameter + + + False + + + Now + + The -Now switch is a shortcut that automatically creates a temporary file, enables "AutoSize", "TableName" and "Show", and opens the file immediately. + + + SwitchParameter + + + False + + + ReturnRange + + If specified, Export-Excel returns the range of added cells in the format "A1:Z100". + + + SwitchParameter + + + False + + + PivotTotals + + By default, PivotTables have totals for each row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. + + + SwitchParameter + + + False + + + ReZip + + If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. + + + SwitchParameter + + + False + + + + Export-Excel + + ExcelPackage + + An object representing an Excel Package - usually this is returned by specifying -PassThru allowing multiple commands to work on the same workbook without saving and reloading each time. + + ExcelPackage + + ExcelPackage + + + None + + + InputObject + + Date is usually piped into Export-Excel, but it also accepts data through the InputObject parameter + + Object + + Object + + + None + + + Calculate + + If specified, a recalculation of the worksheet will be requested before saving. + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation; convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + WorksheetName + + The name of a sheet within the workbook - "Sheet1" by default. + + String + + String + + + Sheet1 + + + Password + + Sets password protection on the workbook. + + String + + String + + + None + + + ClearSheet + + If specified Export-Excel will remove any existing worksheet with the selected name. + The default behaviour is to overwrite cells in this sheet as needed (but leaving non-overwritten ones in place). + + + SwitchParameter + + + False + + + Append + + If specified data will be added to the end of an existing sheet, using the same column headings. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in the top left cell. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + IncludePivotTable + + Adds a PivotTable using the data in the worksheet. + + + SwitchParameter + + + False + + + PivotTableName + + If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". + + String + + String + + + None + + + PivotRows + + Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotColumns + + Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotData + + In a PivotTable created from command line parameters, the fields to use in the table body are given as a Hash-table in the form + ColumnName = Average|Count|CountNums|Max|Min|Product|None|StdDev|StdDevP|Sum|Var|VarP. + + Object + + Object + + + None + + + PivotFilter + + Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown as separate rows under the given row heading; this switch makes them separate columns. + + + SwitchParameter + + + False + + + PivotTableDefinition + + Instead of describing a single PivotTable with multiple command-line parameters; you can use a HashTable in the form PivotTableName = Definition; + In this table Definition is itself a Hashtable with Sheet, PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values. The New-PivotTableDefinition command will create the definition from a command line. + + Hashtable + + Hashtable + + + None + + + IncludePivotChart + + Include a chart with the PivotTable - implies -IncludePivotTable. + + + SwitchParameter + + + False + + + ChartType + + The type for PivotChart (one of Excel's defined chart types). + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + Pie + + + NoLegend + + Exclude the legend from the PivotChart. + + + SwitchParameter + + + False + + + ShowCategory + + Add category labels to the PivotChart. + + + SwitchParameter + + + False + + + ShowPercent + + Add percentage labels to the PivotChart. + + + SwitchParameter + + + False + + + AutoSize + + Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. + + + SwitchParameter + + + False + + + MaxAutoSizeRows + + Autosizing can be time consuming, so this sets a maximum number of rows to look at for the Autosize operation. Default is 1000; If 0 is specified ALL rows will be checked + + Object + + Object + + + 1000 + + + NoClobber + + Not used. Left in to avoid problems with older scripts, it may be removed in future versions. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. + + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + NoHeader + + Specifies that field names should not be put at the top of columns. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name, and applies a style to it. The name must not contain spaces. If the -Tablestyle parameter is specified without Tablename, "table1", "table2" etc. will be used. + + Object + + Object + + + None + + + TableStyle + + Selects the style for the named table - if the Tablename parameter is specified without giving a style, 'Medium6' is used as a default. + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + Medium6 + + + Barchart + + Creates a "quick" bar chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + PieChart + + Creates a "quick" pie chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + LineChart + + Creates a "quick" line chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + ColumnChart + + Creates a "quick" column chart using the first text column as labels and the first numeric column as values. + + + SwitchParameter + + + False + + + ExcelChartDefinition + + A hash-table containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-Pivot] charts. This can be created with the New-ExcelChartDefinition command. + + Object[] + + Object[] + + + None + + + HideSheet + + Name(s) of Sheet(s) to hide in the workbook, supports wildcards. If the selection would cause all sheets to be hidden, the sheet being worked on will be revealed. + + String[] + + String[] + + + None + + + UnHideSheet + + Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. + + String[] + + String[] + + + None + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + -MoveToStart takes precedence over -MoveToEnd, -Movebefore and -MoveAfter if more than one is specified. + + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. (This is the default position for newly created sheets, but the option can be specified to move existing sheets.) + + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be a position starting from 1, or a name). + -MoveBefore takes precedence over -MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be a position starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + KillExcel + + Closes Excel without stopping to ask if work should be saved - prevents errors writing to the file because Excel has it open. + + + SwitchParameter + + + False + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + StartRow + + Row to start adding data. 1 by default. Row 1 will contain the title, if any is specifed. Then headers will appear (Unless -No header is specified) then the data appears. + + Int32 + + Int32 + + + 1 + + + StartColumn + + Column to start adding data - 1 by default. + + Int32 + + Int32 + + + 1 + + + PassThru + + If specified, Export-Excel returns an object representing the Excel package without saving the package first. To save, you must either use the Close-ExcelPackage command, or send the package object back to Export-Excel which will save and close the file, or use the object's .Save() or SaveAs() method. + + + SwitchParameter + + + False + + + Numberformat + + Formats all values that can be converted to a number to the format specified. For examples: + + '0' integer (not really needed unless you need to round numbers, Excel will use default cell properties). + '#' integer without displaying the number 0 in the cell. + '0.0' number with 1 decimal place. + '0.00' number with 2 decimal places. + '#,##0.00' number with 2 decimal places and thousand-separator. + '€#,##0.00' number with 2 decimal places and thousand-separator and money-symbol. + '0%' number with 2 decimal places and thousand-separator and money-symbol. + '[Blue]$#,##0.00;[Red]-$#,##0.00' + blue for positive numbers and red for negative numbers; Both proceeded by a '$' sign + + String + + String + + + General + + + ExcludeProperty + + Specifies properties which may exist in the target data but should not be placed on the worksheet. + + String[] + + String[] + + + None + + + NoAliasOrScriptPropeties + + Some objects in PowerShell duplicate existing properties by adding aliases, or have Script properties which may take a long time to return a value and slow the export down, if specified this option removes these properties + + + SwitchParameter + + + False + + + DisplayPropertySet + + Many (but not all) objects in PowerShell have a hidden property named psStandardmembers with a child property DefaultDisplayPropertySet ; this parameter reduces the properties exported to those in this set. + + + SwitchParameter + + + False + + + NoNumberConversion + + By default the command will convert all values to numbers if possible, but this isn't always desirable. -NoNumberConversion allows you to add exceptions for the conversion. + The only Wildcard allowed is * for all properties + + String[] + + String[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. + + Object[] + + Object[] + + + None + + + Style + + Takes style settings as a hash-table (which may be built with the New-ExcelStyle command) and applies them to the worksheet. If the hash-table contains a range the settings apply to the range, otherewise they apply to the whole sheet. + + Object[] + + Object[] + + + None + + + CellStyleSB + + A script block which is run at the end of the export to apply styles to cells (although it can be used for other purposes). The script block is given three paramaters; an object containing the current worksheet, the Total number of Rows and the number of the last column. + + ScriptBlock + + ScriptBlock + + + None + + + Activate + + If there is already content in the workbook, a new sheet will not be active UNLESS Activate is specified; when a PivotTable is created its sheet will be activated by this switch. + + + SwitchParameter + + + False + + + ReturnRange + + If specified, Export-Excel returns the range of added cells in the format "A1:Z100". + + + SwitchParameter + + + False + + + PivotTotals + + By default, PivotTables have totals for each row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. + + + SwitchParameter + + + False + + + ReZip + + If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. + + + SwitchParameter + + + False + + + + + + Path + + Path to a new or existing .XLSX file. + + String + + String + + + None + + + ExcelPackage + + An object representing an Excel Package - usually this is returned by specifying -PassThru allowing multiple commands to work on the same workbook without saving and reloading each time. + + ExcelPackage + + ExcelPackage + + + None + + + InputObject + + Date is usually piped into Export-Excel, but it also accepts data through the InputObject parameter + + Object + + Object + + + None + + + Calculate + + If specified, a recalculation of the worksheet will be requested before saving. + + SwitchParameter + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation; convenient for viewing the results instantly without having to search for the file first. + + SwitchParameter + + SwitchParameter + + + False + + + WorksheetName + + The name of a sheet within the workbook - "Sheet1" by default. + + String + + String + + + Sheet1 + + + Password + + Sets password protection on the workbook. + + String + + String + + + None + + + ClearSheet + + If specified Export-Excel will remove any existing worksheet with the selected name. + The default behaviour is to overwrite cells in this sheet as needed (but leaving non-overwritten ones in place). + + SwitchParameter + + SwitchParameter + + + False + + + Append + + If specified data will be added to the end of an existing sheet, using the same column headings. + + SwitchParameter + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in the top left cell. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBold + + Sets the title in boldface type. + + SwitchParameter + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + IncludePivotTable + + Adds a PivotTable using the data in the worksheet. + + SwitchParameter + + SwitchParameter + + + False + + + PivotTableName + + If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". + + String + + String + + + None + + + PivotRows + + Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotColumns + + Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotData + + In a PivotTable created from command line parameters, the fields to use in the table body are given as a Hash-table in the form + ColumnName = Average|Count|CountNums|Max|Min|Product|None|StdDev|StdDevP|Sum|Var|VarP. + + Object + + Object + + + None + + + PivotFilter + + Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. + + String[] + + String[] + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown as separate rows under the given row heading; this switch makes them separate columns. + + SwitchParameter + + SwitchParameter + + + False + + + PivotTableDefinition + + Instead of describing a single PivotTable with multiple command-line parameters; you can use a HashTable in the form PivotTableName = Definition; + In this table Definition is itself a Hashtable with Sheet, PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values. The New-PivotTableDefinition command will create the definition from a command line. + + Hashtable + + Hashtable + + + None + + + IncludePivotChart + + Include a chart with the PivotTable - implies -IncludePivotTable. + + SwitchParameter + + SwitchParameter + + + False + + + ChartType + + The type for PivotChart (one of Excel's defined chart types). + + eChartType + + eChartType + + + Pie + + + NoLegend + + Exclude the legend from the PivotChart. + + SwitchParameter + + SwitchParameter + + + False + + + ShowCategory + + Add category labels to the PivotChart. + + SwitchParameter + + SwitchParameter + + + False + + + ShowPercent + + Add percentage labels to the PivotChart. + + SwitchParameter + + SwitchParameter + + + False + + + AutoSize + + Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. + + SwitchParameter + + SwitchParameter + + + False + + + MaxAutoSizeRows + + Autosizing can be time consuming, so this sets a maximum number of rows to look at for the Autosize operation. Default is 1000; If 0 is specified ALL rows will be checked + + Object + + Object + + + 1000 + + + NoClobber + + Not used. Left in to avoid problems with older scripts, it may be removed in future versions. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + SwitchParameter + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. + + SwitchParameter + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + SwitchParameter + + SwitchParameter + + + False + + + NoHeader + + Specifies that field names should not be put at the top of columns. + + SwitchParameter + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name, and applies a style to it. The name must not contain spaces. If the -Tablestyle parameter is specified without Tablename, "table1", "table2" etc. will be used. + + Object + + Object + + + None + + + TableStyle + + Selects the style for the named table - if the Tablename parameter is specified without giving a style, 'Medium6' is used as a default. + + TableStyles + + TableStyles + + + Medium6 + + + Barchart + + Creates a "quick" bar chart using the first text column as labels and the first numeric column as values. + + SwitchParameter + + SwitchParameter + + + False + + + PieChart + + Creates a "quick" pie chart using the first text column as labels and the first numeric column as values. + + SwitchParameter + + SwitchParameter + + + False + + + LineChart + + Creates a "quick" line chart using the first text column as labels and the first numeric column as values. + + SwitchParameter + + SwitchParameter + + + False + + + ColumnChart + + Creates a "quick" column chart using the first text column as labels and the first numeric column as values. + + SwitchParameter + + SwitchParameter + + + False + + + ExcelChartDefinition + + A hash-table containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-Pivot] charts. This can be created with the New-ExcelChartDefinition command. + + Object[] + + Object[] + + + None + + + HideSheet + + Name(s) of Sheet(s) to hide in the workbook, supports wildcards. If the selection would cause all sheets to be hidden, the sheet being worked on will be revealed. + + String[] + + String[] + + + None + + + UnHideSheet + + Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. + + String[] + + String[] + + + None + + + MoveToStart + + If specified, the worksheet will be moved to the start of the workbook. + -MoveToStart takes precedence over -MoveToEnd, -Movebefore and -MoveAfter if more than one is specified. + + SwitchParameter + + SwitchParameter + + + False + + + MoveToEnd + + If specified, the worksheet will be moved to the end of the workbook. (This is the default position for newly created sheets, but the option can be specified to move existing sheets.) + + SwitchParameter + + SwitchParameter + + + False + + + MoveBefore + + If specified, the worksheet will be moved before the nominated one (which can be a position starting from 1, or a name). + -MoveBefore takes precedence over -MoveAfter if both are specified. + + Object + + Object + + + None + + + MoveAfter + + If specified, the worksheet will be moved after the nominated one (which can be a position starting from 1, or a name or *). + If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + + Object + + Object + + + None + + + KillExcel + + Closes Excel without stopping to ask if work should be saved - prevents errors writing to the file because Excel has it open. + + SwitchParameter + + SwitchParameter + + + False + + + AutoNameRange + + Makes each column a named range. + + SwitchParameter + + SwitchParameter + + + False + + + StartRow + + Row to start adding data. 1 by default. Row 1 will contain the title, if any is specifed. Then headers will appear (Unless -No header is specified) then the data appears. + + Int32 + + Int32 + + + 1 + + + StartColumn + + Column to start adding data - 1 by default. + + Int32 + + Int32 + + + 1 + + + PassThru + + If specified, Export-Excel returns an object representing the Excel package without saving the package first. To save, you must either use the Close-ExcelPackage command, or send the package object back to Export-Excel which will save and close the file, or use the object's .Save() or SaveAs() method. + + SwitchParameter + + SwitchParameter + + + False + + + Numberformat + + Formats all values that can be converted to a number to the format specified. For examples: + + '0' integer (not really needed unless you need to round numbers, Excel will use default cell properties). + '#' integer without displaying the number 0 in the cell. + '0.0' number with 1 decimal place. + '0.00' number with 2 decimal places. + '#,##0.00' number with 2 decimal places and thousand-separator. + '€#,##0.00' number with 2 decimal places and thousand-separator and money-symbol. + '0%' number with 2 decimal places and thousand-separator and money-symbol. + '[Blue]$#,##0.00;[Red]-$#,##0.00' + blue for positive numbers and red for negative numbers; Both proceeded by a '$' sign + + String + + String + + + General + + + ExcludeProperty + + Specifies properties which may exist in the target data but should not be placed on the worksheet. + + String[] + + String[] + + + None + + + NoAliasOrScriptPropeties + + Some objects in PowerShell duplicate existing properties by adding aliases, or have Script properties which may take a long time to return a value and slow the export down, if specified this option removes these properties + + SwitchParameter + + SwitchParameter + + + False + + + DisplayPropertySet + + Many (but not all) objects in PowerShell have a hidden property named psStandardmembers with a child property DefaultDisplayPropertySet ; this parameter reduces the properties exported to those in this set. + + SwitchParameter + + SwitchParameter + + + False + + + NoNumberConversion + + By default the command will convert all values to numbers if possible, but this isn't always desirable. -NoNumberConversion allows you to add exceptions for the conversion. + The only Wildcard allowed is * for all properties + + String[] + + String[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. + + Object[] + + Object[] + + + None + + + Style + + Takes style settings as a hash-table (which may be built with the New-ExcelStyle command) and applies them to the worksheet. If the hash-table contains a range the settings apply to the range, otherewise they apply to the whole sheet. + + Object[] + + Object[] + + + None + + + CellStyleSB + + A script block which is run at the end of the export to apply styles to cells (although it can be used for other purposes). The script block is given three paramaters; an object containing the current worksheet, the Total number of Rows and the number of the last column. + + ScriptBlock + + ScriptBlock + + + None + + + Activate + + If there is already content in the workbook, a new sheet will not be active UNLESS Activate is specified; when a PivotTable is created its sheet will be activated by this switch. + + SwitchParameter + + SwitchParameter + + + False + + + Now + + The -Now switch is a shortcut that automatically creates a temporary file, enables "AutoSize", "TableName" and "Show", and opens the file immediately. + + SwitchParameter + + SwitchParameter + + + False + + + ReturnRange + + If specified, Export-Excel returns the range of added cells in the format "A1:Z100". + + SwitchParameter + + SwitchParameter + + + False + + + PivotTotals + + By default, PivotTables have totals for each row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. + + SwitchParameter + + SwitchParameter + + + False + + + ReZip + + If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.ExcelPackage + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Get-Process | Export-Excel .\Test.xlsx -show + + Export all the processes to the Excel file 'Test.xlsx' and open the file immediately. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Write-Output -1 668 34 777 860 -0.5 119 -0.1 234 788 | + Export-Excel @ExcelParams -NumberFormat ' [Blue$#,##0.00; [Red]-$#,##0.00' + + Exports all data to the Excel file 'Excel.xslx' and colors the negative values in Red and the positive values in Blue. + It will also add a dollar sign in front of the numbers which use a thousand seperator and display to two decimal places. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> [PSCustOmobject][Ordered]@{ + Date = Get-Date + Formula1 = '=SUM(F2:G2)' + String1 = 'My String' + String2 = 'a' + IPAddress = '10.10.25.5' + Number1 = '07670' + Number2 = '0,26' + Number3 = '1.555,83' + Number4 = '1.2' + Number5 = '-31' + PhoneNr1 = '+32 44' + PhoneNr2 = '+32 4 4444 444' + PhoneNr3 = '+3244444444' +} | Export-Excel @ExcelParams -NoNumberConversion IPAddress, Number1 + + Exports all data to the Excel file "Excel.xlsx" and tries to convert all values to numbers where possible except for "IPAddress" and "Number1", which are stored in the sheet 'as is', without being converted to a number. + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> [PSCustOmobject][Ordered]@{ + Date = Get-Date + Formula1 = '=SUM(F2:G2)' + String1 = 'My String' + String2 = 'a' + IPAddress = '10.10.25.5' + Number1 = '07670' + Number2 = '0,26' + Number3 = '1.555,83' + Number4 = '1.2' + Number5 = '-31' + PhoneNr1 = '+32 44' + PhoneNr2 = '+32 4 4444 444' + PhoneNr3 = '+3244444444' +} | Export-Excel @ExcelParams -NoNumberConversion * + + Exports all data to the Excel file 'Excel.xslx' as is, no number conversion will take place. This means that Excel will show the exact same data that you handed over to the 'Export-Excel' function. + + + + -------------------------- EXAMPLE 5 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Write-Output 489 668 299 777 860 151 119 497 234 788 | + Export-Excel @ExcelParams -ConditionalText $( + New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink + ) + + Exports data that will have a Conditional Formatting rule in Excel that will show cells with a value is greater than 525, with a background fill color of "LightPink" and the text in "DarkRed". + Where the condition is not met the color will be the default, black text on a white background. + + + + -------------------------- EXAMPLE 6 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Get-Service | Select-Object -Property Name, Status, DisplayName, ServiceName | + Export-Excel @ExcelParams -ConditionalText $( + New-ConditionalText Stop DarkRed LightPink + New-ConditionalText Running Blue Cyan + ) + + Exports all services to an Excel sheet, setting a Conditional formatting rule that will set the background fill color to "LightPink" and the text color to "DarkRed" when the value contains the word "Stop". + If the value contains the word "Running" it will have a background fill color of "Cyan" and text colored 'Blue'. + If neither condition is met, the color will be the default, black text on a white background. + + + + -------------------------- EXAMPLE 7 -------------------------- + PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true + } +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> $Array = @() +PS\> $Obj1 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' +} + +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} + + PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} + +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorksheetName Numbers + + Updates the first object of the array by adding property 'Member3' and 'Member4'. Afterwards, all objects are exported to an Excel file and all column headers are visible. + + + + -------------------------- EXAMPLE 8 -------------------------- + PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM + + + + + + -------------------------- EXAMPLE 9 -------------------------- + PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PM + + + + + + -------------------------- EXAMPLE 10 -------------------------- + PS\> Get-Service | Export-Excel 'c:\temp\test.xlsx' -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} + + + + + + -------------------------- EXAMPLE 11 -------------------------- + PS\> $pt = [ordered]@{} +PS\> $pt.pt1=@{ + SourceWorkSheet = 'Sheet1'; + PivotRows = 'Status' + PivotData = @{'Status'='count'} + IncludePivotChart = $true + ChartType = 'BarClustered3D' +} +PS\> $pt.pt2=@ + SourceWorkSheet = 'Sheet2'; + PivotRows = 'Company' + PivotData = @{'Company'='count'} + IncludePivotChart = $true + ChartType = 'PieExploded3D' +} +PS\> Remove-Item -Path .\test.xlsx +PS\> Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize +PS\> Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' +PS\> Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show + + This example defines two PivotTables. + Then it puts Service data on Sheet1 with one call to Export-Excel and Process Data on sheet2 with a second call to Export-Excel. + The third and final call adds the two PivotTables and opens the spreadsheet in Excel. + + + + -------------------------- EXAMPLE 12 -------------------------- + PS\> Remove-Item -Path .\test.xlsx +PS\> $excel = Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -PassThru +PS\> $excel.Workbook.Worksheets ["Sheet1"].Row(1).style.font.bold = $true +PS\> $excel.Workbook.Worksheets ["Sheet1"].Column(3 ).width = 29 +PS\> $excel.Workbook.Worksheets ["Sheet1"].Column(3 ).Style.wraptext = $true +PS\> $excel.Save() +PS\> $excel.Dispose() +PS\> Start-Process .\test.xlsx + + This example uses -PassThru. + It puts service information into sheet1 of the workbook and saves the ExcelPackage object in $Excel. + It then uses the package object to apply formatting, and then saves the workbook and disposes of the object, before loading the document in Excel. + Note: Other commands in the module remove the need to work directly with the package object in this way. + + + + -------------------------- EXAMPLE 13 -------------------------- + PS\> Remove-Item -Path .\test.xlsx -ErrorAction Ignore +PS\> $excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | + Export-Excel -Path .\test.xlsx -ClearSheet -WorksheetName "Processes" -PassThru +PS\> $sheet = $excel.Workbook.Worksheets ["Processes"] +PS\> $sheet.Column(1) | Set-ExcelRange -Bold -AutoFit +PS\> $sheet.Column(2) | Set-ExcelRange -Width 29 -WrapText +PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NFormat "#,###" +PS\> Set-ExcelRange -Address $sheet.Cells ["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###" +PS\> Set-ExcelRange -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold +PS\> Set-ExcelRange -Address $sheet.Row(1) -Bold -HorizontalAlignment Center +PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red +PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red +PS\> foreach ($c in 5..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit } +PS\> Export-Excel -ExcelPackage $excel -WorksheetName "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show + + This a more sophisticated version of the previous example showing different ways of using Set-ExcelRange, and also adding conditional formatting. + In the final command a PivotChart is added and the workbook is opened in Excel. + + + + -------------------------- EXAMPLE 14 -------------------------- + PS\> 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | + Export-Excel -now -LineChart -AutoNameRange + + Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees. + + + + -------------------------- EXAMPLE 15 -------------------------- + PS\> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | + Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables + + Runs a query against a SQL Server database and outputs the resulting rows as DataRows using the -OutputAs parameter. The results are then piped to the Export-Excel function. + NOTE: You need to install the SqlServer module from the PowerShell Gallery in order to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. + + + + + + https://github.com/dfinke/ImportExcel + https://github.com/dfinke/ImportExcel + + + + + + Get-ExcelSheetInfo + Get + ExcelSheetInfo + + Get worksheet names and their indices of an Excel workbook. + + + + The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook. + + + + Get-ExcelSheetInfo + + Path + + Specifies the path to the Excel file. (This parameter is required.) + + Object + + Object + + + None + + + + + + Path + + Specifies the path to the Excel file. (This parameter is required.) + + Object + + Object + + + None + + + + + + + CHANGELOG 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + + + + + -------------------------- EXAMPLE 1 -------------------------- + Get-ExcelSheetInfo .\Test.xlsx + + + + + + + + https://github.com/dfinke/ImportExcel + https://github.com/dfinke/ImportExcel + + + + + + Get-ExcelWorkbookInfo + Get + ExcelWorkbookInfo + + Retrieve information of an Excel workbook. + + + + The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage. + + + + Get-ExcelWorkbookInfo + + Path + + Specifies the path to the Excel file. This parameter is required. + + String + + String + + + None + + + + + + Path + + Specifies the path to the Excel file. This parameter is required. + + String + + String + + + None + + + + + + + CHANGELOG 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + + + + + -------------------------- EXAMPLE 1 -------------------------- + Get-ExcelWorkbookInfo .\Test.xlsx + + CorePropertiesXml : #document Title : Subject : Author : Konica Minolta User Comments : Keywords : LastModifiedBy : Bond, James (London) GBR LastPrinted : 2017-01-21T12:36:11Z Created : 17/01/2017 13:51:32 Category : Status : ExtendedPropertiesXml : #document Application : Microsoft Excel HyperlinkBase : AppVersion : 14.0300 Company : Secret Service Manager : Modified : 10/02/2017 12:45:37 CustomPropertiesXml : #document + + + + + + https://github.com/dfinke/ImportExcel + https://github.com/dfinke/ImportExcel + + + + + + Import-Excel + Import + Excel + + Create custom objects from the rows in an Excel worksheet. + + + + The Import-Excel cmdlet creates custom objects from the rows in an Excel worksheet. Each row is represented as one object. + This is possible without installing Microsoft Excel by using the .NET library 'EPPLus.dll'. + By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blank property name, only columns with column headers will be imported. + If the default behavior is not desired and you want to import the complete worksheet 'as is', the parameter '-NoHeader' can be used. In case you want to provide your own property names, you can use the parameter '-HeaderName'. + + + + Import-Excel + + Path + + Specifies the path to the Excel file. + + String + + String + + + None + + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. + This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + + + SwitchParameter + + + False + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + Import-Excel + + Path + + Specifies the path to the Excel file. + + String + + String + + + None + + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + HeaderName + + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. + If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. + If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. + + String[] + + String[] + + + None + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + Import-Excel + + Path + + Specifies the path to the Excel file. + + String + + String + + + None + + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + Import-Excel + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + ExcelPackage + + Instead of specifying a path, provides an Excel Package object (from Open-ExcelPackage). Using this avoids re-reading the whole file when importing multiple parts of it. + To allow multiple read operations Import-Excel does NOT close the package, and you should use Close-ExcelPackage -noSave to close it. + + ExcelPackage + + ExcelPackage + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. + This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + + + SwitchParameter + + + False + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + Import-Excel + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + ExcelPackage + + Instead of specifying a path, provides an Excel Package object (from Open-ExcelPackage). Using this avoids re-reading the whole file when importing multiple parts of it. + To allow multiple read operations Import-Excel does NOT close the package, and you should use Close-ExcelPackage -noSave to close it. + + ExcelPackage + + ExcelPackage + + + None + + + HeaderName + + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. + If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. + If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. + + String[] + + String[] + + + None + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + Import-Excel + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + ExcelPackage + + Instead of specifying a path, provides an Excel Package object (from Open-ExcelPackage). Using this avoids re-reading the whole file when importing multiple parts of it. + To allow multiple read operations Import-Excel does NOT close the package, and you should use Close-ExcelPackage -noSave to close it. + + ExcelPackage + + ExcelPackage + + + None + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + + + Path + + Specifies the path to the Excel file. + + String + + String + + + None + + + ExcelPackage + + Instead of specifying a path, provides an Excel Package object (from Open-ExcelPackage). Using this avoids re-reading the whole file when importing multiple parts of it. + To allow multiple read operations Import-Excel does NOT close the package, and you should use Close-ExcelPackage -noSave to close it. + + ExcelPackage + + ExcelPackage + + + None + + + WorksheetName + + Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + + String + + String + + + None + + + HeaderName + + Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. + If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. + If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. + + String[] + + String[] + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. + This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + + SwitchParameter + + SwitchParameter + + + False + + + StartRow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + + Int32 + + Int32 + + + 1 + + + EndRow + + By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + + Int32 + + Int32 + + + 0 + + + StartColumn + + The number of the first column to read data from (1 by default). + + Int32 + + Int32 + + + 1 + + + EndColumn + + By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + + Int32 + + Int32 + + + 0 + + + DataOnly + + Import only rows and columns that contain data, empty rows and empty columns are not imported. + + SwitchParameter + + SwitchParameter + + + False + + + AsText + + Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + + String[] + + String[] + + + None + + + Password + + Accepts a string that will be used to open a password protected Excel file. + + String + + String + + + None + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + ---------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------- +| A B C | +|1 First Name Address | +|2 Chuck Norris California | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------- + +PS C:> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors + +First Name: Chuck +Address : California + +First Name: Jean-Claude +Address : Brussels + + Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the column names defined in the first row. In case a column doesn't have a column header (usually in row 1 when '-StartRow' is not used), then the unnamed columns will be skipped and the data in those columns will not be imported. + Notice that column 'B' is not imported because there's no value in cell 'B1' that can be used as property name for the objects. + + + + -------------------------- EXAMPLE 2 -------------------------- + ---------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------- +| A B C | +|1 First Name Address | +|2 Chuck Norris California | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -NoHeader + +P1: First Name +P2: +P3: Address + +P1: Chuck +P2: Norris +P3: California + +P1: Jean-Claude +P2: Vandamme +P3: Brussels + + Imports the complete Excel worksheet 'as is' by using the '-NoHeader' switch. One object is created for each row. The property names of the objects will be automatically generated (P1, P2, P3, ..). + Notice that the column header (row 1) is imported as an object too. + + + + -------------------------- EXAMPLE 3 -------------------------- + ---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Movies | +---------------------------------------------------------- +| A B C D | +|1 The Bodyguard 1992 9 | +|2 The Matrix 1999 8 | +|3 | +|4 Skyfall 2012 9 | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -HeaderName 'Movie name', 'Year', 'Rating', 'Genre' + +Movie name: The Bodyguard +Year : 1992 +Rating : 9 +Genre : + +Movie name: The Matrix +Year : 1999 +Rating : 8 +Genre : + +Movie name: +Year : +Rating : +Genre : + +Movie name: Skyfall +Year : 2012 +Rating : 9 +Genre : + + This imports data from an Excel worksheet, and as before one object is created for each row. The property names for the objects are defined in the parameter '-HeaderName'. The properties are named starting from the most left column (A) to the right. In case no value is present in one of the columns, that property will have an empty value. + Notice that empty rows are imported and that data for the property 'Genre' is not present in the worksheet. As such, the 'Genre' property will be blank for all objects. + + + + -------------------------- EXAMPLE 4 -------------------------- + ---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Movies | +---------------------------------------------------------- +| A B C D | +|1 The Bodyguard 1992 9 | +|2 The Matrix 1999 8 | +|3 | +|4 Skyfall 2012 9 | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -NoHeader -DataOnly + +P1: The Bodyguard +P2: 1992 +P3: 9 + +P1: The Matrix +P2: 1999 +P3: 8 + +P1: Skyfall +P2: 2012 +P3: 9 + + Import data from an Excel worksheet, and one object is created for each non-blank row. The property names of the objects (P1, P2, P3, ..) are automatically generated by using the switch '-NoHeader' . The switch '-DataOnly' will speed up the import because empty rows and empty columns are not imported. + Notice that empty rows and empty columns are not imported. + + + + -------------------------- EXAMPLE 5 -------------------------- + ---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------------------- +| A B C D | +|1 Chuck Norris California | +|2 | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -DataOnly -HeaderName 'FirstName', 'SecondName', 'City' -StartRow 2 + +FirstName : Jean-Claude +SecondName: Vandamme +City : Brussels + + Import data from an Excel worksheet. One object is created for each row. The property names are provided with the '-HeaderName' parameter. The import will start from row 2 and empty columns and rows are not imported. + Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with 'Chuck Norris' has not been imported, because we started the import from row 2 with the parameter '-StartRow 2'. + + + + -------------------------- EXAMPLE 6 -------------------------- + PS\> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | + Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force + + Imports data from an Excel file and pipes the result to the Write-SqlTableData command to be INSERTed into a table in a SQL Server database. + The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows. + The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. + The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in. NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet. + + + + + + https://github.com/dfinke/ImportExcel + https://github.com/dfinke/ImportExcel + + + + + + Join-Worksheet + Join + Worksheet + + Combines data on all the sheets in an Excel worksheet onto a single sheet. + + + + Join-Worksheet can work in two main ways, either + *Combining data which has the same layout from many pages into one, or *Combining pages which have nothing in common. In the former case the header row is copied from the first sheet and, by default, each row of data is labelled with the name of the sheet it came from. + In the latter case -NoHeader is specified, and each copied block can have the sheet it came from placed above it as a title. + + + + Join-Worksheet + + Path + + Path to a new or existing .XLSX file. + + String + + String + + + None + + + WorkSheetName + + The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + + Object + + Object + + + Combined + + + Clearsheet + + If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + + + SwitchParameter + + + False + + + NoHeader + + Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + + + SwitchParameter + + + False + + + FromLabel + + If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + + String + + String + + + From + + + LabelBlocks + + If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + + + SwitchParameter + + + False + + + AutoSize + + Sets the width of the Excel columns to display all the data in their cells. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the headers of the combined sheet. + + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + HideSource + + If specified, hides the sheets that the data is copied from. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in Cell A1. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + PivotTableDefinition + + Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + + Hashtable + + Hashtable + + + None + + + ExcelChartDefinition + + A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. + + Object[] + + Object[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. + + Object[] + + Object[] + + + None + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + ReturnRange + + If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + PassThru + + If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + + + SwitchParameter + + + False + + + + Join-Worksheet + + Path + + Path to a new or existing .XLSX file. + + String + + String + + + None + + + WorkSheetName + + The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + + Object + + Object + + + Combined + + + Clearsheet + + If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + + + SwitchParameter + + + False + + + NoHeader + + Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + + + SwitchParameter + + + False + + + FromLabel + + If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + + String + + String + + + From + + + LabelBlocks + + If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + + + SwitchParameter + + + False + + + AutoSize + + Sets the width of the Excel columns to display all the data in their cells. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + + Int32[] + + Int32[] + + + None + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + HideSource + + If specified, hides the sheets that the data is copied from. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in Cell A1. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + PivotTableDefinition + + Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + + Hashtable + + Hashtable + + + None + + + ExcelChartDefinition + + A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. + + Object[] + + Object[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. + + Object[] + + Object[] + + + None + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. + + String + + String + + + None + + + TableStyle + + Selects the style for the named table - defaults to "Medium6". + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + Medium6 + + + ReturnRange + + If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + PassThru + + If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + + + SwitchParameter + + + False + + + + Join-Worksheet + + ExcelPackage + + An object representing an Excel Package - either from Open-ExcelPackage or specifying -PassThru to Export-Excel. + + ExcelPackage + + ExcelPackage + + + None + + + WorkSheetName + + The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + + Object + + Object + + + Combined + + + Clearsheet + + If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + + + SwitchParameter + + + False + + + NoHeader + + Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + + + SwitchParameter + + + False + + + FromLabel + + If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + + String + + String + + + From + + + LabelBlocks + + If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + + + SwitchParameter + + + False + + + AutoSize + + Sets the width of the Excel columns to display all the data in their cells. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + + Int32[] + + Int32[] + + + None + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + HideSource + + If specified, hides the sheets that the data is copied from. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in Cell A1. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + PivotTableDefinition + + Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + + Hashtable + + Hashtable + + + None + + + ExcelChartDefinition + + A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. + + Object[] + + Object[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. + + Object[] + + Object[] + + + None + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. + + String + + String + + + None + + + TableStyle + + Selects the style for the named table - defaults to "Medium6". + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + Medium6 + + + ReturnRange + + If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + PassThru + + If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + + + SwitchParameter + + + False + + + + Join-Worksheet + + ExcelPackage + + An object representing an Excel Package - either from Open-ExcelPackage or specifying -PassThru to Export-Excel. + + ExcelPackage + + ExcelPackage + + + None + + + WorkSheetName + + The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + + Object + + Object + + + Combined + + + Clearsheet + + If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + + + SwitchParameter + + + False + + + NoHeader + + Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + + + SwitchParameter + + + False + + + FromLabel + + If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + + String + + String + + + From + + + LabelBlocks + + If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + + + SwitchParameter + + + False + + + AutoSize + + Sets the width of the Excel columns to display all the data in their cells. + + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the headers of the combined sheet. + + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + + SwitchParameter + + + False + + + HideSource + + If specified, hides the sheets that the data is copied from. + + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in Cell A1. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + TitleBold + + Sets the title in boldface type. + + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + PivotTableDefinition + + Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + + Hashtable + + Hashtable + + + None + + + ExcelChartDefinition + + A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. + + Object[] + + Object[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. + + Object[] + + Object[] + + + None + + + AutoNameRange + + Makes each column a named range. + + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + ReturnRange + + If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + + + SwitchParameter + + + False + + + PassThru + + If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + + + SwitchParameter + + + False + + + + + + Path + + Path to a new or existing .XLSX file. + + String + + String + + + None + + + ExcelPackage + + An object representing an Excel Package - either from Open-ExcelPackage or specifying -PassThru to Export-Excel. + + ExcelPackage + + ExcelPackage + + + None + + + WorkSheetName + + The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + + Object + + Object + + + Combined + + + Clearsheet + + If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + + SwitchParameter + + SwitchParameter + + + False + + + NoHeader + + Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + + SwitchParameter + + SwitchParameter + + + False + + + FromLabel + + If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + + String + + String + + + From + + + LabelBlocks + + If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + + SwitchParameter + + SwitchParameter + + + False + + + AutoSize + + Sets the width of the Excel columns to display all the data in their cells. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeTopRow + + Freezes headers etc. in the top row. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeFirstColumn + + Freezes titles etc. in the left column. + + SwitchParameter + + SwitchParameter + + + False + + + FreezeTopRowFirstColumn + + Freezes top row and left column (equivalent to Freeze pane 2,2 ). + + SwitchParameter + + SwitchParameter + + + False + + + FreezePane + + Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + + Int32[] + + Int32[] + + + None + + + AutoFilter + + Enables the Excel filter on the headers of the combined sheet. + + SwitchParameter + + SwitchParameter + + + False + + + BoldTopRow + + Makes the top row boldface. + + SwitchParameter + + SwitchParameter + + + False + + + HideSource + + If specified, hides the sheets that the data is copied from. + + SwitchParameter + + SwitchParameter + + + False + + + Title + + Text of a title to be placed in Cell A1. + + String + + String + + + None + + + TitleFillPattern + + Sets the fill pattern for the title cell. + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + TitleBackgroundColor + + Sets the cell background color for the title cell. + + Object + + Object + + + None + + + TitleBold + + Sets the title in boldface type. + + SwitchParameter + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 22 + + + PivotTableDefinition + + Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + + Hashtable + + Hashtable + + + None + + + ExcelChartDefinition + + A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. + + Object[] + + Object[] + + + None + + + ConditionalFormat + + One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + + Object[] + + Object[] + + + None + + + ConditionalText + + Applies a Conditional formatting rule defined with New-ConditionalText. + + Object[] + + Object[] + + + None + + + AutoNameRange + + Makes each column a named range. + + SwitchParameter + + SwitchParameter + + + False + + + RangeName + + Makes the data in the worksheet a named range. + + String + + String + + + None + + + TableName + + Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. + + String + + String + + + None + + + TableStyle + + Selects the style for the named table - defaults to "Medium6". + + TableStyles + + TableStyles + + + Medium6 + + + ReturnRange + + If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + + SwitchParameter + + SwitchParameter + + + False + + + Show + + Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> foreach ($computerName in @('Server1', 'Server2', 'Server3', 'Server4')) { + Get-Service -ComputerName $computerName | + Select-Object -Property Status, Name, DisplayName, StartType | + Export-Excel -Path .\test.xlsx -WorkSheetname $computerName -AutoSize +} +PS\> $ptDef = New-PivotTableDefinition -PivotTableName "Pivot1" -SourceWorkSheet "Combined" -PivotRows "Status" -PivotFilter "MachineName" -PivotData @{Status='Count'} -IncludePivotChart -ChartType BarClustered3D +PS\> Join-Worksheet -Path .\test.xlsx -WorkSheetName combined -FromLabel "MachineName" -HideSource-AutoSize -FreezeTopRow -BoldTopRow -PivotTableDefinition $pt -Show + + The foreach command gets a list of services running on four servers and exports each list to its own page in Test.xlsx. And $PtDef=... creates a definition for a PivotTable. + The Join-Worksheet command uses the same file and merges the results into a sheet named "Combined". It sets a column header of "Machinename", this column will contain the name of the sheet the data was copied from; after copying the data to the sheet "Combined", the other sheets will be hidden. Join-Worksheet finishes by calling Export-Excel to AutoSize cells, freeze the top row and make it bold and add thePivotTable. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Get-CimInstance -ClassName win32_logicaldisk | + Select-Object -Property DeviceId,VolumeName, Size,Freespace | + Export-Excel -Path "$env:computerName.xlsx" -WorkSheetname Volumes -NumberFormat "0,000" +PS\> Get-NetAdapter| Select-Object Name,InterfaceDescription,MacAddress,LinkSpeed | + Export-Excel -Path "$env:COMPUTERNAME.xlsx" -WorkSheetname NetAdapter +PS\> Join-Worksheet -Path "$env:COMPUTERNAME.xlsx"-WorkSheetName Summary -Title "Summary" -TitleBold -TitleSize 22 -NoHeader -LabelBlocks -AutoSize -HideSource -show + + The first two commands get logical-disk and network-card information; each type is exported to its own sheet in a workbook. + The Join-Worksheet command copies both onto a page named "Summary".Because the data is dissimilar, -NoHeader is specified, ensuring the whole of each page is copied. Specifying -LabelBlocks causes each sheet's name to become a title on the summary page above the copied data. The source data is hidden, a title is added in 22 point boldface and the columns are sized to fit the data. + + + + + + Online Version: + https://github.com/dfinke/ImportExcel + + + + + + Merge-MultipleSheets + Merge + MultipleSheets + + Merges Worksheets into a single Worksheet with differences marked up. + + + + The Merge Worksheet command combines two sheets. Merge-MultipleSheets is designed to merge more than two. + If asked to merge sheets A,B,C which contain Services, with a Name, Displayname and Start mode, where "Name" is treated as the key, Merge-MultipleSheets: + * Calls Merge-Worksheet to merge "Name", "Displayname" and "Startmode" from sheets A and C; the result has column headings "_Row", "Name", "DisplayName", "Startmode", "C-DisplayName", "C-StartMode", "C-Is" and "C-Row". + * Calls Merge-Worksheet again passing it the intermediate result and sheet B, comparing "Name", "Displayname" and "Start mode" columns on each side, and gets a result with columns "_Row", "Name", "DisplayName", "Startmode", "B-DisplayName", "B-StartMode", "B-Is", "B-Row", "C-DisplayName", "C-StartMode", "C-Is" and "C-Row". + Any columns on the "reference" side which are not used in the comparison are added on the right, which is why we compare the sheets in reverse order. + The "Is" columns hold "Same", "Added", "Removed" or "Changed" and is used for conditional formatting in the output sheet (these columns are hidden by default), and when the data is written to Excel the "reference" columns, in this case "DisplayName" and "Start" are renamed to reflect their source, so they become "A-DisplayName" and "A-Start". + Conditional formatting is also applied to the Key column ("Name" in this case) so the view can be filtered to rows with changes by filtering this column on color. + Note: the processing order can affect what is seen as a change.For example, if there is an extra item in sheet B in the example above, Sheet C will be processed first and that row and will not be seen to be missing. When sheet B is processed it is marked as an addition, and the conditional formatting marks the entries from sheet A to show that a values were added in at least one sheet. + However if Sheet B is the reference sheet, A and C will be seen to have an item removed; and if B is processed before C, the extra item is known when C is processed and so C is considered to be missing that item. + + + + Merge-MultipleSheets + + Path + + Paths to the files to be merged. Files are also accepted + + Object + + Object + + + None + + + KeyFontColor + + Sets the font color for the Key field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::Red + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + Startrow + + The row from where we start to import data, all rows above the Start row are disregarded. By default this is the first row. + + Int32 + + Int32 + + + 1 + + + Headername + + Specifies custom property names to use, instead of the values defined in the column headers of the Start row. + + String[] + + String[] + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. + + Object + + Object + + + Sheet1 + + + OutputFile + + File to write output to. + + Object + + Object + + + .\temp.xlsx + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the comparison - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the comparison - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the reference and difference sides, default is "Name". + + Object + + Object + + + Name + + + NoHeader + + If specified, property names will be automatically generated (P1, P2, P3, ..) instead of using the values from the start row. + + + SwitchParameter + + + False + + + HideRowNumbers + + If specified, hides the columns in the spreadsheet that contain the row numbers. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -whatif so it the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + + + + Path + + Paths to the files to be merged. Files are also accepted + + Object + + Object + + + None + + + Startrow + + The row from where we start to import data, all rows above the Start row are disregarded. By default this is the first row. + + Int32 + + Int32 + + + 1 + + + Headername + + Specifies custom property names to use, instead of the values defined in the column headers of the Start row. + + String[] + + String[] + + + None + + + NoHeader + + If specified, property names will be automatically generated (P1, P2, P3, ..) instead of using the values from the start row. + + SwitchParameter + + SwitchParameter + + + False + + + WorksheetName + + Name(s) of Worksheets to compare. + + Object + + Object + + + Sheet1 + + + OutputFile + + File to write output to. + + Object + + Object + + + .\temp.xlsx + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the comparison - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the comparison - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the reference and difference sides, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the Key field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::Red + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + HideRowNumbers + + If specified, hides the columns in the spreadsheet that contain the row numbers. + + SwitchParameter + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -whatif so it the command only outputs to the pipeline). + + SwitchParameter + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> dir Server*.xlsx | Merge-MulipleSheets -WorksheetName Services -OutputFile Test2.xlsx -OutputSheetName Services -Show + + Here we are auditing servers and each one has a workbook in the current directory which contains a "Services" Worksheet (the result of Get-WmiObject -Class win32_service | Select-Object -Property Name, Displayname, Startmode). No key is specified so the key is assumed to be the "Name" column. The files are merged and the result is opened on completion. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> dir Serv*.xlsx | Merge-MulipleSheets -WorksheetName Software -Key "*" -ExcludeProperty Install* -OutputFile Test2.xlsx -OutputSheetName Software -Show + + The server audit files in the previous example also have "Software" worksheet, but no single field on that sheet works as a key. Specifying "*" for the key produces a compound key using all non-excluded fields (and the installation date and file location are excluded). + + + + -------------------------- EXAMPLE 3 -------------------------- + Merge-MulipleSheets -Path hotfixes.xlsx -WorksheetName Serv* -Key hotfixid -OutputFile test2.xlsx -OutputSheetName hotfixes -HideRowNumbers -Show + + This time all the servers have written their hotfix information to their own worksheets in a shared Excel workbook named "Hotfixes.xlsx" (the information was obtained by running Get-Hotfix | Sort-Object -Property description,hotfixid | Select-Object -Property Description,HotfixID) This ignores any sheets which are not named "Serv*", and uses the HotfixID as the key; in this version the row numbers are hidden. + + + + + + Online Version: + https://github.com/dfinke/ImportExcel + + + + + + Merge-Worksheet + Merge + Worksheet + + Merges two Worksheets (or other objects) into a single Worksheet with differences marked up. + + + + The Compare-Worksheet command takes two Worksheets and marks differences in the source document, and optionally outputs a grid showing the changes. + By contrast the Merge-Worksheet command takes the Worksheets and combines them into a single sheet showing the old and new data side by side. Although it is designed to work with Excel data it can work with arrays of any kind of object; so it can be a merge of Worksheets, or a merge to a Worksheet. + + + + Merge-Worksheet + + Referencefile + + First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. works with the following parameter sets + * A = Compare two files default headers + * B = Compare two files user supplied headers + * C = Compare two files headers P1, P2, P3 etc + + Object + + Object + + + None + + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of using the values the top row of the sheet. Works with parameter sets + * C 2 sheets with headers of P1, P2, P3 ... + * G Compare object + sheet + + + SwitchParameter + + + False + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + Referencefile + + First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. works with the following parameter sets + * A = Compare two files default headers + * B = Compare two files user supplied headers + * C = Compare two files headers P1, P2, P3 etc + + Object + + Object + + + None + + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + Headername + + Specifies custom property names to use, instead of the values defined in the column headers of the Start Row. Works with the following parameter sets: + * B 2 sheets with user supplied headers + * F Compare object + sheet + + String[] + + String[] + + + None + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + Referencefile + + First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. works with the following parameter sets + * A = Compare two files default headers + * B = Compare two files user supplied headers + * C = Compare two files headers P1, P2, P3 etc + + Object + + Object + + + None + + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + DiffPrefix + + If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" + + Object + + Object + + + => + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of using the values the top row of the sheet. Works with parameter sets + * C 2 sheets with headers of P1, P2, P3 ... + * G Compare object + sheet + + + SwitchParameter + + + False + + + ReferenceObject + + Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object + + Object + + Object + + + None + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + DiffPrefix + + If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" + + Object + + Object + + + => + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + Headername + + Specifies custom property names to use, instead of the values defined in the column headers of the Start Row. Works with the following parameter sets: + * B 2 sheets with user supplied headers + * F Compare object + sheet + + String[] + + String[] + + + None + + + ReferenceObject + + Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object + + Object + + Object + + + None + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + DiffPrefix + + If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" + + Object + + Object + + + => + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + ReferenceObject + + Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object + + Object + + Object + + + None + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + Merge-Worksheet + + DifferenceObject + + Difference object to compare if a Worksheet is NOT being used for either half. Can't have a reference sheet and difference object. + + Object + + Object + + + None + + + DiffPrefix + + If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" + + Object + + Object + + + => + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + ReferenceObject + + Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object + + Object + + Object + + + None + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + + + Referencefile + + First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. works with the following parameter sets + * A = Compare two files default headers + * B = Compare two files user supplied headers + * C = Compare two files headers P1, P2, P3 etc + + Object + + Object + + + None + + + Differencefile + + Second Excel file to compare. Works with paramter sets A,B,C as well as the following + * D = Compare two objects; + * E = Compare one object one file that uses default headers + * F = Compare one object one file that uses user supplied headers + * G = Compare one object one file that uses headers P1, P2, P3 etc + + Object + + Object + + + None + + + WorksheetName + + Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + + Object + + Object + + + Sheet1 + + + Startrow + + The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + + Int32 + + Int32 + + + 1 + + + Headername + + Specifies custom property names to use, instead of the values defined in the column headers of the Start Row. Works with the following parameter sets: + * B 2 sheets with user supplied headers + * F Compare object + sheet + + String[] + + String[] + + + None + + + NoHeader + + Automatically generate property names (P1, P2, P3, ..) instead of using the values the top row of the sheet. Works with parameter sets + * C 2 sheets with headers of P1, P2, P3 ... + * G Compare object + sheet + + SwitchParameter + + SwitchParameter + + + False + + + ReferenceObject + + Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object + + Object + + Object + + + None + + + DifferenceObject + + Difference object to compare if a Worksheet is NOT being used for either half. Can't have a reference sheet and difference object. + + Object + + Object + + + None + + + DiffPrefix + + If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" + + Object + + Object + + + => + + + OutputFile + + File to hold merged data. + + Object + + Object + + + None + + + OutputSheetName + + Name of Worksheet to output - if none specified will use the reference Worksheet name. + + Object + + Object + + + Sheet1 + + + Property + + Properties to include in the DIFF - supports wildcards, default is "*". + + Object + + Object + + + * + + + ExcludeProperty + + Properties to exclude from the the search - supports wildcards. + + Object + + Object + + + None + + + Key + + Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + + Object + + Object + + + Name + + + KeyFontColor + + Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + ChangeBackgroundColor + + Sets the background color for changed rows. + + Object + + Object + + + [System.Drawing.Color]::Orange + + + DeleteBackgroundColor + + Sets the background color for rows in the reference but deleted from the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + AddBackgroundColor + + Sets the background color for rows not in the reference but added to the difference sheet. + + Object + + Object + + + [System.Drawing.Color]::PaleGreen + + + HideEqual + + if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + + SwitchParameter + + SwitchParameter + + + False + + + Passthru + + If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + + SwitchParameter + + SwitchParameter + + + False + + + Show + + If specified, opens the output workbook. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -show + + The workbooks contain audit information for two servers, one sheet contains a list of services. + This command creates a worksheet named "54-55" in a workbook named "services.xlsx" which shows all the services and their differences, and opens the new workbook in Excel. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -HideEqual -AddBackgroundColor LightBlue -show + + This modifies the previous command to hide the equal rows in the output sheet and changes the color used to mark rows added to the second file. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Merge-Worksheet -OutputFile .\j1.xlsx -OutputSheetName test11 -ReferenceObject (dir .\ImportExcel\4.0.7) -DifferenceObject (dir .\ImportExcel\4.0.8) -Property Length -Show + + This version compares two directories, and marks what has changed. Because no "Key" property is given, "Name" is assumed to be the key and the only other property examined is length. Files which are added or deleted or have changed size will be highlighed in the output sheet. Changes to dates or other attributes will be ignored. + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> Merge-Worksheet -RefO (dir .\ImportExcel\4.0.7) -DiffO (dir .\ImportExcel\4.0.8) -Pr Length | Out-GridView + + This time no file is written and the results - which include all properties, not just length, are output and sent to Out-Gridview. + This version uses aliases to shorten the parameters, (OutputFileName can be "outFile" and the Sheet can be"OutSheet"; DifferenceObject & ReferenceObject can be DiffObject & RefObject respectively). + + + + + + Online Version: + https://github.com/dfinke/ImportExcel + + + + + + New-ConditionalFormattingIconSet + New + ConditionalFormattingIconSet + + Creates an object which describes a conditional formatting rule a for 3,4 or 5 icon set. + + + + Export-Excel takes a -ConditionalFormat parameter which can hold one or more descriptions for conditional formats; this command builds the defintion of a Conditional formatting rule for an icon set. + + + + New-ConditionalFormattingIconSet + + Range + + The range of cells that the conditional format applies to. + + Object + + Object + + + None + + + ConditionalFormat + + The type of rule: one of "ThreeIconSet","FourIconSet" or "FiveIconSet" + + Object + + Object + + + None + + + Reverse + + Use the icons in the reverse order. + + + SwitchParameter + + + False + + + + + + Range + + The range of cells that the conditional format applies to. + + Object + + Object + + + None + + + ConditionalFormat + + The type of rule: one of "ThreeIconSet","FourIconSet" or "FiveIconSet" + + Object + + Object + + + None + + + Reverse + + Use the icons in the reverse order. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $cfRange = [OfficeOpenXml.ExcelAddress]::new($topRow, $column, $lastDataRow, $column) +PS\> $cfdef = New-ConditionalFormattingIconSet -Range $cfrange -ConditionalFormat ThreeIconSet -IconType Arrows +PS\> Export-Excel -ExcelPackage $excel -ConditionalFormat $cfdef -show + + The first line creates a range - one column wide in the column $column, running from $topRow to $lastDataRow. The second line creates a definition object using this range and the third uses Export-Excel with an open package to apply the format and save and open the file. + + + + + + Add-Add-ConditionalFormatting + + + + New-ConditionalText + + + + + + + New-ConditionalText + New + ConditionalText + + Creates an object which describes a conditional formatting rule for single valued rules. + + + + Some Conditional formatting rules don't apply styles to a cell (IconSets and Databars); some take two parameters (Between); some take none (ThisWeek, ContainsErrors, AboveAverage etc).The others take a single parameter (Top, BottomPercent, GreaterThan, Contains etc). + This command creates an object to describe the last two categories, which can then be passed to Export-Excel. + + + + New-ConditionalText + + Text + + The text (or other value) to use in the rule. Note that Equals, GreaterThan/LessThan rules require text to wrapped in double quotes. + + Object + + Object + + + None + + + ConditionalTextColor + + The font color for the cell - by default: "DarkRed". + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + BackgroundColor + + The fill color for the cell - by default: "LightPink". + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + Range + + The range of cells that the conditional format applies to; if none is specified the range will be apply to all the data in the sheet. + + String + + String + + + None + + + PatternType + + The background pattern for the cell - by default: "Solid" + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + ConditionalType + + One of the supported rules; by default "ContainsText" is selected. + + Object + + Object + + + ContainsText + + + + + + Text + + The text (or other value) to use in the rule. Note that Equals, GreaterThan/LessThan rules require text to wrapped in double quotes. + + Object + + Object + + + None + + + ConditionalTextColor + + The font color for the cell - by default: "DarkRed". + + Object + + Object + + + [System.Drawing.Color]::DarkRed + + + BackgroundColor + + The fill color for the cell - by default: "LightPink". + + Object + + Object + + + [System.Drawing.Color]::LightPink + + + Range + + The range of cells that the conditional format applies to; if none is specified the range will be apply to all the data in the sheet. + + String + + String + + + None + + + PatternType + + The background pattern for the cell - by default: "Solid" + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + ConditionalType + + One of the supported rules; by default "ContainsText" is selected. + + Object + + Object + + + ContainsText + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $ct = New-ConditionalText -Text 'Ferrari' +PS\> Export-Excel -ExcelPackage $excel -ConditionalTest $ct -show + + The first line creates a definition object which will highlight the word "Ferrari" in any cell. and the second uses Export-Excel with an open package to apply the format and save and open the file. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $ct = New-ConditionalText -Text "Ferrari" +PS\> $ct2 = New-ConditionalText -Range $worksheet.Names\["FinishPosition"\].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalTextColor Red -BackgroundColor White +PS\> Export-Excel -ExcelPackage $excel -ConditionalText $ct,$ct2 -show + + This builds on the previous example, and specifies a condition of <=3 with a format of red text on a white background; this applies to a named range "Finish Position". + The range could be written -Range "C:C" to specify a named column, or -Range "C2:C102" to specify certain cells in the column. + + + + + + Add-ConditionalFormatting + + + + New-ConditionalFormattingIconSet + + + + + + + New-ExcelChartDefinition + New + ExcelChartDefinition + + Creates a Definition of a chart which can be added using Export-Excel, or Add-PivotTable + + + + All the parameters which are passed to Add-ExcelChart can be added to a chart-definition object and passed to Export-Excel with the -ExcelChartDefinition parameter, or to Add-PivotTable with the -PivotChartDefinition parameter. This command sets up those definition objects. + + + + New-ExcelChartDefinition + + Title + + The title for the chart. + + Object + + Object + + + Chart Title + + + RowOffSetPixels + + Offset to position the chart by a fraction of a row. + + Object + + Object + + + 10 + + + Column + + Column position of the top left corner of the chart. 0 places it at the edge of the sheet, 1 to the right of column A and so on. + + Object + + Object + + + 6 + + + ColumnOffSetPixels + + Offset to position the chart by a fraction of a column. + + Object + + Object + + + 5 + + + LegendPosition + + Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". + + + Top + Left + Right + Bottom + TopRight + + eLegendPosition + + eLegendPosition + + + None + + + LegendSize + + Font size for the key. + + Object + + Object + + + None + + + SeriesHeader + + Specifies explicit name(s) for the data series, which will appear in the legend/key + + Object + + Object + + + None + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 0 + + + XAxisTitleText + + Specifies a title for the X-axis. + + String + + String + + + None + + + XAxisTitleSize + + Sets the font size for the axis title. + + Object + + Object + + + None + + + XAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers along the X-axis. + + String + + String + + + None + + + Header + + No longer used. This may be removed in future versions. + + Object + + Object + + + None + + + XMajorUnit + + Spacing for the major gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMinorUnit + + Spacing for the minor gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMaxValue + + Maximum value for the scale along the X-axis. + + Object + + Object + + + None + + + XMinValue + + Minimum value for the scale along the X-axis. + + Object + + Object + + + None + + + XAxisPosition + + Position for the X-axis ("Top" or" Bottom"). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + YAxisTitleText + + Specifies a title for the Y-axis. + + String + + String + + + None + + + YAxisTitleSize + + Sets the font size for the Y-axis title. + + Object + + Object + + + None + + + YAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers on the Y-axis + + String + + String + + + None + + + YMajorUnit + + Spacing for the major gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMinorUnit + + Spacing for the minor gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + ChartType + + One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + ColumnStacked + + + YMaxValue + + Maximum value on the Y-axis. + + Object + + Object + + + None + + + YMinValue + + Minimum value on the Y-axis. + + Object + + Object + + + None + + + YAxisPosition + + Position for the Y-axis ("Left" or "Right"). + + + Left + Bottom + Right + Top + + eAxisPosition + + eAxisPosition + + + None + + + ChartTrendLine + + Superimposes one of Excel's trenline types on the chart. + + + Exponential + Linear + Logarithmic + MovingAvgerage + Polynomial + Power + + eTrendLine[] + + eTrendLine[] + + + None + + + XRange + + The range of cells containing values for the X-Axis - usually labels. + + Object + + Object + + + None + + + YRange + + The range(s) of cells holding values for the Y-Axis - usually "data". + + Object + + Object + + + None + + + Width + + Width of the chart in pixels. Defaults to 500. + + Object + + Object + + + 500 + + + Height + + Height of the chart in pixels. Defaults to 350. + + Object + + Object + + + 350 + + + Row + + Row position of the top left corner of the chart. 0 places it at the top of the sheet, 1 below row 1 and so on. + + Object + + Object + + + 0 + + + LegendBold + + Sets the key in bold type. + + + SwitchParameter + + + False + + + NoLegend + + If specified, turns off display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + + + SwitchParameter + + + False + + + ShowCategory + + Attaches a category label in charts which support this. + + + SwitchParameter + + + False + + + ShowPercent + + Attaches a percentage label in charts which support this. + + + SwitchParameter + + + False + + + TitleBold + + Sets the title in bold face. + + + SwitchParameter + + + False + + + XAxisTitleBold + + Sets the X-axis title in bold face. + + + SwitchParameter + + + False + + + YAxisTitleBold + + Sets the Y-axis title in bold face. + + + SwitchParameter + + + False + + + + + + Title + + The title for the chart. + + Object + + Object + + + Chart Title + + + Header + + No longer used. This may be removed in future versions. + + Object + + Object + + + None + + + ChartType + + One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + + eChartType + + eChartType + + + ColumnStacked + + + ChartTrendLine + + Superimposes one of Excel's trenline types on the chart. + + eTrendLine[] + + eTrendLine[] + + + None + + + XRange + + The range of cells containing values for the X-Axis - usually labels. + + Object + + Object + + + None + + + YRange + + The range(s) of cells holding values for the Y-Axis - usually "data". + + Object + + Object + + + None + + + Width + + Width of the chart in pixels. Defaults to 500. + + Object + + Object + + + 500 + + + Height + + Height of the chart in pixels. Defaults to 350. + + Object + + Object + + + 350 + + + Row + + Row position of the top left corner of the chart. 0 places it at the top of the sheet, 1 below row 1 and so on. + + Object + + Object + + + 0 + + + RowOffSetPixels + + Offset to position the chart by a fraction of a row. + + Object + + Object + + + 10 + + + Column + + Column position of the top left corner of the chart. 0 places it at the edge of the sheet, 1 to the right of column A and so on. + + Object + + Object + + + 6 + + + ColumnOffSetPixels + + Offset to position the chart by a fraction of a column. + + Object + + Object + + + 5 + + + LegendPosition + + Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". + + eLegendPosition + + eLegendPosition + + + None + + + LegendSize + + Font size for the key. + + Object + + Object + + + None + + + LegendBold + + Sets the key in bold type. + + SwitchParameter + + SwitchParameter + + + False + + + NoLegend + + If specified, turns off display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + + SwitchParameter + + SwitchParameter + + + False + + + ShowCategory + + Attaches a category label in charts which support this. + + SwitchParameter + + SwitchParameter + + + False + + + ShowPercent + + Attaches a percentage label in charts which support this. + + SwitchParameter + + SwitchParameter + + + False + + + SeriesHeader + + Specifies explicit name(s) for the data series, which will appear in the legend/key + + Object + + Object + + + None + + + TitleBold + + Sets the title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + TitleSize + + Sets the point size for the title. + + Int32 + + Int32 + + + 0 + + + XAxisTitleText + + Specifies a title for the X-axis. + + String + + String + + + None + + + XAxisTitleBold + + Sets the X-axis title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + XAxisTitleSize + + Sets the font size for the axis title. + + Object + + Object + + + None + + + XAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers along the X-axis. + + String + + String + + + None + + + XMajorUnit + + Spacing for the major gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMinorUnit + + Spacing for the minor gridlines / tick marks along the X-axis. + + Object + + Object + + + None + + + XMaxValue + + Maximum value for the scale along the X-axis. + + Object + + Object + + + None + + + XMinValue + + Minimum value for the scale along the X-axis. + + Object + + Object + + + None + + + XAxisPosition + + Position for the X-axis ("Top" or" Bottom"). + + eAxisPosition + + eAxisPosition + + + None + + + YAxisTitleText + + Specifies a title for the Y-axis. + + String + + String + + + None + + + YAxisTitleBold + + Sets the Y-axis title in bold face. + + SwitchParameter + + SwitchParameter + + + False + + + YAxisTitleSize + + Sets the font size for the Y-axis title. + + Object + + Object + + + None + + + YAxisNumberformat + + A number formatting string, like "#,##0.00", for numbers on the Y-axis + + String + + String + + + None + + + YMajorUnit + + Spacing for the major gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMinorUnit + + Spacing for the minor gridlines / tick marks on the Y-axis. + + Object + + Object + + + None + + + YMaxValue + + Maximum value on the Y-axis. + + Object + + Object + + + None + + + YMinValue + + Minimum value on the Y-axis. + + Object + + Object + + + None + + + YAxisPosition + + Position for the Y-axis ("Left" or "Right"). + + eAxisPosition + + eAxisPosition + + + None + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $cDef = New-ExcelChartDefinition -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom +PS\> 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -now -WorkSheetname SinX -ExcelChartDefinition $cDef -Show + + This reworks an example from Add-Excel-Chart but here the chart is defined and the defintion stored in $cDef and then Export-Excel uses $cDef . + + + + + + + + New-PivotTableDefinition + New + PivotTableDefinition + + Creates PivotTable definitons for Export-Excel + + + + Export-Excel allows a single PivotTable to be defined using the parameters -IncludePivotTable, -PivotColumns, -PivotRows, -PivotData, -PivotFilter, -PivotTotals, -PivotDataToColumn, -IncludePivotChart and -ChartType. + Its -PivotTableDefintion paramater allows multiple PivotTables to be defined, with additional parameters. New-PivotTableDefinition is a convenient way to build these definitions. + + + + New-PivotTableDefinition + + PivotTableName + + Name for the new pivot table + This command previously had a typo - and has an alias to avoid breaking scripts This will be removed in a future release + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must contain the column names to pivot by: if the range is not specified the whole source sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable + + Object + + Object + + + None + + + PivotData + + A hash-table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP + + Hashtable + + Hashtable + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown seperatate rows under the given row heading; this switch makes them seperate columns. + + + SwitchParameter + + + False + + + PivotTotals + + By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None" + + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + + Years + Quarters + Months + Days + Hours + Minutes + Seconds + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + None + + + PivotChartDefinition + + Use a chart definition instead of specifying chart settings one by one + + Object + + Object + + + None + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified + + + SwitchParameter + + + False + + + + New-PivotTableDefinition + + PivotTableName + + Name for the new pivot table + This command previously had a typo - and has an alias to avoid breaking scripts This will be removed in a future release + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must contain the column names to pivot by: if the range is not specified the whole source sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable + + Object + + Object + + + None + + + PivotData + + A hash-table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP + + Hashtable + + Hashtable + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown seperatate rows under the given row heading; this switch makes them seperate columns. + + + SwitchParameter + + + False + + + PivotTotals + + By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None" + + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + + Years + Quarters + Months + Days + Hours + Minutes + Seconds + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable + + + None + Custom + Light1 + Light2 + Light3 + Light4 + Light5 + Light6 + Light7 + Light8 + Light9 + Light10 + Light11 + Light12 + Light13 + Light14 + Light15 + Light16 + Light17 + Light18 + Light19 + Light20 + Light21 + Medium1 + Medium2 + Medium3 + Medium4 + Medium5 + Medium6 + Medium7 + Medium8 + Medium9 + Medium10 + Medium11 + Medium12 + Medium13 + Medium14 + Medium15 + Medium16 + Medium17 + Medium18 + Medium19 + Medium20 + Medium21 + Medium22 + Medium23 + Medium24 + Medium25 + Medium26 + Medium27 + Medium28 + Dark1 + Dark2 + Dark3 + Dark4 + Dark5 + Dark6 + Dark7 + Dark8 + Dark9 + Dark10 + Dark11 + + TableStyles + + TableStyles + + + None + + + IncludePivotChart + + If specified a chart Will be included. + + + SwitchParameter + + + False + + + ChartTitle + + Optional title for the pivot chart, by default the title omitted. + + String + + String + + + None + + + ChartHeight + + Height of the chart in Pixels (400 by default) + + Int32 + + Int32 + + + 400 + + + ChartWidth + + Width of the chart in Pixels (600 by default) + + Int32 + + Int32 + + + 600 + + + ChartRow + + Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + + Int32 + + Int32 + + + 0 + + + ChartColumn + + Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E) + + Int32 + + Int32 + + + 4 + + + ChartRowOffSetPixels + + Vertical offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartColumnOffSetPixels + + Horizontal offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartType + + Type of chart + + + Area + Line + Pie + Bubble + ColumnClustered + ColumnStacked + ColumnStacked100 + ColumnClustered3D + ColumnStacked3D + ColumnStacked1003D + BarClustered + BarStacked + BarStacked100 + BarClustered3D + BarStacked3D + BarStacked1003D + LineStacked + LineStacked100 + LineMarkers + LineMarkersStacked + LineMarkersStacked100 + PieOfPie + PieExploded + PieExploded3D + BarOfPie + XYScatterSmooth + XYScatterSmoothNoMarkers + XYScatterLines + XYScatterLinesNoMarkers + AreaStacked + AreaStacked100 + AreaStacked3D + AreaStacked1003D + DoughnutExploded + RadarMarkers + RadarFilled + Surface + SurfaceWireframe + SurfaceTopView + SurfaceTopViewWireframe + Bubble3DEffect + StockHLC + StockOHLC + StockVHLC + StockVOHLC + CylinderColClustered + CylinderColStacked + CylinderColStacked100 + CylinderBarClustered + CylinderBarStacked + CylinderBarStacked100 + CylinderCol + ConeColClustered + ConeColStacked + ConeColStacked100 + ConeBarClustered + ConeBarStacked + ConeBarStacked100 + ConeCol + PyramidColClustered + PyramidColStacked + PyramidColStacked100 + PyramidBarClustered + PyramidBarStacked + PyramidBarStacked100 + PyramidCol + XYScatter + Radar + Doughnut + Pie3D + Line3D + Column3D + Area3D + + eChartType + + eChartType + + + Pie + + + NoLegend + + If specified hides the chart legend + + + SwitchParameter + + + False + + + ShowCategory + + if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + + + SwitchParameter + + + False + + + ShowPercent + + If specified attaches percentages to slices in a pie chart. + + + SwitchParameter + + + False + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified + + + SwitchParameter + + + False + + + + + + PivotTableName + + Name for the new pivot table + This command previously had a typo - and has an alias to avoid breaking scripts This will be removed in a future release + + Object + + Object + + + None + + + SourceWorkSheet + + Worksheet where the data is found + + Object + + Object + + + None + + + SourceRange + + Address range in the worksheet e.g "A10:F20" - the first row must contain the column names to pivot by: if the range is not specified the whole source sheet will be used. + + Object + + Object + + + None + + + PivotRows + + Fields to set as rows in the PivotTable + + Object + + Object + + + None + + + PivotData + + A hash-table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP + + Hashtable + + Hashtable + + + None + + + PivotColumns + + Fields to set as columns in the PivotTable + + Object + + Object + + + None + + + PivotFilter + + Fields to use to filter in the PivotTable + + Object + + Object + + + None + + + PivotDataToColumn + + If there are multiple datasets in a PivotTable, by default they are shown seperatate rows under the given row heading; this switch makes them seperate columns. + + SwitchParameter + + SwitchParameter + + + False + + + PivotTotals + + By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + + String + + String + + + Both + + + NoTotalsInPivot + + Included for compatibility - equivalent to -PivotTotals "None" + + SwitchParameter + + SwitchParameter + + + False + + + GroupDateRow + + The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + + String + + String + + + None + + + GroupDatePart + + The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + + eDateGroupBy[] + + eDateGroupBy[] + + + None + + + GroupNumericRow + + The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + + String + + String + + + None + + + GroupNumericMin + + The starting point for grouping + + Double + + Double + + + 0 + + + GroupNumericMax + + The endpoint for grouping + + Double + + Double + + + 1.79769313486232E+308 + + + GroupNumericInterval + + The interval for grouping + + Double + + Double + + + 100 + + + PivotNumberFormat + + Number format to apply to the data cells in the PivotTable + + String + + String + + + None + + + PivotTableStyle + + Apply a table style to the PivotTable + + TableStyles + + TableStyles + + + None + + + PivotChartDefinition + + Use a chart definition instead of specifying chart settings one by one + + Object + + Object + + + None + + + IncludePivotChart + + If specified a chart Will be included. + + SwitchParameter + + SwitchParameter + + + False + + + ChartTitle + + Optional title for the pivot chart, by default the title omitted. + + String + + String + + + None + + + ChartHeight + + Height of the chart in Pixels (400 by default) + + Int32 + + Int32 + + + 400 + + + ChartWidth + + Width of the chart in Pixels (600 by default) + + Int32 + + Int32 + + + 600 + + + ChartRow + + Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + + Int32 + + Int32 + + + 0 + + + ChartColumn + + Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E) + + Int32 + + Int32 + + + 4 + + + ChartRowOffSetPixels + + Vertical offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartColumnOffSetPixels + + Horizontal offset of the chart from the cell corner. + + Int32 + + Int32 + + + 0 + + + ChartType + + Type of chart + + eChartType + + eChartType + + + Pie + + + NoLegend + + If specified hides the chart legend + + SwitchParameter + + SwitchParameter + + + False + + + ShowCategory + + if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + + SwitchParameter + + SwitchParameter + + + False + + + ShowPercent + + If specified attaches percentages to slices in a pie chart. + + SwitchParameter + + SwitchParameter + + + False + + + Activate + + If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $pt = New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet "Sheet1" -PivotRows "Status" -PivotData @{Status='Count'} -PivotFilter 'StartType' -IncludePivotChart -ChartType BarClustered3D +PS\> $Pt += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet "Sheet2" -PivotRows "Company" -PivotData @{Company='Count'} -IncludePivotChart -ChartType PieExploded3D -ShowPercent -ChartTitle "Breakdown of processes by company" +PS\> Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize +PS\> Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' +PS\> $excel = Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show + + This is a re-work of one of the examples in Export-Excel - instead of writing out the pivot definition hash-table, it is built by calling New-PivotTableDefinition. + + + + + + + + Open-ExcelPackage + Open + ExcelPackage + + Returns an ExcelPackage object for the specified XLSX fil.e + + + + Import-Excel and Export-Excel open an Excel file, carry out their tasks and close it again. + Sometimes it is necessary to open a file and do other work on it. Open-ExcelPackage allows the file to be opened for these tasks. + It takes a -KillExcel switch to make sure Excel is not holding the file open; a -Password parameter for existing protected files, and a -Create switch to set-up a new file if no file already exists. + + + + Open-ExcelPackage + + Path + + The path to the file to open. + + Object + + Object + + + None + + + Password + + The password for a protected worksheet, as a [normal] string (not a secure string). + + String + + String + + + None + + + KillExcel + + If specified, any running instances of Excel will be terminated before opening the file. This may result in lost work, so should be used with caution. + + + SwitchParameter + + + False + + + Create + + By default Open-ExcelPackage will only open an existing file; -Create instructs it to create a new file if required. + + + SwitchParameter + + + False + + + + + + Path + + The path to the file to open. + + Object + + Object + + + None + + + KillExcel + + If specified, any running instances of Excel will be terminated before opening the file. This may result in lost work, so should be used with caution. + + SwitchParameter + + SwitchParameter + + + False + + + Password + + The password for a protected worksheet, as a [normal] string (not a secure string). + + String + + String + + + None + + + Create + + By default Open-ExcelPackage will only open an existing file; -Create instructs it to create a new file if required. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.ExcelPackage + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $excel = Open-ExcelPackage -Path "$env:TEMP\test99.xlsx" -Create +PS\> $ws = Add-WorkSheet -ExcelPackage $excel + + This will create a new file in the temp folder if it doesn't already exist. It then adds a worksheet - because no name is specified it will use the default name of "Sheet1" + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $excela= Open-ExcelPackage -path "$xlPath" -Password $password +PS\> $sheet1 = $excel.Workbook.Worksheetsa"sheet1" ] +PS\> Set-ExcelRange -Range $sheet1.Cells ["E1:S1048576" ], $sheet1.Cells ["V1:V1048576" ] -NFormat ( [cultureinfo ]::CurrentCulture.DateTimeFormat.ShortDatePattern) +PS\> Close-ExcelPackage $excel -Show + + This will open the password protected file at $xlPath using the password stored in $Password. Sheet1 is selected and formatting applied to two blocks of the sheet; then the file is and saved and loaded into Excel. + + + + + + + + Remove-WorkSheet + Remove + WorkSheet + + Removes one or more worksheets from one or more workbooks + + + + + + Remove-WorkSheet + + FullName + + The fully qualified path to the XLSX file(s) + + Object + + Object + + + None + + + WorksheetName + + The worksheet to be removed (sheet1 by default) + + String[] + + String[] + + + Sheet1 + + + Show + + If specified the file will be opened in excel after the sheet is removed. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + + + + FullName + + The fully qualified path to the XLSX file(s) + + Object + + Object + + + None + + + WorksheetName + + The worksheet to be removed (sheet1 by default) + + String[] + + String[] + + + Sheet1 + + + Show + + If specified the file will be opened in excel after the sheet is removed. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1 + + Removes the worksheet named 'Sheet1' from 'Test1.xlsx' + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 + + Removes the worksheet named 'Sheet1' and 'Target1' from 'Test1.xlsx' + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 -Show + + Removes the worksheets and then launches the xlsx in Excel + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> dir c:\reports\*.xlsx | Remove-WorkSheet + + Removes 'Sheet1' from all the xlsx files in the c:\reports directory + + + + + + + + Select-Worksheet + Select + Worksheet + + Sets the selected tab in an Excel workbook to be the chosen sheet and unselects all the others. + + + + Sometimes when a sheet is added we want it to be the active sheet, sometimes we want the active sheet to be left as it was. Select-Worksheet exists to change which sheet is the selected tab when Excel opens the file. + + + + Select-Worksheet + + ExcelPackage + + An object representing an ExcelPackage. + + ExcelPackage + + ExcelPackage + + + None + + + WorksheetName + + The name of the worksheet "Sheet1" by default. + + String + + String + + + None + + + + Select-Worksheet + + ExcelWorkbook + + An Excel workbook to which the Worksheet will be added - a package contains one Workbook so you can use workbook or package as it suits. + + ExcelWorkbook + + ExcelWorkbook + + + None + + + WorksheetName + + The name of the worksheet "Sheet1" by default. + + String + + String + + + None + + + + Select-Worksheet + + ExcelWorksheet + + An object representing an Excel worksheet. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + + + + ExcelPackage + + An object representing an ExcelPackage. + + ExcelPackage + + ExcelPackage + + + None + + + ExcelWorkbook + + An Excel workbook to which the Worksheet will be added - a package contains one Workbook so you can use workbook or package as it suits. + + ExcelWorkbook + + ExcelWorkbook + + + None + + + WorksheetName + + The name of the worksheet "Sheet1" by default. + + String + + String + + + None + + + ExcelWorksheet + + An object representing an Excel worksheet. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Select-Worksheet -ExcelWorkbook $ExcelWorkbook -WorksheetName "NewSheet" + + $ExcelWorkbook holds a workbook object containing a sheet named "NewSheet"; This sheet will become the [only] active sheet in the workbook + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Select-Worksheet -ExcelPackage $Pkg -WorksheetName "NewSheet2" + + $pkg holds an Excel Package, whose workbook contains a sheet named "NewSheet2" This sheet will become the [only] active sheet in the workbook. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Select-Worksheet -ExcelWorksheet $ws + + $ws holds an Excel worksheet which will become the [only] active sheet in its workbook. + + + + + + + + Send-SQLDataToExcel + Send + SQLDataToExcel + + Inserts a DataTable - returned by a SQL query - into an ExcelSheet + + + + This command takes a SQL statement and run it against a database connection; for the connection it accepts either + * an object representing a session with a SQL server or ODBC database, or + * a connection string to make a session (if -MSSQLServer is specified it uses the SQL Native client, + and -Connection can be a server name instead of a detailed connection string. Without this switch it uses ODBC) + The command takes all the parameters of Export-Excel, except for -InputObject (alias TargetData); after fetching the data it calls Export-Excel with the data as the value of InputParameter and whichever of Export-Excel's parameters it was passed; for details of these parameters see the help for Export-Excel. + + + + Send-SQLDataToExcel + + Connection + + A database connection string to be used to create a database session; either + * A Data source name written in the form DSN=ODBC_Data_Source_Name, or + * A full ODBC or SQL Native Client Connection string, or + * The name of a SQL server. + + Object + + Object + + + None + + + SQL + + The SQL query to run against the session which was passed in -Session or set up from -Connection. + + String + + String + + + None + + + QueryTimeout + + Override the default query time of 30 seconds. + + Int32 + + Int32 + + + 0 + + + Force + + If specified Export-Excel will be called with parameters specified, even if there is no data to send + + + SwitchParameter + + + False + + + + Send-SQLDataToExcel + + Connection + + A database connection string to be used to create a database session; either + * A Data source name written in the form DSN=ODBC_Data_Source_Name, or + * A full ODBC or SQL Native Client Connection string, or + * The name of a SQL server. + + Object + + Object + + + None + + + MsSQLserver + + Specifies the connection string is for SQL server, not ODBC. + + + SwitchParameter + + + False + + + DataBase + + Switches to a specific database on a SQL server. + + String + + String + + + None + + + SQL + + The SQL query to run against the session which was passed in -Session or set up from -Connection. + + String + + String + + + None + + + QueryTimeout + + Override the default query time of 30 seconds. + + Int32 + + Int32 + + + 0 + + + Force + + If specified Export-Excel will be called with parameters specified, even if there is no data to send + + + SwitchParameter + + + False + + + + Send-SQLDataToExcel + + Session + + An active ODBC Connection or SQL connection object representing a session with a database which will be queried to get the data . + + Object + + Object + + + None + + + SQL + + The SQL query to run against the session which was passed in -Session or set up from -Connection. + + String + + String + + + None + + + QueryTimeout + + Override the default query time of 30 seconds. + + Int32 + + Int32 + + + 0 + + + Force + + If specified Export-Excel will be called with parameters specified, even if there is no data to send + + + SwitchParameter + + + False + + + + Send-SQLDataToExcel + + QueryTimeout + + Override the default query time of 30 seconds. + + Int32 + + Int32 + + + 0 + + + DataTable + + A System.Data.DataTable object containing the data to be inserted into the spreadsheet without running a query. This remains supported to avoid breaking older scripts, but if you have a DataTable object you can pass the it into Export-Excel using -InputObject. + + DataTable + + DataTable + + + None + + + Force + + If specified Export-Excel will be called with parameters specified, even if there is no data to send + + + SwitchParameter + + + False + + + + + + Connection + + A database connection string to be used to create a database session; either + * A Data source name written in the form DSN=ODBC_Data_Source_Name, or + * A full ODBC or SQL Native Client Connection string, or + * The name of a SQL server. + + Object + + Object + + + None + + + Session + + An active ODBC Connection or SQL connection object representing a session with a database which will be queried to get the data . + + Object + + Object + + + None + + + MsSQLserver + + Specifies the connection string is for SQL server, not ODBC. + + SwitchParameter + + SwitchParameter + + + False + + + DataBase + + Switches to a specific database on a SQL server. + + String + + String + + + None + + + SQL + + The SQL query to run against the session which was passed in -Session or set up from -Connection. + + String + + String + + + None + + + QueryTimeout + + Override the default query time of 30 seconds. + + Int32 + + Int32 + + + 0 + + + DataTable + + A System.Data.DataTable object containing the data to be inserted into the spreadsheet without running a query. This remains supported to avoid breaking older scripts, but if you have a DataTable object you can pass the it into Export-Excel using -InputObject. + + DataTable + + DataTable + + + None + + + Force + + If specified Export-Excel will be called with parameters specified, even if there is no data to send + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Send-SQLDataToExcel -MsSQLserver -Connection localhost -SQL "select name,type,type_desc from [master].[sys].[all_objects]" -Path .\temp.xlsx -WorkSheetname master -AutoSize -FreezeTopRow -AutoFilter -BoldTopRow + + Connects to the local SQL server and selects 3 columns from [Sys].[all_objects] and exports then to a sheet named master with some basic header management + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> $dbPath = 'C:\Users\James\Documents\Database1.accdb' +PS\> $Connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbPath;" +PS\> $SQL="SELECT top 25 Name,Length From TestData ORDER BY Length DESC" +PS\> Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo1.xlsx -WorkSheetname "Sizes" -AutoSize + + This creates an ODBC connection string to read from an Access file and a SQL Statement to extracts data from it, and sends the resulting data to a new worksheet + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' + +PS\> $Connection = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=$dbPath;" +PS\> $SQL="SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + + " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" + +PS\>Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo2.xlsx -WorkSheetname "Winners" -AutoSize -AutoNameRange -ConditionalFormat @{DataBarColor="Blue"; Range="Wins"} + + Similar to the previous example, this creates a connection string, this time for an Excel file, and runs a SQL statement to get a list of motor-racing results, outputting the resulting data to a new spreadsheet. The spreadsheet is formatted and a data bar added to show make the drivers' wins clearer. (The F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) + + + + -------------------------- EXAMPLE 4 -------------------------- + PS\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' + +PS\> $SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + + " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" +PS\> $null = Get-SQL -Session F1 -excel -Connection $dbPath -sql $sql -OutputVariable Table + +PS\> Send-SQLDataToExcel -DataTable $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show + + This uses Get-SQL (at least V1.1 - download from the PowerShell gallery with Install-Module -Name GetSQL - (note the function is Get-SQL the module is GetSQL without the "-" ) + Get-SQL simplifies making database connections and building /submitting SQL statements. Here Get-SQL uses the same SQL statement as before; -OutputVariable leaves a System.Data.DataTable object in $table and Send-SQLDataToExcel puts $table into the worksheet and sets it as an Excel table. The command is equivalent to running + PS> Export-Excel -inputObject $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show + This is quicker than using PS> Get-SQL <parameters> | export-excel -ExcludeProperty rowerror,rowstate,table,itemarray,haserrors <parameters> + (the F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) + + + + -------------------------- EXAMPLE 5 -------------------------- + PS\>$SQL = "SELECT top 25 DriverName, Count(Win) as Wins FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" +PS\> Send-SQLDataToExcel -Session $DbSessions\["f1"\] -SQL $sql -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -ClearSheet -autosize -ColumnChart + + Like the previous example, this uses Get-SQL (download from the gallery with Install-Module -Name GetSQL). It uses the database session which Get-SQL created, rather than an ODBC connection string. The Session parameter can either be a object (as shown here), or the name used by Get-SQL ("F1" in this case). + Here the data is presented as a quick chart. + + + + -------------------------- EXAMPLE 6 -------------------------- + Send-SQLDataToExcel -path .\demo4.xlsx -WorkSheetname "LR" -Connection "DSN=LR" -sql "SELECT name AS CollectionName FROM AgLibraryCollection Collection ORDER BY CollectionName" + + This example uses an Existing ODBC datasource name "LR" which maps to an adobe lightroom database and gets a list of collection names into a worksheet + + + + + + Export-Excel + + + + + + + Set-ExcelColumn + Set + ExcelColumn + + Adds or modifies a column in an Excel worksheet, filling values, setting formatting and/or creating named ranges. + + + + Set-ExcelColumn can take a value which is either a string containing a value or formula or a scriptblock which evaluates to a string, and optionally a column number and fills that value down the column. + A column heading can be specified, and the column can be made a named range. + The column can be formatted in the same operation. + + + + Set-ExcelColumn + + ExcelPackage + + If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. + + ExcelPackage + + ExcelPackage + + + None + + + Worksheetname + + The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. + + String + + String + + + Sheet1 + + + Column + + Column to fill down - the first column is 1. 0 will be interpreted as first empty column. + + Object + + Object + + + 0 + + + StartRow + + First row to fill data in. + + Int32 + + Int32 + + + 0 + + + Value + + A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional column heading. + + Object + + Object + + + None + + + NumberFormat + + Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Colour for the text - if none specified it will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + + None + Single + Double + SingleAccounting + DoubleAccounting + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or None). + + + None + Baseline + Subscript + Superscript + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - "Solid" by default. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. Default is "General". + + + General + Left + Center + CenterContinuous + Right + Fill + Distributed + Justify + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + + Top + Center + Bottom + Distributed + Justify + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + AutoSize + + Attempt to auto-fit cells to the width their contents. + + + SwitchParameter + + + False + + + Width + + Set cells to a fixed width, ignored if -AutoSize is specified. + + Single + + Single + + + 0 + + + AutoNameRange + + Set the inserted data to be a named range. + + + SwitchParameter + + + False + + + Hide + + Hide the column. + + + SwitchParameter + + + False + + + Specified + + If specified, returns the range of cells which were affected. + + + SwitchParameter + + + False + + + PassThru + + If specified, return an object representing the Column, to allow further work to be done on it. + + + SwitchParameter + + + False + + + + Set-ExcelColumn + + Worksheet + + This passes the worksheet object instead of passing a sheet name and an Excelpackage object. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + Column + + Column to fill down - the first column is 1. 0 will be interpreted as first empty column. + + Object + + Object + + + 0 + + + StartRow + + First row to fill data in. + + Int32 + + Int32 + + + 0 + + + Value + + A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional column heading. + + Object + + Object + + + None + + + NumberFormat + + Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Colour for the text - if none specified it will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + + None + Single + Double + SingleAccounting + DoubleAccounting + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or None). + + + None + Baseline + Subscript + Superscript + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - "Solid" by default. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. Default is "General". + + + General + Left + Center + CenterContinuous + Right + Fill + Distributed + Justify + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + + Top + Center + Bottom + Distributed + Justify + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + AutoSize + + Attempt to auto-fit cells to the width their contents. + + + SwitchParameter + + + False + + + Width + + Set cells to a fixed width, ignored if -AutoSize is specified. + + Single + + Single + + + 0 + + + AutoNameRange + + Set the inserted data to be a named range. + + + SwitchParameter + + + False + + + Hide + + Hide the column. + + + SwitchParameter + + + False + + + Specified + + If specified, returns the range of cells which were affected. + + + SwitchParameter + + + False + + + PassThru + + If specified, return an object representing the Column, to allow further work to be done on it. + + + SwitchParameter + + + False + + + + + + ExcelPackage + + If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. + + ExcelPackage + + ExcelPackage + + + None + + + Worksheetname + + The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. + + String + + String + + + Sheet1 + + + Worksheet + + This passes the worksheet object instead of passing a sheet name and an Excelpackage object. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + Column + + Column to fill down - the first column is 1. 0 will be interpreted as first empty column. + + Object + + Object + + + 0 + + + StartRow + + First row to fill data in. + + Int32 + + Int32 + + + 0 + + + Value + + A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional column heading. + + Object + + Object + + + None + + + NumberFormat + + Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Colour for the text - if none specified it will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + SwitchParameter + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + SwitchParameter + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + SwitchParameter + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + SwitchParameter + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or None). + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - "Solid" by default. + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + SwitchParameter + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. Default is "General". + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + AutoSize + + Attempt to auto-fit cells to the width their contents. + + SwitchParameter + + SwitchParameter + + + False + + + Width + + Set cells to a fixed width, ignored if -AutoSize is specified. + + Single + + Single + + + 0 + + + AutoNameRange + + Set the inserted data to be a named range. + + SwitchParameter + + SwitchParameter + + + False + + + Hide + + Hide the column. + + SwitchParameter + + SwitchParameter + + + False + + + Specified + + If specified, returns the range of cells which were affected. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + If specified, return an object representing the Column, to allow further work to be done on it. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.ExcelColumn + + + + + + + + System.String + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency' + + $ws contains a worksheet object - and column "E" is set to use the local currency format. + Intelisense will complete the names of predefined number formats. + You can see how currency is interpreted on the local computer with the command Expand-NumberFormat currency + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Set-ExcelColumn -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange + + Here, $WS already contains a worksheet which holds counts of races won and fastest laps recorded by racing drivers (in columns C and E). Set-ExcelColumn specifies that Column 7 should have a heading of "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc the new data cells should become a named range, which will also be named "WinsToFastLaps" and the column width will be set automatically. + When a value begins with "=", it is treated as a formula. + If value is a script block it will be evaluated, so here the string "=E$row/C$Row" will have the number of the current row inserted; see the value parameter for a list of variables which can be used. + Note than when evaluating an expression in a string, it is necessary to wrap it in $() so $row is valid but $($row+1) is needed. + To preventVariables merging into other parts of the string, use the back tick "$columnName`4" will be "G4" - without the backtick the string will look for a variable named "columnName4" + + + + -------------------------- EXAMPLE 3 -------------------------- + Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize + + In this example, the worksheet in $ws has partial links to Wikipedia pages in column B. + The -Value parameter is a script block which outputs a string beginning "https..." and ending with the value of the cell at column B in the current row. + When given a valid URI, Set-ExcelColumn makes it a hyperlink. + The column will be autosized to fit the links. + + + + -------------------------- EXAMPLE 4 -------------------------- + 4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange + + Again $ws contains a worksheet. Here columns 4 to 6 are made into named ranges, row 1 is used for the range name and the rest of the column becomes the range. + + + + + + + + Set-ExcelRange + Set + ExcelRange + + Applies number, font, alignment and/or color formatting, values or formulas to a range of Excel cells. + + + + Set-ExcelRange was created to set the style elements for a range of cells, this includes auto-sizing and hiding, setting font elements (Name, Size, Bold, Italic, Underline & UnderlineStyle and Subscript & SuperScript), font and background colors, borders, text wrapping, rotation, alignment within cells, and number format. + It was orignally named "Set-Format", but it has been extended to set Values, Formulas and ArrayFormulas (sometimes called Ctrl-shift-Enter [CSE] formulas); because of this, the name has become Set-ExcelRange but the old name of Set-Format is preserved as an alias. + + + + Set-ExcelRange + + Range + + One or more row(s), Column(s) and/or block(s) of cells to format. + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + NumberFormat + + Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the range. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderColor + + Color of the border. + + Object + + Object + + + [System.Drawing.Color]::Black + + + BorderBottom + + Style for the bottom border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderTop + + Style for the top border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderLeft + + Style for the left border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderRight + + Style for the right border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Colour for the text - if none is specified it will be left as it is. + + Object + + Object + + + None + + + Value + + Value for the cell. + + Object + + Object + + + None + + + Formula + + Formula for the cell. + + Object + + Object + + + None + + + ArrayFormula + + Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). + + + SwitchParameter + + + False + + + ResetFont + + Clear Bold, Italic, StrikeThrough and Underline and set color to Black. + + + SwitchParameter + + + False + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + + None + Single + Double + SingleAccounting + DoubleAccounting + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -Strikethru:$false to remove Strike through + + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or none). + + + None + Baseline + Subscript + Superscript + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - Solid by default. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. default is 'General'. + + + General + Left + Center + CenterContinuous + Right + Fill + Distributed + Justify + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + + Top + Center + Bottom + Distributed + Justify + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + AutoSize + + Autofit cells to width (columns or ranges only). + + + SwitchParameter + + + False + + + Width + + Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. + + Single + + Single + + + 0 + + + Height + + Set cells to a fixed height (rows or ranges only). + + Single + + Single + + + 0 + + + Hidden + + Hide a row or column (not a range); use -Hidden:$false to unhide. + + + SwitchParameter + + + False + + + Locked + + Locks cells. Cells are locked by default use -locked:$false on the whole sheet and then lock specific ones, and enable protection on the sheet. + + + SwitchParameter + + + False + + + Merge + + Merges cells - it is recommended that you explicitly set -HorizontalAlignment + + + SwitchParameter + + + False + + + + + + Range + + One or more row(s), Column(s) and/or block(s) of cells to format. + + Object + + Object + + + None + + + WorkSheet + + The worksheet where the format is to be applied. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + NumberFormat + + Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the range. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderColor + + Color of the border. + + Object + + Object + + + [System.Drawing.Color]::Black + + + BorderBottom + + Style for the bottom border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderTop + + Style for the top border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderLeft + + Style for the left border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderRight + + Style for the right border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Colour for the text - if none is specified it will be left as it is. + + Object + + Object + + + None + + + Value + + Value for the cell. + + Object + + Object + + + None + + + Formula + + Formula for the cell. + + Object + + Object + + + None + + + ArrayFormula + + Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). + + SwitchParameter + + SwitchParameter + + + False + + + ResetFont + + Clear Bold, Italic, StrikeThrough and Underline and set color to Black. + + SwitchParameter + + SwitchParameter + + + False + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + SwitchParameter + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + SwitchParameter + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + SwitchParameter + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -Strikethru:$false to remove Strike through + + SwitchParameter + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or none). + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - Solid by default. + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + SwitchParameter + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. default is 'General'. + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + AutoSize + + Autofit cells to width (columns or ranges only). + + SwitchParameter + + SwitchParameter + + + False + + + Width + + Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. + + Single + + Single + + + 0 + + + Height + + Set cells to a fixed height (rows or ranges only). + + Single + + Single + + + 0 + + + Hidden + + Hide a row or column (not a range); use -Hidden:$false to unhide. + + SwitchParameter + + SwitchParameter + + + False + + + Locked + + Locks cells. Cells are locked by default use -locked:$false on the whole sheet and then lock specific ones, and enable protection on the sheet. + + SwitchParameter + + SwitchParameter + + + False + + + Merge + + Merges cells - it is recommended that you explicitly set -HorizontalAlignment + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NumberFormat "#,###" -AutoFit + + Selects column 3 from a sheet object (within a workbook object, which is a child of the ExcelPackage object) and passes it to Set-ExcelRange which formats numbers as a integers with comma-separated groups, aligns it right, and auto-fits the column to the contents. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Set-ExcelRange -Range $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###" + + Instead of piping the address, this version specifies a block of cells and applies similar formatting. + + + + -------------------------- EXAMPLE 3 -------------------------- + PS\> Set-ExcelRange $excel.Workbook.Worksheets[1].Tables["Processes"] -Italic + + This time instead of specifying a range of cells, a table is selected by name and formatted as italic. + + + + + + + + Set-ExcelRow + Set + ExcelRow + + Fills values into a [new] row in an Excel spreadsheet, and sets row formats. + + + + Set-ExcelRow accepts either a Worksheet object or an ExcelPackage object returned by Export-Excel and the name of a sheet, and inserts the chosen contents into a row of the sheet. + The contents can be a constant, like "42", a formula or a script block which is converted into a constant or a formula. + The first cell of the row can optionally be given a heading. + + + + Set-ExcelRow + + ExcelPackage + + An Excel package object - for example from Export-Excel -PassThru - if specified requires a sheet name to be passed a parameter. + + ExcelPackage + + ExcelPackage + + + None + + + Worksheetname + + The name of the sheet to update in the package. + + Object + + Object + + + Sheet1 + + + Row + + Row to fill right - first row is 1. 0 will be interpreted as first unused row. + + Object + + Object + + + 0 + + + StartColumn + + Position in the row to start from. + + Int32 + + Int32 + + + 0 + + + Value + + Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional row-heading. + + Object + + Object + + + None + + + HeadingBold + + Set the heading in bold type. + + + SwitchParameter + + + False + + + HeadingSize + + Change the font-size of the heading. + + Int32 + + Int32 + + + 0 + + + NumberFormat + + Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderColor + + Color of the border. + + Object + + Object + + + [System.Drawing.Color]::Black + + + BorderBottom + + Style for the bottom border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderTop + + Style for the top border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderLeft + + Style for the left border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderRight + + Style for the right border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Color for the text - if not specified the font will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + + None + Single + Double + SingleAccounting + DoubleAccounting + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or none). + + + None + Baseline + Subscript + Superscript + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - solid by default. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. default is 'General'. + + + General + Left + Center + CenterContinuous + Right + Fill + Distributed + Justify + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + + Top + Center + Bottom + Distributed + Justify + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + Height + + Set cells to a fixed height. + + Single + + Single + + + 0 + + + Hide + + Hide the row. + + + SwitchParameter + + + False + + + ReturnRange + + If sepecified, returns the range of cells which were affected. + + + SwitchParameter + + + False + + + PassThru + + If Specified, return a row object to allow further work to be done. + + + SwitchParameter + + + False + + + + Set-ExcelRow + + Worksheet + + A worksheet object instead of passing a name and package. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + Row + + Row to fill right - first row is 1. 0 will be interpreted as first unused row. + + Object + + Object + + + 0 + + + StartColumn + + Position in the row to start from. + + Int32 + + Int32 + + + 0 + + + Value + + Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional row-heading. + + Object + + Object + + + None + + + HeadingBold + + Set the heading in bold type. + + + SwitchParameter + + + False + + + HeadingSize + + Change the font-size of the heading. + + Int32 + + Int32 + + + 0 + + + NumberFormat + + Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderColor + + Color of the border. + + Object + + Object + + + [System.Drawing.Color]::Black + + + BorderBottom + + Style for the bottom border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderTop + + Style for the top border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderLeft + + Style for the left border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderRight + + Style for the right border. + + + None + Hair + Dotted + DashDot + Thin + DashDotDot + Dashed + MediumDashDotDot + MediumDashed + MediumDashDot + Thick + Medium + Double + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Color for the text - if not specified the font will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + + None + Single + Double + SingleAccounting + DoubleAccounting + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or none). + + + None + Baseline + Subscript + Superscript + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - solid by default. + + + None + Solid + DarkGray + MediumGray + LightGray + Gray125 + Gray0625 + DarkVertical + DarkHorizontal + DarkDown + DarkUp + DarkGrid + DarkTrellis + LightVertical + LightHorizontal + LightDown + LightUp + LightGrid + LightTrellis + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. default is 'General'. + + + General + Left + Center + CenterContinuous + Right + Fill + Distributed + Justify + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + + Top + Center + Bottom + Distributed + Justify + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + Height + + Set cells to a fixed height. + + Single + + Single + + + 0 + + + Hide + + Hide the row. + + + SwitchParameter + + + False + + + ReturnRange + + If sepecified, returns the range of cells which were affected. + + + SwitchParameter + + + False + + + PassThru + + If Specified, return a row object to allow further work to be done. + + + SwitchParameter + + + False + + + + + + ExcelPackage + + An Excel package object - for example from Export-Excel -PassThru - if specified requires a sheet name to be passed a parameter. + + ExcelPackage + + ExcelPackage + + + None + + + Worksheetname + + The name of the sheet to update in the package. + + Object + + Object + + + Sheet1 + + + Worksheet + + A worksheet object instead of passing a name and package. + + ExcelWorksheet + + ExcelWorksheet + + + None + + + Row + + Row to fill right - first row is 1. 0 will be interpreted as first unused row. + + Object + + Object + + + 0 + + + StartColumn + + Position in the row to start from. + + Int32 + + Int32 + + + 0 + + + Value + + Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. + + Object + + Object + + + None + + + Heading + + Optional row-heading. + + Object + + Object + + + None + + + HeadingBold + + Set the heading in bold type. + + SwitchParameter + + SwitchParameter + + + False + + + HeadingSize + + Change the font-size of the heading. + + Int32 + + Int32 + + + 0 + + + NumberFormat + + Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. + + Object + + Object + + + None + + + BorderAround + + Style of border to draw around the row. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderColor + + Color of the border. + + Object + + Object + + + [System.Drawing.Color]::Black + + + BorderBottom + + Style for the bottom border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderTop + + Style for the top border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderLeft + + Style for the left border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + BorderRight + + Style for the right border. + + ExcelBorderStyle + + ExcelBorderStyle + + + None + + + FontColor + + Color for the text - if not specified the font will be left as it it is. + + Object + + Object + + + None + + + Bold + + Make text bold; use -Bold:$false to remove bold. + + SwitchParameter + + SwitchParameter + + + False + + + Italic + + Make text italic; use -Italic:$false to remove italic. + + SwitchParameter + + SwitchParameter + + + False + + + Underline + + Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + + SwitchParameter + + SwitchParameter + + + False + + + UnderLineType + + Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + + ExcelUnderLineType + + ExcelUnderLineType + + + Single + + + StrikeThru + + Strike through text; use -StrikeThru:$false to remove strike through. + + SwitchParameter + + SwitchParameter + + + False + + + FontShift + + Subscript or Superscript (or none). + + ExcelVerticalAlignmentFont + + ExcelVerticalAlignmentFont + + + None + + + FontName + + Font to use - Excel defaults to Calibri. + + String + + String + + + None + + + FontSize + + Point size for the text. + + Single + + Single + + + 0 + + + BackgroundColor + + Change background color. + + Object + + Object + + + None + + + BackgroundPattern + + Background pattern - solid by default. + + ExcelFillStyle + + ExcelFillStyle + + + Solid + + + PatternColor + + Secondary color for background pattern. + + Object + + Object + + + None + + + WrapText + + Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + + SwitchParameter + + SwitchParameter + + + False + + + HorizontalAlignment + + Position cell contents to Left, Right, Center etc. default is 'General'. + + ExcelHorizontalAlignment + + ExcelHorizontalAlignment + + + None + + + VerticalAlignment + + Position cell contents to Top, Bottom or Center. + + ExcelVerticalAlignment + + ExcelVerticalAlignment + + + None + + + TextRotation + + Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + + Int32 + + Int32 + + + 0 + + + Height + + Set cells to a fixed height. + + Single + + Single + + + 0 + + + Hide + + Hide the row. + + SwitchParameter + + SwitchParameter + + + False + + + ReturnRange + + If sepecified, returns the range of cells which were affected. + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + If Specified, return a row object to allow further work to be done. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + OfficeOpenXml.ExcelRow + + + + + + + + System.String + + + + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> Set-ExcelRow -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" } + + $Ws contains a worksheet object, and no Row number is specified so Set-ExcelRow will select the next row after the end of the data in the sheet. + The first cell in the row will contain "Total", and each of the other cells will contain =Sum(xx2:xx99) where xx is the column name, and 99 is the last row of data. + Note the use of the backtick in the script block (`2) to Prevent 2 becoming part of the variable "ColumnName" + The script block can use $Worksheet, $Row, $Column (number), $ColumnName (letter), $StartRow/Column and $EndRow/Column. + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\> Set-ExcelRow -Worksheet $ws -Heading Total -HeadingBold -Value {"=sum($columnName`2:$columnName$endrow)" } -NumberFormat 'Currency' -StartColumn 2 -Bold -BorderTop Double -BorderBottom Thin + + This builds on the previous example, but this time the label "Total" appears in column 2 and the formula fills from column 3 onwards. + The formula and heading are set in bold face, and the formula is formatted for the local currency, and given a double line border above and single line border below. + + + + + + + + Update-FirstObjectProperties + Update + FirstObjectProperties + + Updates the first object to contain all the properties of the object with the most properties in the array. + + + + Updates the first object to contain all the properties found anywhere in the array. + This is usefull when not all objects have the same quantity of properties and CmdLets like Out-GridView or Export-Excel are not able to show all the properties because the first object doesn't have them all. + + + + Update-FirstObjectProperties + + + + + + + + CHANGELOG 2017/06/08 Function born + + + + + -------------------------- EXAMPLE 1 -------------------------- + PS\> $Array = @() +PS\> $Obj1 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' +} +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} +PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Out-GridView -Title 'All properties are visible' + + Updates the first object of the array by adding Member3 and Member4 and shows before and after in gridviews + + + + -------------------------- EXAMPLE 2 -------------------------- + PS\>$ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> $Array = @() +PS\> $Obj1 = [PSCustomObjectable@{ + Member1 = 'First' + Member2 = 'Second' +} +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} +PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorkSheetname Numbers + + Updates the first object of the array by adding property 'Member3' and 'Member4'. Afterwards, all objects are exported to an Excel file and all column headers are visible. + + + + + + https://github.com/dfinke/ImportExcel + https://github.com/dfinke/ImportExcel + + + + \ No newline at end of file diff --git a/mdHelp/Add-ConditionalFormatting.md b/mdHelp/Add-ConditionalFormatting.md new file mode 100644 index 0000000..158fac7 --- /dev/null +++ b/mdHelp/Add-ConditionalFormatting.md @@ -0,0 +1,482 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-ConditionalFormatting + +## SYNOPSIS +Adds conditional formatting to all or part of a worksheet. + +## SYNTAX + +### NamedRule +``` +Add-ConditionalFormatting [-Address] [-WorkSheet ] [-RuleType] [-ForegroundColor ] [-Reverse] [[-ConditionValue] ] [[-ConditionValue2] ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-NumberFormat ] [-Bold] [-Italic] [-Underline] [-StrikeThru] [-StopIfTrue] [-Priority ] [-PassThru] [] +``` + +### DataBar +``` +Add-ConditionalFormatting [-Address] [-WorkSheet ] -DataBarColor [-Priority ] [-PassThru] [] +``` + +### ThreeIconSet +``` +Add-ConditionalFormatting [-Address] [-WorkSheet ] -ThreeIconsSet [-Reverse] [-Priority ] [-PassThru] [] +``` + +### FourIconSet +``` +Add-ConditionalFormatting [-Address] [-WorkSheet ] -FourIconsSet [-Reverse] [-Priority ] [-PassThru] [] +``` + +### FiveIconSet +``` +Add-ConditionalFormatting [-Address] [-WorkSheet ] -FiveIconsSet [-Reverse] [-Priority ] [-PassThru] [] +``` + +## DESCRIPTION +Conditional formatting allows Excel to: + +* Mark cells with icons depending on their value +* Show a databar whose length indicates the value or a two or three color scale where the color indicates the relative value +* Change the color, font, or number format of cells which meet given criteria +Add-ConditionalFormatting allows these parameters to be set; for fine tuning of the rules, the -PassThru switch will return the rule so that you can modify things which are specific to that type of rule, example, the values which correspond to each icon in an Icon-Set. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru + Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "b2:b1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "2003" + Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "i2:i1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "Disabled" + $excel.Workbook.Worksheets[1].Cells["D1:G1048576"].Style.Numberformat.Format = [cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern + $excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true + $excel.Save() ; $excel.Dispose() +``` + +Here Export-Excel is called with the -PassThru parameter, so the ExcelPackage object representing Machines.XLSX is stored in $Excel.The desired worksheet is selected, and then columns" B" and "I" are conditionally formatted (excluding the top row) to show red text if they contain "2003" or "Disabled" respectively. + +A fixed date format is then applied to columns D to G, and the top row is formatted. + +Finally the workbook is saved and the Excel package object is closed. + +### EXAMPLE 2 +``` +PS\> $r = Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Range "B1:B100" -ThreeIconsSet Flags -Passthru + $r.Reverse = $true ; $r.Icon1.Type = "Num"; $r.Icon2.Type = "Num" ; $r.Icon2.value = 100 ; $r.Icon3.type = "Num" ;$r.Icon3.value = 1000 +``` + + +Again Export-Excel has been called with -PassThru leaving a package object in $Excel. + +This time B1:B100 has been conditionally formatted with 3 icons, using the "Flags" Icon-Set. + +Add-ConditionalFormatting does not provide accessto every option in the formatting rule, so -PassThru has been used and the rule is modified to apply the flags in reverse order, and transitions between flags are set to 100 and 1000. + +### EXAMPLE 3 +``` +PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red +``` + +This time $sheet holds an ExcelWorkshseet object and databars are added to column D, excluding the top row. + +### EXAMPLE 4 +``` +PS\> Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue +``` + +In this example a named range is used to select the cells where the condition should apply, and instead of specifying a sheet and range within the sheet as separate parameters, the cells where the format should apply are specified directly. + +If a cell in the "FinishPosition" range is 1, then the text is turned to Bold & Purple. + +This rule is moved to first in the priority list, and where cells have a value of 1, no other rules will be processed. + +### EXAMPLE 5 +``` +PS\> $excel = Get-ChildItem | Select-Object -Property Name,Length,LastWriteTime,CreationTime | Export-Excel "$env:temp\test43.xlsx" -PassThru -AutoSize + $ws = $excel.Workbook.Worksheets["Sheet1"] + $ws.Cells["E1"].Value = "SavedAt" + $ws.Cells["F1"].Value = [datetime]::Now + $ws.Cells["F1"].Style.Numberformat.Format = (Expand-NumberFormat -NumberFormat 'Date-Time') + $lastRow = $ws.Dimension.End.Row + Add-ConditionalFormatting -WorkSheet $ws -address "A2:A$Lastrow" -RuleType LessThan -ConditionValue "A" -ForeGroundColor Gray + Add-ConditionalFormatting -WorkSheet $ws -address "B2:B$Lastrow" -RuleType GreaterThan -ConditionValue 1000000 -NumberFormat '#,###,,.00"M"' + Add-ConditionalFormatting -WorkSheet $ws -address "C2:C$Lastrow" -RuleType GreaterThan -ConditionValue "=INT($F$1-7)" -ForeGroundColor Green -StopIfTrue + Add-ConditionalFormatting -WorkSheet $ws -address "D2:D$Lastrow" -RuleType Equal -ConditionValue "=C2" -ForeGroundColor Blue -StopIfTrue + Close-ExcelPackage -Show $excel +``` +The first few lines of code export a list of file and directory names, sizes and dates to a spreadsheet. + +It puts the date of the export in cell F1. + +The first Conditional format changes the color of files and folders that begin with a ".", "_" or anything else which sorts before "A". + +The second Conditional format changes the Number format of numbers bigger than 1 million, for example 1,234,567,890 will dispay as "1,234.57M" + +The third highlights datestamps of files less than a week old when the export was run; the = is necessary in the condition value otherwise the rule will look for the the text INT($F$1-7), and the cell address for the date is fixed using the standard Excel $ notation. + +The final Conditional format looks for files which have not changed since they were created. Here the condition value is "=C2". The = sign means C2 is treated as a formula, not literal text. Unlike the file age, we want the cell used to change for each cell where the conditional format applies. + +The first cell in the conditional format range is D2, which is compared against C2, then D3 is compared against C3 and so on. +A common mistake is to include the title row in the range and accidentally apply conditional formatting to it, or to begin the +range at row 2 but use row 1 as the starting point for comparisons. + +### EXAMPLE 6 +``` +PS\> Add-ConditionalFormatting $ws.Cells["B:B"] GreaterThan 10000000 -Fore Red -Stop -Pri 1 +``` + +This version shows the shortest syntax - the Address, Ruletype, and Conditionvalue can be identified from their position, and ForegroundColor, +StopIfTrue and Priority can all be shortend. + +## PARAMETERS + +### -Address +A block of cells to format - you can use a named range with -Address $ws.names\[1\] or $ws.cells\["RangeName"\] + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Range + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheet +The worksheet where the format is to be applied + +```yaml +Type: ExcelWorksheet +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RuleType +A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc. + +```yaml +Type: eExcelConditionalFormattingRuleType +Parameter Sets: NamedRule +Aliases: +Accepted values: AboveAverage, AboveOrEqualAverage, BelowAverage, BelowOrEqualAverage, AboveStdDev, BelowStdDev, Bottom, BottomPercent, Top, TopPercent, Last7Days, LastMonth, LastWeek, NextMonth, NextWeek, ThisMonth, ThisWeek, Today, Tomorrow, Yesterday, BeginsWith, Between, ContainsBlanks, ContainsErrors, ContainsText, DuplicateValues, EndsWith, Equal, Expression, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, NotBetween, NotContains, NotContainsBlanks, NotContainsErrors, NotContainsText, NotEqual, UniqueValues, ThreeColorScale, TwoColorScale, ThreeIconSet, FourIconSet, FiveIconSet, DataBar + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ForegroundColor +Text color for matching objects + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: ForegroundColour, FontColor + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataBarColor +Color for databar type charts + +```yaml +Type: Object +Parameter Sets: DataBar +Aliases: DataBarColour + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ThreeIconsSet +One of the three-icon set types (e.g. +Traffic Lights) + +```yaml +Type: eExcelconditionalFormatting3IconsSetType +Parameter Sets: ThreeIconSet +Aliases: +Accepted values: Arrows, ArrowsGray, Flags, Signs, Symbols, Symbols2, TrafficLights1, TrafficLights2 + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FourIconsSet +A four-icon set name + +```yaml +Type: eExcelconditionalFormatting4IconsSetType +Parameter Sets: FourIconSet +Aliases: +Accepted values: Arrows, ArrowsGray, Rating, RedToBlack, TrafficLights + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FiveIconsSet +A five-icon set name + +```yaml +Type: eExcelconditionalFormatting5IconsSetType +Parameter Sets: FiveIconSet +Aliases: +Accepted values: Arrows, ArrowsGray, Quarters, Rating + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Reverse +Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule, ThreeIconSet, FourIconSet, FiveIconSet +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionValue +A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" ) + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionValue2 +A second value for the conditions like "Between X and Y" + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +Background color for matching items + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundPattern +Background pattern for matching items + +```yaml +Type: ExcelFillStyle +Parameter Sets: NamedRule +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternColor +Secondary color when a background pattern requires it + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumberFormat +Sets the numeric format for matching items + +```yaml +Type: Object +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Bold +Put matching items in bold face + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Italic +Put matching items in italic + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Underline +Underline matching items + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StrikeThru +Strikethrough text of matching items + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StopIfTrue +Prevent the processing of subsequent rules + +```yaml +Type: SwitchParameter +Parameter Sets: NamedRule +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Priority +Set the sequence for rule processing + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If specified pass the rule back to the caller to allow additional customization. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-ExcelChart.md b/mdHelp/Add-ExcelChart.md new file mode 100644 index 0000000..371661e --- /dev/null +++ b/mdHelp/Add-ExcelChart.md @@ -0,0 +1,736 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-ExcelChart + +## SYNOPSIS +Creates a chart in an existing Excel worksheet. + +## SYNTAX + +### Worksheet (Default) +``` +Add-ExcelChart [-Title ] [-ChartType ] [-ChartTrendLine ] [-XRange ] [-YRange ] [-Width ] [-Height ] [-Row ] [-RowOffSetPixels ] [-Column ] [-ColumnOffSetPixels ] [-LegendPosition ] [-LegendSize ] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-SeriesHeader ] [-TitleBold] [-TitleSize ] [-XAxisTitleText ] [-XAxisTitleBold] [-XAxisTitleSize ] [-XAxisNumberformat ] [-XMajorUnit ] [-XMinorUnit ] [-XMaxValue ] [-XMinValue ] [-XAxisPosition ] [-YAxisTitleText ] [-YAxisTitleBold] [-YAxisTitleSize ] [-YAxisNumberformat ] [-YMajorUnit ] [-YMinorUnit ] [-YMaxValue ] [-YMinValue ] [-YAxisPosition ] [-PassThru] [] +``` + +### PivotTable +``` +Add-ExcelChart -PivotTable [-Title ] [-ChartType ] [-ChartTrendLine ] [-XRange ] [-YRange ] [-Width ] [-Height ] [-Row ] [-RowOffSetPixels ] [-Column ] [-ColumnOffSetPixels ] [-LegendPosition ] [-LegendSize ] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-SeriesHeader ] [-TitleBold] [-TitleSize ] [-XAxisTitleText ] [-XAxisTitleBold] [-XAxisTitleSize ] [-XAxisNumberformat ] [-XMajorUnit ] [-XMinorUnit ] [-XMaxValue ] [-XMinValue ] [-XAxisPosition ] [-YAxisTitleText ] [-YAxisTitleBold] [-YAxisTitleSize ] [-YAxisNumberformat ] [-YMajorUnit ] [-YMinorUnit ] [-YMaxValue ] [-YMinValue ] [-YAxisPosition ] [-PassThru] [] +``` + +## DESCRIPTION +Creates a chart. + +It is possible to configure the type of chart, the range of X values (labels) and Y values, the title, the legend, the ranges for both axes, the format and position of the axes. + +Normally the command does not return anything, but if -passthru is specified the chart is returned so that it can be customized. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $Excel = ConvertFrom-Csv @" + Product, City, Sales + Apple, London, 300 + Orange, London, 400 + Banana, London, 300 + Orange, Paris, 600 + Banana, Paris, 300 + Apple, New York, 1200 +"@ | Export-Excel -Path test.xlsx -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -ChartType "Doughnut" -XRange "A2:B7" -YRange "C2:C7" -width 500 + Close-ExcelPackage -Show $Excel +``` + +The first command expands a multi-line string into 6 rows of data which is exported to new Excel file; leaving an ExcelPackage object in $excel +The second command adds a chart - the cell ranges are explicitly specified. + +Note that the XRange (labels) is TWO columns wide and the chart will combine the name of the product and the name of the City to create the label. + +The width of the chart is set explictly, the default legend is used and there is no Chart title. + +### EXAMPLE 2 +``` +PS\> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel $path -AutoSize -ExcelChartDefinition $c -AutoNameRange -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title "VM use" -ChartType PieExploded3D -XRange "Name" -YRange "VirtualMemorySize" -NoLegend -ShowCategory + Close-ExcelPackage $Excel -Show +``` + +The first line exports information and creates named ranges for each column. + +The Second line uses the ranges to specify a chart - the labels come from the range "Name" and the data from the range "VirtualMemorySize" + +The chart is specified as a 3D exploded PIE chart, with a title of "VM Use" and instead of a legend the the pie slices are identified with a label. + +### EXAMPLE 3 +``` +PS\> $Excel = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize | Export-Excel test.xlsx -TableName Processes -PassThru + Add-ExcelChart -Worksheet $Excel.Workbook.Worksheets[1] -Title Stats -ChartType LineMarkersStacked -XRange "Processes[Name]" -YRange "Processes[PM]", "Processes[VirtualMemorySize]" -SeriesHeader 'PM', 'VMSize' + Close-ExcelPackage $Excel -Show +``` + +The first line exports information to a table in new file; and captures the excel Package object in $Excel + +The second line creates a chart on the first page of the work sheet, using the notation "TableName[ColumnnName]" to refer to the data, the labels come Name column in the table, and the data series from its PM and VirtualMemorySize columns. +The display names for these in the header are set to 'PM' and 'VMSize'. + +### EXAMPLE 4 +``` +PS\> $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path Text.xlsx -WorkSheetname SinX -PassThru +Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 \` + -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" \` + -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 \` + -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom +Close-ExcelPackage $Excel -Show + +``` + + +The first line puts numbers from 0 to 360 into a sheet, as the first column, and a formula to calculate the Sine of that number of number of degrees in the second column. It creates named-ranges for the two columns - "X" and "SinX" respectively + +The Add-ExcelChart command adds a chart to that worksheet, specifying a line chart with the X values coming from named-range "X" and the Y values coming from named-range "SinX". The chart has a title, and is positioned to the right of column 2 and sized 800 pixels wide + +The X-axis is labelled "Degrees", in bold 12 point type and runs from 0 to 361 with labels every 30, and minor tick marks every 10. Degrees are shown padded to 3 digits. + +The Y-axis is labelled "Sine" and to allow some room above and below its scale runs from -1.25 to 1.25, and is marked off in units of 0.25 shown to two decimal places. + +The key will for the chart will be at the bottom in 8 point bold type and the line will be named "Sin(x)". + +## PARAMETERS + +### -Worksheet +An existing Sheet where the chart will be created. + +```yaml +Type: ExcelWorksheet +Parameter Sets: Workshet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTable +Instead of specify X and Y ranges, get data from a PivotTable by passing a PivotTable Object. + +```yaml +Type: ExcelPivotTable +Parameter Sets: PivotTable +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Title +The title for the chart. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartType +One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. +Defaults to "ColumnStacked". + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: Named +Default value: ColumnStacked +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartTrendLine +{{ Fill ChartTrendLine Description }} + +```yaml +Type: eTrendLine[] +Parameter Sets: (All) +Aliases: +Accepted values: Exponential, Linear, Logarithmic, MovingAvgerage, Polynomial, Power + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XRange +The range of cells containing values for the X-Axis - usually labels. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YRange +The range(s) of cells holding values for the Y-Axis - usually "data". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Width +Width of the chart in Pixels; defaults to 500. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 500 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Height +Height of the chart in Pixels; defaults to 350. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 350 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Row +Row position of the top left corner of the chart. ) places at the top of the sheet, 1 below row 1 and so on. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RowOffSetPixels +Offset to position the chart by a fraction of a row. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 10 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Column +Column position of the top left corner of the chart; 0 places at the edge of the sheet 1 to the right of column A and so on. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 6 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ColumnOffSetPixels +Offset to position the chart by a fraction of a column. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 5 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendPosition +Location of the key, either left, right, top, bottom or TopRight. + +```yaml +Type: eLegendPosition +Parameter Sets: (All) +Aliases: +Accepted values: Top, Left, Right, Bottom, TopRight + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendSize +Font size for the key. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendBold +Sets the key in bold type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +If specified, turns of display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +Attaches a category label, in charts which support this. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +Attaches a percentage label, in charts which support this. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SeriesHeader +Specify explicit name(s) for the data series, which will appear in the legend/key. The contents of a cell can be specified in the from =Sheet9!Z10 . + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBold +Sets the title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleSize +Sets the point size for the title. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleText +Specifies a title for the X-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleBold +Sets the X-axis title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleSize +Sets the font size for the axis title. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisNumberformat +A number formatting string, like "#,##0.00", for numbers along the X-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMajorUnit +Spacing for the major gridlines / tick marks along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMinorUnit +Spacing for the minor gridlines / tick marks along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMaxValue +Maximum value for the scale along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMinValue +Minimum value for the scale along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisPosition +Position for the X-axis (Top or Bottom). + +```yaml +Type: eAxisPosition +Parameter Sets: (All) +Aliases: +Accepted values: Left, Bottom, Right, Top + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleText +Specifies a title for the Y-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleBold +Sets the Y-axis title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleSize +Sets the font size for the Y-axis title + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisNumberformat +A number formatting string, like "#,##0.00", for numbers on the Y-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMajorUnit +Spacing for the major gridlines / tick marks on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMinorUnit +Spacing for the minor gridlines / tick marks on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMaxValue +Maximum value on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMinValue +Minimum value on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisPosition +Position for the Y-axis (Left or Right). + +```yaml +Type: eAxisPosition +Parameter Sets: (All) +Aliases: +Accepted values: Left, Bottom, Right, Top + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Add-Excel chart doesn't normally return anything, but if -PassThru is specified it returns the newly created chart to allow it to be fine tuned. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.Drawing.Chart.ExcelChart +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-ExcelDataValidationRule.md b/mdHelp/Add-ExcelDataValidationRule.md new file mode 100644 index 0000000..af06331 --- /dev/null +++ b/mdHelp/Add-ExcelDataValidationRule.md @@ -0,0 +1,319 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-ExcelDataValidationRule + +## SYNOPSIS +Adds data validation to a range of cells + +## SYNTAX + +``` +Add-ExcelDataValidationRule [[-Range] ] [-WorkSheet ] [-ValidationType ] [-Operator ] [-Value ] [-Value2 ] [-Formula ] [-Formula2 ] [-ValueSet ] [-ShowErrorMessage] [-ErrorStyle ] [-ErrorTitle ] [-ErrorBody ] [-ShowPromptMessage] [-PromptBody ] [-PromptTitle ] [-NoBlank ] [] +``` + +## DESCRIPTION +Excel supports the validation of user input, and ranges of cells can be marked to only contain numbers, or date, or Text up to a particular length, or selections from a list. This command adds validation rules to a worksheet. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'E2:E1001' -ValidationType Integer -Operator between -Value 0 -Value2 100 \` + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'Percentage must be a whole number between 0 and 100' +``` + +This defines a validation rule on cells E2-E1001; it is an integer rule and requires a number between 0 and 100. If a value is input with a fraction, negative number, or positive number \> 100 a stop dialog box appears. + +### EXAMPLE 2 +``` +PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'B2:B1001' -ValidationType List -Formula 'values!$a$2:$a$1000' + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody 'You must select an item from the list' +``` + +This defines a list rule on Cells B2:1001, and the posible values are in a sheet named "values" at cells A2 to A1000 Blank cells in this range are ignored. + +If $ signs were left out of the fomrmula B2 would be checked against A2-A1000, B3, against A3-A1001, B4 against A4-A1002 up to B1001 beng checked against A1001-A1999 + +### EXAMPLE 3 +``` +PS\>Add-ExcelDataValidationRule -WorkSheet $PlanSheet -Range 'I2:N1001' -ValidationType List -ValueSet @('yes','YES','Yes') + -ShowErrorMessage -ErrorStyle stop -ErrorTitle 'Invalid Data' -ErrorBody "Select Yes or leave blank for no" +``` + + Similar to the previous example but this time provides a value set; Excel comparisons are case sesnsitive, hence 3 versions of Yes. + +## PARAMETERS + +### -Range +The range of cells to be validate, for example, "B2:C100" + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Address + +Required: False +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -WorkSheet +The worksheet where the cells should be validated + +```yaml +Type: ExcelWorksheet +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ValidationType +An option corresponding to a choice from the 'Allow' pull down on the settings page in the Excel dialog. "Any" means "any allowed" - in other words, no Validation + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Operator +The operator to apply to Decimal, Integer, TextLength, DateTime and time fields, for example "equal" or "between" + +```yaml +Type: ExcelDataValidationOperator +Parameter Sets: (All) +Aliases: +Accepted values: between, notBetween, equal, notEqual, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual + +Required: False +Position: Named +Default value: Equal +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +For Decimal, Integer, TextLength, DateTime the \[first\] data value + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value2 +When using the between operator, the second data value + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Formula +The \[first\] data value as a formula. +Use absolute formulas $A$1 if (e.g.) you want all cells to check against the same list + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Formula2 +When using the between operator, the second data value as a formula + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ValueSet +When using the list validation type, a set of values (rather than refering to Sheet!B$2:B$100 ) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowErrorMessage +Corresponds to the the 'Show Error alert ...' check box on error alert page in the Excel dialog + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ErrorStyle +Stop, Warning, or Infomation, corresponding to to the style setting in the Excel dialog + +```yaml +Type: ExcelDataValidationWarningStyle +Parameter Sets: (All) +Aliases: +Accepted values: undefined, stop, warning, information + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ErrorTitle +The title for the message box corresponding to to the title setting in the Excel dialog + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ErrorBody +The error message corresponding to to the Error message setting in the Excel dialog + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPromptMessage +Corresponds to the the 'Show Input message ...' check box on input message page in the Excel dialog + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PromptBody +The prompt message corresponding to to the Input message setting in the Excel dialog + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PromptTitle +The title for the message box corresponding to to the title setting in the Excel dialog + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoBlank +By default the 'Ignore blank' option will be selected, unless NoBlank is sepcified. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-ExcelName.md b/mdHelp/Add-ExcelName.md new file mode 100644 index 0000000..df1eb37 --- /dev/null +++ b/mdHelp/Add-ExcelName.md @@ -0,0 +1,72 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-ExcelName + +## SYNOPSIS +Adds a named-range to an existing Excel worksheet. + +## SYNTAX + +``` +Add-ExcelName [-Range] [[-RangeName] ] [] +``` + +## DESCRIPTION +It is often helpful to be able to refer to sets of cells with a name rather than using their co-ordinates; Add-ExcelName sets up these names. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $rangeName +``` + +$WS is a worksheet, and $dataRange is a string describing a range of cells - for example "A1:Z10" - which will become a named range, using the name in $rangeName. + +## PARAMETERS + +### -Range +The range of cells to assign as a name. + +```yaml +Type: ExcelRange +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RangeName +The name to assign to the range. If the name exists it will be updated to the new range. If no name is specified, the first cell in the range will be used as the name. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-ExcelTable.md b/mdHelp/Add-ExcelTable.md new file mode 100644 index 0000000..200ad0d --- /dev/null +++ b/mdHelp/Add-ExcelTable.md @@ -0,0 +1,236 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-ExcelTable + +## SYNOPSIS +Adds Tables to Excel workbooks. + +## SYNTAX + +``` +Add-ExcelTable [-Range] [[-TableName] ] [[-TableStyle] ] [-ShowHeader] [-ShowFilter] [-ShowTotal] [[-TotalSettings] ] [-ShowFirstColumn] [-ShowLastColumn] [-ShowRowStripes] [-ShowColumnStripes] [-PassThru] [] +``` + +## DESCRIPTION +Unlike named ranges, where the name only needs to be unique within a sheet, Table names must be unique in the workbook. + +Tables carry formatting and by default have a filter. + +The filter, header, totals, first and last column highlights can all be configured. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName +``` + +$WS is a worksheet, and $dataRange is a string describing a range of cells - for example "A1:Z10". This range which will become a table, named $TableName + +### EXAMPLE 2 +``` +PS\> Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName Musictable -ShowFilter:$false -ShowTotal -ShowFirstColumn +``` + +Again $ws is a worksheet, range here is the whole of the active part of the worksheet. +The table style and name are set, the filter is turned off, and a "Totals" row added, and first column is set in bold. + +## PARAMETERS + +### -Range +The range of cells to assign to a table. + +```yaml +Type: ExcelRange +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableName +The name for the Table - this should be unqiue in the Workbook - auto generated names will be used if this is left empty. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableStyle +The Style for the table, by default "Medium6" is used + +```yaml +Type: TableStyles +Parameter Sets: (All) +Aliases: +Accepted values: None, Custom, Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9, Light10, Light11, Light12, Light13, Light14, Light15, Light16, Light17, Light18, Light19, Light20, Light21, Medium1, Medium2, Medium3, Medium4, Medium5, Medium6, Medium7, Medium8, Medium9, Medium10, Medium11, Medium12, Medium13, Medium14, Medium15, Medium16, Medium17, Medium18, Medium19, Medium20, Medium21, Medium22, Medium23, Medium24, Medium25, Medium26, Medium27, Medium28, Dark1, Dark2, Dark3, Dark4, Dark5, Dark6, Dark7, Dark8, Dark9, Dark10, Dark11 + +Required: False +Position: 3 +Default value: Medium6 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowHeader +By default the header row is shown - it can be turned off with -ShowHeader:$false. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowFilter +By default the filter is enabled - it can be turned off with -ShowFilter:$false. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowTotal +Show total adds a totals row. This does not automatically sum the columns but provides a drop-down in each to select sum, average etc + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TotalSettings +A HashTable in the form ColumnName = "Average"|"Count"|"CountNums"|"Max"|"Min"|"None"|"StdDev"|"Sum"|"Var" - if specified, -ShowTotal is not needed. + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowFirstColumn +Highlights the first column in bold. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowLastColumn +Highlights the last column in bold. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowRowStripes +By default the table formats show striped rows, the can be turned off with -ShowRowStripes:$false + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowColumnStripes +Turns on column stripes. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If -PassThru is specified, the table object will be returned to allow additional changes to be made. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.Table.ExcelTable +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-PivotTable.md b/mdHelp/Add-PivotTable.md new file mode 100644 index 0000000..7f4f1cd --- /dev/null +++ b/mdHelp/Add-PivotTable.md @@ -0,0 +1,659 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-PivotTable + +## SYNOPSIS +Adds a PivotTable (and optional PivotChart) to a workbook. + +## SYNTAX + +### ChartbyParams (Default) +``` +Add-PivotTable -PivotTableName [-Address ] [-ExcelPackage ] [-SourceWorkSheet ] [-SourceRange ] [-PivotRows ] [-PivotData ] [-PivotColumns ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTotals ] [-NoTotalsInPivot] [-GroupDateRow ] [-GroupDatePart ] [-GroupNumericRow ] [-GroupNumericMin ] [-GroupNumericMax ] [-GroupNumericInterval ] [-PivotNumberFormat ] [-PivotTableStyle ] [-IncludePivotChart] [-ChartTitle ] [-ChartHeight ] [-ChartWidth ] [-ChartRow ] [-ChartColumn ] [-ChartRowOffSetPixels ] [-ChartColumnOffSetPixels ] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-Activate] [-PassThru] [] +``` + +### ChartbyDef +``` +Add-PivotTable -PivotTableName [-Address ] [-ExcelPackage ] [-SourceWorkSheet ] [-SourceRange ] [-PivotRows ] [-PivotData ] [-PivotColumns ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTotals ] [-NoTotalsInPivot] [-GroupDateRow ] [-GroupDatePart ] [-GroupNumericRow ] [-GroupNumericMin ] [-GroupNumericMax ] [-GroupNumericInterval ] [-PivotNumberFormat ] [-PivotTableStyle ] -PivotChartDefinition [-Activate] [-PassThru] [] +``` + +## DESCRIPTION +If the PivotTable already exists, the source data will be updated. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $excel = Get-Service | Export-Excel -Path test.xlsx -WorksheetName Services -PassThru -AutoSize -DisplayPropertySet -TableName ServiceTable -Title "Services on $Env:COMPUTERNAME" + Add-PivotTable -ExcelPackage $excel -PivotTableName ServiceSummary -SourceRange $excel.Workbook.Worksheets\[1\].Tables\[0\].Address -PivotRows Status -PivotData Name -NoTotalsInPivot -Activate + Close-ExcelPackage $excel -Show +``` + + +This exports data to new workbook and creates a table with the data in it. + +The Pivot table is added on its own page, the table created in the first command is used as the source for the PivotTable; which counts the service names in for each Status. + +At the end the Pivot page is made active. + +### EXAMPLE 2 +``` +PS\> $chartdef = New-ExcelChartDefinition -Title "Gross and net by city and product" -ChartType ColumnClustered ` + -Column 11 -Width 500 -Height 360 -YMajorUnit 500 -YMinorUnit 100 -YAxisNumberformat "$#,##0" -LegendPosition Bottom + $excel = ConvertFrom-Csv @" +Product, City, Gross, Net +Apple, London , 300, 250 +Orange, London , 400, 350 +Banana, London , 300, 200 +Orange, Paris, 600, 500 +Banana, Paris, 300, 200 +Apple, New York, 1200,700 +"@ | Export-Excel -Path "test.xlsx" -TableStyle Medium13 -tablename "RawData" -PassThru + Add-PivotTable -PivotTableName Sales -Address $excel.Workbook.Worksheets[1].Cells["F1"] ` + -SourceWorkSheet $excel.Workbook.Worksheets[1] -PivotRows City -PivotColumns Product -PivotData @{Gross="Sum";Net="Sum"} ` + -PivotNumberFormat "$#,##0.00" -PivotTotals Both -PivotTableStyle Medium12 -PivotChartDefinition $chartdef + Close-ExcelPackage -show $excel +``` + +This script starts by defining a chart. + +Then it exports some data to an XLSX file and keeps the file open. + +The next step is to add the pivot table, normally this would be on its own sheet in the workbook, but here -Address is specified to place it beside the data. + +The Add-Pivot table is given the chart definition and told to create a tale using the City field to create rows, the Product field to create columns and the data should be the sum of the gross field and the sum of the net field; grand totals for both gross and net are included for rows (Cities) and columns (Products) and the data is explicitly formatted as a currency. + +Note that in the chart definition the number format for the axis does not include any fraction part. + +### EXAMPLE 3 +``` +PS> $excel = Convertfrom-csv @" +Location,OrderDate,quantity +Boston,1/1/2017,100 +New York,1/21/2017,200 +Boston,1/11/2017,300 +New York,1/9/2017,400 +Boston,1/18/2017,500 +Boston,2/1/2017,600 +New York,2/21/2017,700 +New York,2/11/2017,800 +Boston,2/9/2017,900 +Boston,2/18/2017,1000 +New York,1/1/2018,100 +Boston,1/21/2018,200 +New York,1/11/2018,300 +Boston,1/9/2018,400 +New York,1/18/2018,500 +Boston,2/1/2018,600 +Boston,2/21/2018,700 +New York,2/11/2018,800 +New York,2/9/2018,900 +Boston,2/18/2018,1000 +"@ | Select-Object -Property @{n="OrderDate";e={[datetime]::ParseExact($_.OrderDate,"M/d/yyyy",(Get-Culture))}}, + Location, Quantity | Export-Excel "test2.xlsx" -PassThru -AutoSize + Set-ExcelColumn -Worksheet $excel.sheet1 -Column 1 -NumberFormat 'Short Date' + $pt = Add-PivotTable -PassThru -PivotTableName "ByDate" -Address $excel.Sheet1.cells["F1"] -SourceWorkSheet $excel.Sheet1 -PivotRows location,orderdate -PivotData @{'quantity'='sum'} -GroupDateRow orderdate -GroupDatePart 'Months,Years' -PivotTotals None + $pt.RowFields[0].SubtotalTop=$false + $pt.RowFields[0].Compact=$false + Close-ExcelPackage $excel -Show +``` + + +Here the data contains dates formatted as strings using US format. + +These are converted to DateTime objects before being exported to Excel; the "OrderDate" column is formatted with the local short-date style. + +Then the PivotTable is added; it groups information by date and location, the date is split into years and then months. + +No grand totals are displayed. + +The Pivot table object is caught in a variable, and the "Location" column has its subtotal moved from the top to the bottom of each location section, and the "Compact" option is disabled to prevent "Year" moving into the same column as location. + +Finally the workbook is saved and shown in Excel. + +## PARAMETERS + +### -PivotTableName +Name for the new PivotTable - this will be the name of a sheet in the Workbook. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Address +By default, a PivotTable will be created on its own sheet, but it can be created on an existing sheet by giving the address where the top left corner of the table should go. (Allow two rows for the filter if one is used.) + +```yaml +Type: ExcelAddressBase +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelPackage +An Excel-package object for the workbook. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SourceWorkSheet +Worksheet where the data is found. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SourceRange +Address range in the worksheet e.g "A10:F20" - the first row must be column names: if not specified the whole sheet will be used. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotRows +Fields to set as rows in the PivotTable. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotData +A hash table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotColumns +Fields to set as columns in the PivotTable. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotFilter +Fields to use to filter in the PivotTable. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotDataToColumn +If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTotals +Define whether totals should be added to rows, columns neither, or both (the default is both). + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Both +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoTotalsInPivot +Included for compatibility - equivalent to -PivotTotals "None". + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupDateRow +The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupDatePart +The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + +```yaml +Type: eDateGroupBy[] +Parameter Sets: (All) +Aliases: +Accepted values: Years, Quarters, Months, Days, Hours, Minutes, Seconds + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericRow +The name of a row field which should be grouped by Number (e.g. 0-99, 100-199, 200-299 ) + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericMin +The starting point for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericMax +The endpoint for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1.79769313486232E+308 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericInterval +The interval for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 100 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotNumberFormat +Number format to apply to the data cells in the PivotTable. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTableStyle +Apply a table style to the PivotTable. + +```yaml +Type: TableStyles +Parameter Sets: (All) +Aliases: +Accepted values: None, Custom, Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9, Light10, Light11, Light12, Light13, Light14, Light15, Light16, Light17, Light18, Light19, Light20, Light21, Medium1, Medium2, Medium3, Medium4, Medium5, Medium6, Medium7, Medium8, Medium9, Medium10, Medium11, Medium12, Medium13, Medium14, Medium15, Medium16, Medium17, Medium18, Medium19, Medium20, Medium21, Medium22, Medium23, Medium24, Medium25, Medium26, Medium27, Medium28, Dark1, Dark2, Dark3, Dark4, Dark5, Dark6, Dark7, Dark8, Dark9, Dark10, Dark11 + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotChartDefinition +Use a chart definition instead of specifying chart settings one by one. + +```yaml +Type: Object +Parameter Sets: ChartbyDef +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -IncludePivotChart +If specified, a chart will be included. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartTitle +Optional title for the pivot chart, by default the title omitted. + +```yaml +Type: String +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartHeight +Height of the chart in Pixels (400 by default). + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 400 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartWidth +Width of the chart in Pixels (600 by default). + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 600 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartRow +Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartColumn +Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E). + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 4 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartRowOffSetPixels +Vertical offset of the chart from the cell corner. + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartColumnOffSetPixels +Horizontal offset of the chart from the cell corner. + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartType +Type of chart; defaults to "Pie". + +```yaml +Type: eChartType +Parameter Sets: ChartbyParams +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: Named +Default value: Pie +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +If specified hides the chart legend. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +If specified attaches percentages to slices in a pie chart. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Activate +If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Return the PivotTable so it can be customized. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.Table.PivotTable.ExcelPivotTable +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Add-WorkSheet.md b/mdHelp/Add-WorkSheet.md new file mode 100644 index 0000000..9586c2c --- /dev/null +++ b/mdHelp/Add-WorkSheet.md @@ -0,0 +1,248 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Add-WorkSheet + +## SYNOPSIS +Adds a worksheet to an existing workbook. + +## SYNTAX + +### Package +``` +Add-WorkSheet [-ExcelPackage] [-WorksheetName ] [-ClearSheet] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-Activate] [-CopySource ] [-NoClobber] [] +``` + +### WorkBook +``` +Add-WorkSheet -ExcelWorkbook [-WorksheetName ] [-ClearSheet] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-Activate] [-CopySource ] [-NoClobber] [] +``` + +## DESCRIPTION +If the named worksheet already exists, the -Clearsheet parameter decides whether it should be deleted and a new one returned, +or if not specified the existing sheet will be returned. + +By default the sheet is created at the end of the work book, the -MoveXXXX switches allow the sheet to be \[re\]positioned at the start or before or after another sheet. + +A new sheet will only be made the default sheet when excel opens if -Activate is specified. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $WorksheetActors = $ExcelPackage | Add-WorkSheet -WorkSheetname Actors +``` + +$ExcelPackage holds an Excel package object (returned by Open-ExcelPackage, or Export-Excel -passthru). +This command will add a sheet named 'Actors', or return the sheet if it exists, and the result is stored in $WorkSheetActors. + +### EXAMPLE 2 +``` +PS\> $WorksheetActors = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname "Actors" -ClearSheet -MoveToStart +``` + +This time the Excel package object is passed as a parameter instead of piped. + +If the 'Actors' sheet already exists it is deleted and re-created. + +The new sheet will be created last in the workbook, and -MoveToStart Moves it to the start. + +### EXAMPLE 3 +``` +PS\> $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationName -CopySource $sourceWs -Activate +``` + +This time a workbook is used instead of a package, and a worksheet is copied - $SourceWs is a worksheet object, which can come from the same workbook or a different one. + +Here the new copy of the data is made the active sheet when the workbook is opened. + +## PARAMETERS + +### -ExcelPackage +An object representing an Excel Package. + +```yaml +Type: ExcelPackage +Parameter Sets: Package +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -ExcelWorkbook +An Excel Workbook to which the Worksheet will be added - a Package contains one Workbook, so you can use whichever fits at the time. + +```yaml +Type: ExcelWorkbook +Parameter Sets: WorkBook +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +The name of the worksheet, 'Sheet1' by default. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ClearSheet +If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveToStart +If specified, the worksheet will be moved to the start of the workbook. + +MoveToStart takes precedence over MoveToEnd, Movebefore and MoveAfter if more than one is specified. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveToEnd +If specified, the worksheet will be moved to the end of the workbook. + +(This is the default position for newly created sheets, but it can be used to move existing sheets.) + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveBefore +If specified, the worksheet will be moved before the nominated one (which can be an index starting from 1, or a name). + +MoveBefore takes precedence over MoveAfter if both are specified. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveAfter +If specified, the worksheet will be moved after the nominated one (which can be an index starting from 1, or a name or *). + +If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Activate +If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -CopySource +If worksheet is provided as a copy source the new worksheet will be a copy of it. The source can be in the same workbook, or in a different file. + +```yaml +Type: ExcelWorksheet +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoClobber +Ignored but retained for backwards compatibility. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.ExcelWorksheet +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Close-ExcelPackage.md b/mdHelp/Close-ExcelPackage.md new file mode 100644 index 0000000..0bab0b6 --- /dev/null +++ b/mdHelp/Close-ExcelPackage.md @@ -0,0 +1,143 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Close-ExcelPackage + +## SYNOPSIS +Closes an Excel Package, saving, saving under a new name or abandoning changes and opening the file in Excel as required. + +## SYNTAX + +``` +Close-ExcelPackage [-ExcelPackage] [-Show] [-NoSave] [[-SaveAs] ] [[-Password] ] [-Calculate] [] +``` + +## DESCRIPTION +When working with an ExcelPackage object, the Workbook is held in memory and not saved until the .Save() method of the package is called. + +Close-ExcelPackage saves and disposes of the Package object. + +It can be called with -NoSave to abandon the file without saving, with a new "SaveAs" filename, and/or with a password to protect the file. And -Show will open the file in Excel; -Calculate will try to update the workbook, although not everything can be recalculated + +## EXAMPLES + +### EXAMPLE 1 +``` +Close-ExcelPackage -show $excel +``` + +$excel holds a package object, this saves the workbook and loads it into Excel. + +### EXAMPLE 2 +``` +Close-ExcelPackage -NoSave $excel +``` + +$excel holds a package object, this disposes of it without writing it to disk. + +## PARAMETERS + +### -ExcelPackage +Package to close. + +```yaml +Type: ExcelPackage +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Show +Open the file in Excel. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoSave +Abandon the file without saving. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SaveAs +Save file with a new name (ignored if -NoSave Specified). + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Password +Password to protect the file. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Calculate +Attempt to recalculation the workbook before saving + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Compare-WorkSheet.md b/mdHelp/Compare-WorkSheet.md new file mode 100644 index 0000000..429ee2f --- /dev/null +++ b/mdHelp/Compare-WorkSheet.md @@ -0,0 +1,397 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Compare-WorkSheet + +## SYNOPSIS +Compares two worksheets and shows the differences. + +## SYNTAX + +### True (Default) +``` +Compare-WorkSheet [-Referencefile] [-Differencefile] [-WorkSheetName ] [-Property ] [-ExcludeProperty ] [-Startrow ] [-AllDataBackgroundColor ] [-BackgroundColor ] [-TabColor ] [-Key ] [-FontColor ] [-Show] [-GridView] [-PassThru] [-IncludeEqual] [-ExcludeDifferent] [] +``` + +### B +``` +Compare-WorkSheet [-Referencefile] [-Differencefile] [-WorkSheetName ] [-Property ] [-ExcludeProperty ] -Headername [-Startrow ] [-AllDataBackgroundColor ] [-BackgroundColor ] [-TabColor ] [-Key ] [-FontColor ] [-Show] [-GridView] [-PassThru] [-IncludeEqual] [-ExcludeDifferent] [] +``` + +### C +``` +Compare-WorkSheet [-Referencefile] [-Differencefile] [-WorkSheetName ] [-Property ] [-ExcludeProperty ] [-NoHeader] [-Startrow ] [-AllDataBackgroundColor ] [-BackgroundColor ] [-TabColor ] [-Key ] [-FontColor ] [-Show] [-GridView] [-PassThru] [-IncludeEqual] [-ExcludeDifferent] [] +``` + +## DESCRIPTION +This command takes two file names, one or two worksheet names and a name for a "key" column. + +It reads the worksheet from each file and decides the column names and builds a hashtable of the key-column values and the +rows in which they appear. + +It then uses PowerShell's Compare-Object command to compare the sheets (explicitly checking all the column names which have not been excluded). + +For the difference rows it adds the row number for the key of that row - we have to add the key after doing the comparison, otherwise identical rows at different positions in the file will not be considered a match. + +We also add the name of the file and sheet in which the difference occurs. + +If -BackgroundColor is specified the difference rows will be changed to that background in the orginal file. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Compare-WorkSheet -Referencefile 'Server56.xlsx' -Differencefile 'Server57.xlsx' -WorkSheetName Products -key IdentifyingNumber -ExcludeProperty Install* | Format-Table +``` + +The two workbooks in this example contain the result of redirecting a subset of properties from Get-WmiObject -Class win32_product to Export-Excel. + +The command compares the "Products" pages in the two workbooks, but we don't want to register a difference if the software was installed on a different date or from a different place, and excluding Install* removes InstallDate and InstallSource. + +This data doesn't have a "Name" column, so we specify the "IdentifyingNumber" column as the key. + +The results will be presented as a table. + +### EXAMPLE 2 +``` +PS\> Compare-WorkSheet "Server54.xlsx" "Server55.xlsx" -WorkSheetName Services -GridView +``` + +This time two workbooks contain the result of redirecting the command Get-WmiObject -Class win32_service to Export-Excel. + +Here the -Differencefile and -Referencefile parameter switches are assumed and the default setting for -Key ("Name") works for services. + +This will display the differences between the "Services" sheets using a grid view + +### EXAMPLE 3 +``` +PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen +``` + +This version of the command outputs the differences between the "services" pages and highlights any different rows in the spreadsheet files. + +### EXAMPLE 4 +``` +PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen -FontColor Red -Show +``` + +This example builds on the previous one: this time where two changed rows have the value in the "Name" column (the default value for -Key), this version adds highlighting of the changed cells in red; and then opens the Excel file. + +### EXAMPLE 5 +``` +PS\> Compare-WorkSheet 'Pester-tests.xlsx' 'Pester-tests.xlsx' -WorkSheetName 'Server1','Server2' -Property "full Description","Executed","Result" -Key "full Description" +``` + +This time the reference file and the difference file are the same file and two different sheets are used. + +Because the tests include the machine name and time the test was run, the command specifies that a limited set of columns should be used. + +### EXAMPLE 6 +``` +PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -GridView -ExcludeDifferent +``` + +The "General" page in the two workbooks has a title and two unlabelled columns with a row each for CPU, Memory, Domain, Disk and so on. + +So the command is told to start at row 2 in order to skip the title and given names for the columns: the first is "label" and the second "Value"; the label acts as the key. + +This time we are interested in those rows which are the same in both sheets, and the result is displayed using grid view. + +Note that grid view works best when the number of columns is small. + +### EXAMPLE 7 +``` +PS\>Compare-WorkSheet 'Server1.xlsx' 'Server2.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -BackgroundColor White -Show -AllDataBackgroundColor LightGray +``` + +This version of the previous command highlights all the cells in LightGray and then sets the changed rows back to white. + +Only the unchanged rows are highlighted. + +## PARAMETERS + +### -Referencefile +First file to compare. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Differencefile +Second file to compare. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheetName +Name(s) of worksheets to compare. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Property +Properties to include in the comparison - supports wildcards, default is "*". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeProperty +Properties to exclude from the comparison - supports wildcards. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headername +Specifies custom property names to use, instead of the values defined in the starting row of the sheet. + +```yaml +Type: String[] +Parameter Sets: B +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Automatically generate property names (P1, P2, P3 ...) instead of the using the values the starting row of the sheet. + +```yaml +Type: SwitchParameter +Parameter Sets: C +Aliases: + +Required: True +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Startrow +The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AllDataBackgroundColor +If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +If specified, highlights the rows with differences. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TabColor +If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Key +Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Name +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontColor +If specified, highlights the DIFF columns in rows which have the same key. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GridView +If specified, the command tries to the show the DIFF in a Grid-View and not on the console (unless-PassThru is also specified). +This works best with few columns selected, and requires a key. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If specified a full set of DIFF data is returned without filtering to the specified properties. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IncludeEqual +If specified the result will include equal rows as well. By default only different rows are returned. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeDifferent +If specified, the result includes only the rows where both are equal. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Convert-ExcelRangeToImage.md b/mdHelp/Convert-ExcelRangeToImage.md new file mode 100644 index 0000000..ba09ea5 --- /dev/null +++ b/mdHelp/Convert-ExcelRangeToImage.md @@ -0,0 +1,117 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Convert-ExcelRangeToImage + +## SYNOPSIS +Gets the specified part of an Excel file and exports it as an image + +## SYNTAX + +``` +Convert-ExcelRangeToImage [-Path] [[-workSheetname] ] [-range] [[-destination] ] [-show] [] +``` + +## DESCRIPTION +Excel allows charts to be exported directly to a file, but it can't do this with the rest of a sheet. To work round this, this function + +* Opens a copy of Excel and loads a file +* Selects a worksheet and then a range of cells in that worksheet +* Copies the select to the clipboard +* Saves the clipboard contents as an image file (it will save as .JPG unless the file name ends .BMP or .PNG) +* Copies a single cell to the clipboard (to prevent the "you have put a lot in the clipboard" message appearing) +* Closes Excel +Unlike most functions in the module it needs a local copy of Excel to be installed. +## EXAMPLES + +## PARAMETERS + +### -Path +Path to the Excel file + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheetname +Worksheet name - if none is specified "Sheet1" will be assumed + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Range +Range of cells within the sheet, e.g "A1:Z99" + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Destination +A bmp, png or jpg file where the result will be saved + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: "$pwd\temp.png" +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +If specified opens the image in the default viewer. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/ConvertFrom-ExcelToSQLInsert.md b/mdHelp/ConvertFrom-ExcelToSQLInsert.md new file mode 100644 index 0000000..b178c1a --- /dev/null +++ b/mdHelp/ConvertFrom-ExcelToSQLInsert.md @@ -0,0 +1,225 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# ConvertFrom-ExcelToSQLInsert + +## SYNOPSIS +Generate SQL insert statements from Excel spreadsheet. + +## SYNTAX + +``` +ConvertFrom-ExcelToSQLInsert [-TableName] [-Path] [[-WorkSheetname] ] [[-StartRow] ] [[-Header] ] [-NoHeader] [-DataOnly] [-ConvertEmptyStringsToNull] [-UseMSSQLSyntax] [] +``` + +## DESCRIPTION +Generate SQL insert statements from Excel spreadsheet. + +## EXAMPLES + +### EXAMPLE 1 +``` +Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings: + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Sheet1 | +---------------------------------------------------------- +| A B C | +|1 Movie Name Year Rating | +|2 The Bodyguard 1992 9 | +|3 The Matrix 1999 8 | +|4 Skyfall 2012 9 | +|5 The Avengers 2012 | +---------------------------------------------------------- + +PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path 'C:\Movies.xlsx' +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', ''); +``` + +### EXAMPLE 2 +``` +Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string. + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Sheet1 | +---------------------------------------------------------- +| A B C | +|1 Movie Name Year Rating | +|2 The Bodyguard 1992 9 | +|3 The Matrix 1999 8 | +|4 Skyfall 2012 9 | +|5 The Avengers 2012 | +---------------------------------------------------------- + +PS C:\> ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path "C:\Movies.xlsx" -ConvertEmptyStringsToNull +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Bodyguard', '1992', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Matrix', '1999', '8'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9'); +INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL); +``` + +## PARAMETERS + +### -TableName +Name of the target database table. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Path to an existing .XLSX file +This parameter is passed to Import-Excel as is. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: FullName + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -WorkSheetname +Specifies the name of the worksheet in the Excel workbook to import. +By default, if no name is provided, the first worksheet will be imported. +This parameter is passed to Import-Excel as is. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Sheet + +Required: False +Position: 3 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartRow +The row from where we start to import data, all rows above the StartRow are disregarded. +By default this is the first row. +When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. +When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: HeaderRow, TopRow + +Required: False +Position: 4 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Header +Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. +If you provide fewr header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded. +If you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. +As such, the last properties will be blank as there is no data for them. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. +This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataOnly +Import only rows and columns that contain data, empty rows and empty columns are not imported. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConvertEmptyStringsToNull +If specified, cells without any data are replaced with NULL, instead of an empty string. +This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseMSSQLSyntax +{{ Fill UseMSSQLSyntax Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Copy-ExcelWorkSheet.md b/mdHelp/Copy-ExcelWorkSheet.md new file mode 100644 index 0000000..85f9a89 --- /dev/null +++ b/mdHelp/Copy-ExcelWorkSheet.md @@ -0,0 +1,150 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Copy-ExcelWorkSheet + +## SYNOPSIS +Copies a worksheet between workbooks or within the same workbook. + +## SYNTAX + +``` +Copy-ExcelWorkSheet [-SourceObject] [[-SourceWorkSheet] ] [-DestinationWorkbook] + [[-DestinationWorksheet] ] [-Show] [] +``` + +## DESCRIPTION +Copy-ExcelWorkSheet takes a Source object which is either a worksheet, +or a package, Workbook or path, in which case the source worksheet can be specified +by name or number (starting from 1). +The destination worksheet can be explicitly named, or will follow the name of the source if no name is specified. +The Destination workbook can be given as the path to an XLSx file, an ExcelPackage object or an ExcelWorkbook object. + +## EXAMPLES + +### EXAMPLE 1 +``` +Copy-ExcelWorkSheet -SourceWorkbook Test1.xlsx -DestinationWorkbook Test2.xlsx +``` + +This is the simplest version of the command: no source worksheet is specified so Copy-ExcelWorksheet uses the first sheet in the workbook +No Destination sheet is specified so the new worksheet will be the same as the one which is being copied. + +### EXAMPLE 2 +``` +Copy-ExcelWorkSheet -SourceWorkbook Server1.xlsx -sourceWorksheet "Settings" -DestinationWorkbook Settings.xlsx -DestinationWorksheet "Server1" +``` + +Here the Settings page from Server1's workbook is copied to the 'Server1" page of a "Settings" workbook. + +### EXAMPLE 3 +``` +$excel = Open-ExcelPackage .\test.xlsx +``` + +C:\\\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet "first" -DestinationWorkbook $excel -Show -DestinationWorksheet Duplicate +This opens the workbook test.xlsx and copies the worksheet named "first" to a new worksheet named "Duplicate", +because -Show is specified the file is saved and opened in Excel + +### EXAMPLE 4 +``` +$excel = Open-ExcelPackage .\test.xlsx +``` + +C:\\\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet 1 -DestinationWorkbook $excel -DestinationWorksheet Duplicate +C:\\\> Close-ExcelPackage $excel +This is almost the same as the previous example, except source sheet is specified by position rather than name and +because -Show is not specified, so other steps can be carried using the package object, at the end the file is saved by Close-ExcelPackage + +## PARAMETERS + +### -SourceObject +An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: SourceWorkbook + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -SourceWorkSheet +Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1). + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DestinationWorkbook +An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DestinationWorksheet +Name of the worksheet in the destination workbook; by default the same as the source worksheet's name. +If the sheet exists it will be deleted and re-copied. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +if the destination is an excel package or a path, launch excel and open the file on completion. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Expand-NumberFormat.md b/mdHelp/Expand-NumberFormat.md new file mode 100644 index 0000000..c643555 --- /dev/null +++ b/mdHelp/Expand-NumberFormat.md @@ -0,0 +1,70 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Expand-NumberFormat + +## SYNOPSIS +Converts short names for number formats to the formatting strings used in Excel + +## SYNTAX + +``` +Expand-NumberFormat [[-NumberFormat] ] [] +``` + +## DESCRIPTION +Where you can type a number format you can write, for example, 'Short-Date' and the module will translate it into the format string used by Excel. Some formats, like Short-Date, change when Excel loads (so date will use the local ordering of year, month and Day). Excel also changes how markers in the are presented different cultures "," is used in the format string to mean "local thousand seperator" but depending on the country "," or "." or " " may used as the thousand seperator. + +## EXAMPLES + +### EXAMPLE 1 +``` +Expand-NumberFormat percentage +``` +Returns "0.00%" + +### EXAMPLE 2 +``` +Expand-NumberFormat Currency +``` +Returns the currency format specified in the local regional settings, which may not be the same as Excel uses. + +The regional settings set the currency symbol and then whether it is before or after the number and separated with a space or not; for negative numbers the number may be wrapped in parentheses or a - sign might appear before or after the number and symbol. + +So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00- for French. + +Note some Eurozone countries write €1,23 and others 1,23€. In French the decimal point will be rendered as a "," and the thousand +separator as a space. + +## PARAMETERS + +### -NumberFormat +The format string to Expand + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### System.String +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Export-Excel.md b/mdHelp/Export-Excel.md new file mode 100644 index 0000000..e4e3c1b --- /dev/null +++ b/mdHelp/Export-Excel.md @@ -0,0 +1,1397 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Export-Excel + +## SYNOPSIS +Exports data to an Excel worksheet. + +## SYNTAX + +### Default (Default) +``` +Export-Excel [[-Path] ] [-InputObject ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ][-IncludePivotTable] [-PivotTableName ] [-PivotRows [-PivotColumns ] [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +### Package +``` +Export-Excel -ExcelPackage [-InputObject ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ] [-IncludePivotTable] [-PivotTableName ] [-PivotRows ] [-PivotColumns ] [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] + [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] [-Activate] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +## DESCRIPTION +Exports data to an Excel file and where possible tries to convert numbers in text fields so Excel recognizes them as numbers instead of text. After all: Excel is a spreadsheet program used for number manipulation and calculations. +The parameter -NoNumberConversion * can be used if number conversion is not desired. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Get-Process | Export-Excel .\Test.xlsx -show +``` + +Export all the processes to the Excel file 'Test.xlsx' and open the file immediately. + +### EXAMPLE 2 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Write-Output -1 668 34 777 860 -0.5 119 -0.1 234 788 | + Export-Excel @ExcelParams -NumberFormat ' [Blue$#,##0.00; [Red]-$#,##0.00' +``` + +Exports all data to the Excel file 'Excel.xslx' and colors the negative values in Red and the positive values in Blue. + +It will also add a dollar sign in front of the numbers which use a thousand seperator and display to two decimal places. + +### EXAMPLE 3 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> [PSCustOmobject][Ordered]@{ + Date = Get-Date + Formula1 = '=SUM(F2:G2)' + String1 = 'My String' + String2 = 'a' + IPAddress = '10.10.25.5' + Number1 = '07670' + Number2 = '0,26' + Number3 = '1.555,83' + Number4 = '1.2' + Number5 = '-31' + PhoneNr1 = '+32 44' + PhoneNr2 = '+32 4 4444 444' + PhoneNr3 = '+3244444444' +} | Export-Excel @ExcelParams -NoNumberConversion IPAddress, Number1 +``` + +Exports all data to the Excel file "Excel.xlsx" and tries to convert all values to numbers where possible except for "IPAddress" and "Number1", which are stored in the sheet 'as is', without being converted to a number. + +### EXAMPLE 4 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> [PSCustOmobject][Ordered]@{ + Date = Get-Date + Formula1 = '=SUM(F2:G2)' + String1 = 'My String' + String2 = 'a' + IPAddress = '10.10.25.5' + Number1 = '07670' + Number2 = '0,26' + Number3 = '1.555,83' + Number4 = '1.2' + Number5 = '-31' + PhoneNr1 = '+32 44' + PhoneNr2 = '+32 4 4444 444' + PhoneNr3 = '+3244444444' +} | Export-Excel @ExcelParams -NoNumberConversion * +``` + +Exports all data to the Excel file 'Excel.xslx' as is, no number conversion will take place. This means that Excel will show the exact same data that you handed over to the 'Export-Excel' function. + +### EXAMPLE 5 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Write-Output 489 668 299 777 860 151 119 497 234 788 | + Export-Excel @ExcelParams -ConditionalText $( + New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink + ) +``` + +Exports data that will have a Conditional Formatting rule in Excel that will show cells with a value is greater than 525, with a background fill color of "LightPink" and the text in "DarkRed". + +Where the condition is not met the color will be the default, black text on a white background. + +### EXAMPLE 6 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> Get-Service | Select-Object -Property Name, Status, DisplayName, ServiceName | + Export-Excel @ExcelParams -ConditionalText $( + New-ConditionalText Stop DarkRed LightPink + New-ConditionalText Running Blue Cyan + ) +``` + +Exports all services to an Excel sheet, setting a Conditional formatting rule that will set the background fill color to "LightPink" and the text color to "DarkRed" when the value contains the word "Stop". + +If the value contains the word "Running" it will have a background fill color of "Cyan" and text colored 'Blue'. + +If neither condition is met, the color will be the default, black text on a white background. + +### EXAMPLE 7 +``` +PS\> $ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true + } +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> $Array = @() +PS\> $Obj1 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' +} + +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} + + PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} + +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorksheetName Numbers +``` + +Updates the first object of the array by adding property 'Member3' and 'Member4'. Afterwards, all objects are exported to an Excel file and all column headers are visible. + +### EXAMPLE 8 +``` +PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM +``` + +### EXAMPLE 9 +``` +PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PM +``` + +### EXAMPLE 10 +``` +PS\> Get-Service | Export-Excel 'c:\temp\test.xlsx' -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} +``` + +### EXAMPLE 11 +``` +PS\> $pt = [ordered]@{} +PS\> $pt.pt1=@{ + SourceWorkSheet = 'Sheet1'; + PivotRows = 'Status' + PivotData = @{'Status'='count'} + IncludePivotChart = $true + ChartType = 'BarClustered3D' +} +PS\> $pt.pt2=@ + SourceWorkSheet = 'Sheet2'; + PivotRows = 'Company' + PivotData = @{'Company'='count'} + IncludePivotChart = $true + ChartType = 'PieExploded3D' +} +PS\> Remove-Item -Path .\test.xlsx +PS\> Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize +PS\> Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' +PS\> Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show +``` + +This example defines two PivotTables. + +Then it puts Service data on Sheet1 with one call to Export-Excel and Process Data on sheet2 with a second call to Export-Excel. + +The third and final call adds the two PivotTables and opens the spreadsheet in Excel. + +### EXAMPLE 12 +``` +PS\> Remove-Item -Path .\test.xlsx +PS\> $excel = Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -PassThru +PS\> $excel.Workbook.Worksheets ["Sheet1"].Row(1).style.font.bold = $true +PS\> $excel.Workbook.Worksheets ["Sheet1"].Column(3 ).width = 29 +PS\> $excel.Workbook.Worksheets ["Sheet1"].Column(3 ).Style.wraptext = $true +PS\> $excel.Save() +PS\> $excel.Dispose() +PS\> Start-Process .\test.xlsx +``` + +This example uses -PassThru. + +It puts service information into sheet1 of the workbook and saves the ExcelPackage object in $Excel. + +It then uses the package object to apply formatting, and then saves the workbook and disposes of the object, before loading the document in Excel. + +Note: Other commands in the module remove the need to work directly with the package object in this way. + +### EXAMPLE 13 +``` +PS\> Remove-Item -Path .\test.xlsx -ErrorAction Ignore +PS\> $excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | + Export-Excel -Path .\test.xlsx -ClearSheet -WorksheetName "Processes" -PassThru +PS\> $sheet = $excel.Workbook.Worksheets ["Processes"] +PS\> $sheet.Column(1) | Set-ExcelRange -Bold -AutoFit +PS\> $sheet.Column(2) | Set-ExcelRange -Width 29 -WrapText +PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NFormat "#,###" +PS\> Set-ExcelRange -Address $sheet.Cells ["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###" +PS\> Set-ExcelRange -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold +PS\> Set-ExcelRange -Address $sheet.Row(1) -Bold -HorizontalAlignment Center +PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red +PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red +PS\> foreach ($c in 5..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit } +PS\> Export-Excel -ExcelPackage $excel -WorksheetName "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show +``` + +This a more sophisticated version of the previous example showing different ways of using Set-ExcelRange, and also adding conditional formatting. + +In the final command a PivotChart is added and the workbook is opened in Excel. + +### EXAMPLE 14 +``` +PS\> 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | + Export-Excel -now -LineChart -AutoNameRange +``` + +Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees. + +### EXAMPLE 15 +``` +PS\> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | + Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables +``` + +Runs a query against a SQL Server database and outputs the resulting rows as DataRows using the -OutputAs parameter. The results are then piped to the Export-Excel function. + +NOTE: You need to install the SqlServer module from the PowerShell Gallery in order to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. + +## PARAMETERS + +### -Path +Path to a new or existing .XLSX file. + +```yaml +Type: String +Parameter Sets: Default +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelPackage +An object representing an Excel Package - usually this is returned by specifying -PassThru allowing multiple commands to work on the same workbook without saving and reloading each time. + +```yaml +Type: ExcelPackage +Parameter Sets: Package +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +Date is usually piped into Export-Excel, but it also accepts data through the InputObject parameter + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: TargetData + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Calculate +If specified, a recalculation of the worksheet will be requested before saving. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +Opens the Excel file immediately after creation; convenient for viewing the results instantly without having to search for the file first. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +The name of a sheet within the workbook - "Sheet1" by default. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Password +Sets password protection on the workbook. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ClearSheet +If specified Export-Excel will remove any existing worksheet with the selected name. + +The default behaviour is to overwrite cells in this sheet as needed (but leaving non-overwritten ones in place). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Append +If specified data will be added to the end of an existing sheet, using the same column headings. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Title +Text of a title to be placed in the top left cell. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleFillPattern +Sets the fill pattern for the title cell. + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBold +Sets the title in boldface type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleSize +Sets the point size for the title. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 22 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBackgroundColor +Sets the cell background color for the title cell. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IncludePivotTable +Adds a PivotTable using the data in the worksheet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTableName +If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotRows +Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotColumns +Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotData +In a PivotTable created from command line parameters, the fields to use in the table body are given as a Hash-table in the form + +ColumnName = Average|Count|CountNums|Max|Min|Product|None|StdDev|StdDevP|Sum|Var|VarP. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotFilter +Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotDataToColumn +If there are multiple datasets in a PivotTable, by default they are shown as separate rows under the given row heading; this switch makes them separate columns. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTableDefinition +Instead of describing a single PivotTable with multiple command-line parameters; you can use a HashTable in the form PivotTableName = Definition; + +In this table Definition is itself a Hashtable with Sheet, PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values. The New-PivotTableDefinition command will create the definition from a command line. + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IncludePivotChart +Include a chart with the PivotTable - implies -IncludePivotTable. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartType +The type for PivotChart (one of Excel's defined chart types). + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: Named +Default value: Pie +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +Exclude the legend from the PivotChart. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +Add category labels to the PivotChart. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +Add percentage labels to the PivotChart. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoSize +Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MaxAutoSizeRows +Autosizing can be time consuming, so this sets a maximum number of rows to look at for the Autosize operation. Default is 1000; If 0 is specified ALL rows will be checked + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1000 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoClobber +Not used. Left in to avoid problems with older scripts, it may be removed in future versions. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeTopRow +Freezes headers etc. in the top row. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeFirstColumn +Freezes titles etc. in the left column. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeTopRowFirstColumn +Freezes top row and left column (equivalent to Freeze pane 2,2 ). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezePane +Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). + +```yaml +Type: Int32[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoFilter +Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BoldTopRow +Makes the top row boldface. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Specifies that field names should not be put at the top of columns. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RangeName +Makes the data in the worksheet a named range. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableName +Makes the data in the worksheet a table with a name, and applies a style to it. The name must not contain spaces. If the -Tablestyle parameter is specified without Tablename, "table1", "table2" etc. will be used. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Table + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableStyle +Selects the style for the named table - if the Tablename parameter is specified without giving a style, 'Medium6' is used as a default. + +```yaml +Type: TableStyles +Parameter Sets: (All) +Aliases: +Accepted values: None, Custom, Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9, Light10, Light11, Light12, Light13, Light14, Light15, Light16, Light17, Light18, Light19, Light20, Light21, Medium1, Medium2, Medium3, Medium4, Medium5, Medium6, Medium7, Medium8, Medium9, Medium10, Medium11, Medium12, Medium13, Medium14, Medium15, Medium16, Medium17, Medium18, Medium19, Medium20, Medium21, Medium22, Medium23, Medium24, Medium25, Medium26, Medium27, Medium28, Dark1, Dark2, Dark3, Dark4, Dark5, Dark6, Dark7, Dark8, Dark9, Dark10, Dark11 + +Required: False +Position: Named +Default value: Medium6 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Barchart +Creates a "quick" bar chart using the first text column as labels and the first numeric column as values. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PieChart +Creates a "quick" pie chart using the first text column as labels and the first numeric column as values. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LineChart +Creates a "quick" line chart using the first text column as labels and the first numeric column as values. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ColumnChart +Creates a "quick" column chart using the first text column as labels and the first numeric column as values. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelChartDefinition +A hash-table containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more \[non-Pivot\] charts. This can be created with the New-ExcelChartDefinition command. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideSheet +Name(s) of Sheet(s) to hide in the workbook, supports wildcards. If the selection would cause all sheets to be hidden, the sheet being worked on will be revealed. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnHideSheet +Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveToStart +If specified, the worksheet will be moved to the start of the workbook. + +-MoveToStart takes precedence over -MoveToEnd, -Movebefore and -MoveAfter if more than one is specified. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveToEnd +If specified, the worksheet will be moved to the end of the workbook. (This is the default position for newly created sheets, but the option can be specified to move existing sheets.) + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveBefore +If specified, the worksheet will be moved before the nominated one (which can be a position starting from 1, or a name). + +-MoveBefore takes precedence over -MoveAfter if both are specified. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MoveAfter +If specified, the worksheet will be moved after the nominated one (which can be a position starting from 1, or a name or *). + +If * is used, the worksheet names will be examined starting with the first one, and the sheet placed after the last sheet which comes before it alphabetically. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -KillExcel +Closes Excel without stopping to ask if work should be saved - prevents errors writing to the file because Excel has it open. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoNameRange +Makes each column a named range. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartRow +Row to start adding data. 1 by default. +Row 1 will contain the title, if any is specifed. Then headers will appear (Unless -No header is specified) then the data appears. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartColumn +Column to start adding data - 1 by default. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If specified, Export-Excel returns an object representing the Excel package without saving the package first. +To save, you must either use the Close-ExcelPackage command, or send the package object back to Export-Excel which will save and close the file, or use the object's .Save() or SaveAs() method. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PT + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Numberformat +Formats all values that can be converted to a number to the format specified. For examples: +``` +'0' integer (not really needed unless you need to round numbers, Excel will use default cell properties). +'#' integer without displaying the number 0 in the cell. +'0.0' number with 1 decimal place. +'0.00' number with 2 decimal places. +'#,##0.00' number with 2 decimal places and thousand-separator. +'€#,##0.00' number with 2 decimal places and thousand-separator and money-symbol. +'0%' number with 2 decimal places and thousand-separator and money-symbol. +'[Blue]$#,##0.00;[Red]-$#,##0.00' + blue for positive numbers and red for negative numbers; Both proceeded by a '$' sign +``` + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: General +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeProperty +Specifies properties which may exist in the target data but should not be placed on the worksheet. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoAliasOrScriptPropeties +Some objects in PowerShell duplicate existing properties by adding aliases, or have Script properties which may take a long time to return a value and slow the export down, if specified this option removes these properties + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DisplayPropertySet +Many (but not all) objects in PowerShell have a hidden property named psStandardmembers with a child property DefaultDisplayPropertySet ; this parameter reduces the properties exported to those in this set. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoNumberConversion +By default the command will convert all values to numbers if possible, but this isn't always desirable. -NoNumberConversion allows you to add exceptions for the conversion. + +The only Wildcard allowed is * for all properties + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalFormat +One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalText +Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Style +Takes style settings as a hash-table (which may be built with the New-ExcelStyle command) and applies them to the worksheet. If the hash-table contains a range the settings apply to the range, otherewise they apply to the whole sheet. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -CellStyleSB +A script block which is run at the end of the export to apply styles to cells (although it can be used for other purposes). +The script block is given three paramaters; an object containing the current worksheet, the Total number of Rows and the number of the last column. + +```yaml +Type: ScriptBlock +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Activate +If there is already content in the workbook, a new sheet will not be active UNLESS Activate is specified; when a PivotTable is created its sheet will be activated by this switch. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Now +The -Now switch is a shortcut that automatically creates a temporary file, enables "AutoSize", "TableName" and "Show", and opens the file immediately. + +```yaml +Type: SwitchParameter +Parameter Sets: Default +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ReturnRange +If specified, Export-Excel returns the range of added cells in the format "A1:Z100". + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTotals +By default, PivotTables have totals for each row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Both +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoTotalsInPivot +In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ReZip +If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.ExcelPackage +## NOTES + +## RELATED LINKS + +[https://github.com/dfinke/ImportExcel](https://github.com/dfinke/ImportExcel) + diff --git a/mdHelp/Get-ExcelSheetInfo.md b/mdHelp/Get-ExcelSheetInfo.md new file mode 100644 index 0000000..5d718c3 --- /dev/null +++ b/mdHelp/Get-ExcelSheetInfo.md @@ -0,0 +1,60 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-ExcelSheetInfo + +## SYNOPSIS +Get worksheet names and their indices of an Excel workbook. + +## SYNTAX + +``` +Get-ExcelSheetInfo [-Path] [] +``` + +## DESCRIPTION +The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook. + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-ExcelSheetInfo .\Test.xlsx +``` + +## PARAMETERS + +### -Path +Specifies the path to the Excel file. (This parameter is required.) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: FullName + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +CHANGELOG +2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + +## RELATED LINKS + +[https://github.com/dfinke/ImportExcel](https://github.com/dfinke/ImportExcel) + diff --git a/mdHelp/Get-ExcelWorkbookInfo.md b/mdHelp/Get-ExcelWorkbookInfo.md new file mode 100644 index 0000000..287db1f --- /dev/null +++ b/mdHelp/Get-ExcelWorkbookInfo.md @@ -0,0 +1,82 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Get-ExcelWorkbookInfo + +## SYNOPSIS +Retrieve information of an Excel workbook. + +## SYNTAX + +``` +Get-ExcelWorkbookInfo [-Path] [] +``` + +## DESCRIPTION +The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. +These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage. + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-ExcelWorkbookInfo .\Test.xlsx +``` + +CorePropertiesXml : #document +Title : +Subject : +Author : Konica Minolta User +Comments : +Keywords : +LastModifiedBy : Bond, James (London) GBR +LastPrinted : 2017-01-21T12:36:11Z +Created : 17/01/2017 13:51:32 +Category : +Status : +ExtendedPropertiesXml : #document +Application : Microsoft Excel +HyperlinkBase : +AppVersion : 14.0300 +Company : Secret Service +Manager : +Modified : 10/02/2017 12:45:37 +CustomPropertiesXml : #document + +## PARAMETERS + +### -Path +Specifies the path to the Excel file. +This parameter is required. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: FullName + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +CHANGELOG +2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + +## RELATED LINKS + +[https://github.com/dfinke/ImportExcel](https://github.com/dfinke/ImportExcel) + diff --git a/mdHelp/Import-Excel.md b/mdHelp/Import-Excel.md new file mode 100644 index 0000000..159f13d --- /dev/null +++ b/mdHelp/Import-Excel.md @@ -0,0 +1,425 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Import-Excel + +## SYNOPSIS +Create custom objects from the rows in an Excel worksheet. + +## SYNTAX + +### PathC +``` +Import-Excel [-Path] [[-WorksheetName] ] [-NoHeader] [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +### PathB +``` +Import-Excel [-Path] [[-WorksheetName] ] -HeaderName [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +### PathA +``` +Import-Excel [-Path] [[-WorksheetName] ] [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +### PackageC +``` +Import-Excel -ExcelPackage [[-WorksheetName] ] [-NoHeader] [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +### PackageB +``` +Import-Excel -ExcelPackage [[-WorksheetName] ] -HeaderName [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +### PackageA +``` +Import-Excel -ExcelPackage [[-WorksheetName] ] [-StartRow ] [-EndRow ] [-StartColumn ] [-EndColumn ] [-DataOnly] [-AsText ] [-Password ] [] +``` + +## DESCRIPTION +The Import-Excel cmdlet creates custom objects from the rows in an Excel worksheet. Each row is represented as one object. + +This is possible without installing Microsoft Excel by using the .NET library 'EPPLus.dll'. + +By default, the property names of the objects are retrieved from the column headers. Because an object cannot have a blank property name, only columns with column headers will be imported. + +If the default behavior is not desired and you want to import the complete worksheet 'as is', the parameter '-NoHeader' can be used. +In case you want to provide your own property names, you can use the parameter '-HeaderName'. + +## EXAMPLES + +### EXAMPLE 1 +``` + +---------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------- +| A B C | +|1 First Name Address | +|2 Chuck Norris California | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------- + +PS C:> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors + +First Name: Chuck +Address : California + +First Name: Jean-Claude +Address : Brussels +``` +Import data from an Excel worksheet. One object is created for each row. The property names of the objects consist of the column names defined in the first row. In case a column doesn't have a column header (usually in row 1 when '-StartRow' is not used), then the unnamed columns will be skipped and the data in those columns will not be imported. + +Notice that column 'B' is not imported because there's no value in cell 'B1' that can be used as property name for the objects. + +### EXAMPLE 2 +``` + +---------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------- +| A B C | +|1 First Name Address | +|2 Chuck Norris California | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -NoHeader + +P1: First Name +P2: +P3: Address + +P1: Chuck +P2: Norris +P3: California + +P1: Jean-Claude +P2: Vandamme +P3: Brussels +``` + +Imports the complete Excel worksheet 'as is' by using the '-NoHeader' switch. One object is created for each row. The property names of the objects will be automatically generated (P1, P2, P3, ..). + +Notice that the column header (row 1) is imported as an object too. + +### EXAMPLE 3 +``` + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Movies | +---------------------------------------------------------- +| A B C D | +|1 The Bodyguard 1992 9 | +|2 The Matrix 1999 8 | +|3 | +|4 Skyfall 2012 9 | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -HeaderName 'Movie name', 'Year', 'Rating', 'Genre' + +Movie name: The Bodyguard +Year : 1992 +Rating : 9 +Genre : + +Movie name: The Matrix +Year : 1999 +Rating : 8 +Genre : + +Movie name: +Year : +Rating : +Genre : + +Movie name: Skyfall +Year : 2012 +Rating : 9 +Genre : +``` +This imports data from an Excel worksheet, and as before one object is created for each row. The property names for the objects are defined in the parameter '-HeaderName'. The properties are named starting from the most left column (A) to the right. In case no value is present in one of the columns, that property will have an empty value. + +Notice that empty rows are imported and that data for the property 'Genre' is not present in the worksheet. As such, the 'Genre' property will be blank for all objects. + +### EXAMPLE 4 +``` + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Movies | +---------------------------------------------------------- +| A B C D | +|1 The Bodyguard 1992 9 | +|2 The Matrix 1999 8 | +|3 | +|4 Skyfall 2012 9 | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Movies -NoHeader -DataOnly + +P1: The Bodyguard +P2: 1992 +P3: 9 + +P1: The Matrix +P2: 1999 +P3: 8 + +P1: Skyfall +P2: 2012 +P3: 9 +``` + +Import data from an Excel worksheet, and one object is created for each non-blank row. The property names of the objects (P1, P2, P3, ..) are automatically generated by using the switch '-NoHeader' . The switch '-DataOnly' will speed up the import because empty rows and empty columns are not imported. + +Notice that empty rows and empty columns are not imported. + +### EXAMPLE 5 +``` + +---------------------------------------------------------- +| File: Movies.xlsx - Sheet: Actors | +---------------------------------------------------------- +| A B C D | +|1 Chuck Norris California | +|2 | +|3 Jean-Claude Vandamme Brussels | +---------------------------------------------------------- + +PS\> Import-Excel -Path 'C:\Movies.xlsx' -WorkSheetname Actors -DataOnly -HeaderName 'FirstName', 'SecondName', 'City' -StartRow 2 + +FirstName : Jean-Claude +SecondName: Vandamme +City : Brussels +``` + +Import data from an Excel worksheet. One object is created for each row. The property names are provided with the '-HeaderName' parameter. The import will start from row 2 and empty columns and rows are not imported. + +Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with 'Chuck Norris' has not been imported, because we started the import from row 2 with the parameter '-StartRow 2'. + +### EXAMPLE 6 +``` +PS\> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | + Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force + +``` +Imports data from an Excel file and pipes the result to the Write-SqlTableData command to be INSERTed into a table in a SQL Server database. + +The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows. + +The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. + +The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in. +NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet. + +## PARAMETERS + +### -Path +Specifies the path to the Excel file. + +```yaml +Type: String +Parameter Sets: PathC, PathB, PathA +Aliases: FullName + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -ExcelPackage +Instead of specifying a path, provides an Excel Package object (from Open-ExcelPackage). Using this avoids re-reading the whole file when importing multiple parts of it. + +To allow multiple read operations Import-Excel does NOT close the package, and you should use Close-ExcelPackage -noSave to close it. + +```yaml +Type: ExcelPackage +Parameter Sets: PackageC, PackageB, PackageA +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: Sheet + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HeaderName +Specifies custom property names to use, instead of the values defined in the column headers of the TopRow. + +If you provide fewer header names than there are columns of data in the worksheet, then data will only be imported from that number of columns - the others will be ignored. + +If you provide more header names than there are columns of data in the worksheet, it will result in blank properties being added to the objects returned. + +```yaml +Type: String[] +Parameter Sets: PathB, PackageB +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow. + +This switch is best used when you want to import the complete worksheet 'as is' and are not concerned with the property names. + +```yaml +Type: SwitchParameter +Parameter Sets: PathC, PackageC +Aliases: + +Required: True +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartRow +The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. + +When the parameters '-NoHeader' and '-HeaderName' are not provided, this row will contain the column headers that will be used as property names. If either is provided, the property names are automatically created and this row will be treated as a regular row containing data. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: HeaderRow, TopRow + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EndRow +By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: StopRow, BottomRow + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartColumn +The number of the first column to read data from (1 by default). + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: LeftColumn + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EndColumn +By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: RightColumn + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataOnly +Import only rows and columns that contain data, empty rows and empty columns are not imported. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsText +Normally Import-Excel returns the Cell values. AsText allows selected columns to be returned as the text displayed in their cells. (* is supported as a wildcard.) + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Password +Accepts a string that will be used to open a password protected Excel file. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + +[https://github.com/dfinke/ImportExcel](https://github.com/dfinke/ImportExcel) + diff --git a/mdHelp/Join-Worksheet.md b/mdHelp/Join-Worksheet.md new file mode 100644 index 0000000..ad9fc2f --- /dev/null +++ b/mdHelp/Join-Worksheet.md @@ -0,0 +1,553 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Join-Worksheet + +## SYNOPSIS +Combines data on all the sheets in an Excel worksheet onto a single sheet. + +## SYNTAX + +### Default (Default) +``` +Join-Worksheet [[-Path] ] [-WorkSheetName ] [-Clearsheet] [-NoHeader] [-FromLabel ] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-HideSource] [-Title ] [-TitleFillPattern ] [-TitleBackgroundColor ] [-TitleBold] [-TitleSize ] [-PivotTableDefinition ] [-ExcelChartDefinition ] [-ConditionalFormat ] [-ConditionalText ] [-AutoNameRange] [-RangeName ] [-ReturnRange] [-Show] [-PassThru][] +``` + +### Table +``` +Join-Worksheet [[-Path] ] [-WorkSheetName ] [-Clearsheet] [-NoHeader] [-FromLabel ] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-BoldTopRow] [-HideSource] [-Title ] [-TitleFillPattern ] [-TitleBackgroundColor ] [-TitleBold] [-TitleSize ] [-PivotTableDefinition ] [-ExcelChartDefinition ] [-ConditionalFormat ] [-ConditionalText ] [-AutoNameRange] [-RangeName ] -TableName [-TableStyle ] [-ReturnRange] [-Show] [-PassThru] [] +``` + +### PackageTable +``` +Join-Worksheet -ExcelPackage [-WorkSheetName ] [-Clearsheet] [-NoHeader] [-FromLabel ] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-BoldTopRow] [-HideSource] [-Title ] [-TitleFillPattern ] [-TitleBackgroundColor ] [-TitleBold] [-TitleSize ] [-PivotTableDefinition ] [-ExcelChartDefinition ] [-ConditionalFormat ] [-ConditionalText ] [-AutoNameRange] [-RangeName ] -TableName [-TableStyle ] [-ReturnRange] [-Show] [-PassThru] [] +``` + +### PackageDefault +``` +Join-Worksheet -ExcelPackage [-WorkSheetName ] [-Clearsheet] [-NoHeader] [-FromLabel ] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-HideSource] [-Title ] [-TitleFillPattern ] [-TitleBackgroundColor ] [-TitleBold] [-TitleSize ] [-PivotTableDefinition ] [-ExcelChartDefinition ] [-ConditionalFormat ] [-ConditionalText ] [-AutoNameRange] [-RangeName ] [-ReturnRange] [-Show] [-PassThru] [] +``` + +## DESCRIPTION +Join-Worksheet can work in two main ways, either + +*Combining data which has the same layout from many pages into one, or +*Combining pages which have nothing in common. +In the former case the header row is copied from the first sheet and, by default, each row of data is labelled with the name of the sheet it came from. + +In the latter case -NoHeader is specified, and each copied block can have the sheet it came from placed above it as a title. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> foreach ($computerName in @('Server1', 'Server2', 'Server3', 'Server4')) { + Get-Service -ComputerName $computerName | + Select-Object -Property Status, Name, DisplayName, StartType | + Export-Excel -Path .\test.xlsx -WorkSheetname $computerName -AutoSize +} +PS\> $ptDef = New-PivotTableDefinition -PivotTableName "Pivot1" -SourceWorkSheet "Combined" -PivotRows "Status" -PivotFilter "MachineName" -PivotData @{Status='Count'} -IncludePivotChart -ChartType BarClustered3D +PS\> Join-Worksheet -Path .\test.xlsx -WorkSheetName combined -FromLabel "MachineName" -HideSource-AutoSize -FreezeTopRow -BoldTopRow -PivotTableDefinition $pt -Show +``` + +The foreach command gets a list of services running on four servers and exports each list to its own page in Test.xlsx. And $PtDef=... creates a definition for a PivotTable. + +The Join-Worksheet command uses the same file and merges the results into a sheet named "Combined". It sets a column header of "Machinename", this column will contain the name of the sheet the data was copied from; after copying the data to the sheet "Combined", the other sheets will be hidden. Join-Worksheet finishes by calling Export-Excel to AutoSize cells, freeze the top row and make it bold and add thePivotTable. + +### EXAMPLE 2 +``` +PS\> Get-CimInstance -ClassName win32_logicaldisk | + Select-Object -Property DeviceId,VolumeName, Size,Freespace | + Export-Excel -Path "$env:computerName.xlsx" -WorkSheetname Volumes -NumberFormat "0,000" +PS\> Get-NetAdapter| Select-Object Name,InterfaceDescription,MacAddress,LinkSpeed | + Export-Excel -Path "$env:COMPUTERNAME.xlsx" -WorkSheetname NetAdapter +PS\> Join-Worksheet -Path "$env:COMPUTERNAME.xlsx"-WorkSheetName Summary -Title "Summary" -TitleBold -TitleSize 22 -NoHeader -LabelBlocks -AutoSize -HideSource -show +``` + +The first two commands get logical-disk and network-card information; each type is exported to its own sheet in a workbook. + +The Join-Worksheet command copies both onto a page named "Summary".Because the data is dissimilar, -NoHeader is specified, ensuring the whole of each page is copied. Specifying -LabelBlocks causes each sheet's name to become a title on the summary page above the copied data. The source data is hidden, a title is added in 22 point boldface and the columns are sized to fit the data. + +## PARAMETERS + +### -Path +Path to a new or existing .XLSX file. + +```yaml +Type: String +Parameter Sets: Default, Table +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelPackage +An object representing an Excel Package - either from Open-ExcelPackage or specifying -PassThru to Export-Excel. + +```yaml +Type: ExcelPackage +Parameter Sets: PackageTable, PackageDefault +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorkSheetName +The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Combined +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Clearsheet +If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FromLabel +If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: From +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LabelBlocks +If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoSize +Sets the width of the Excel columns to display all the data in their cells. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeTopRow +Freezes headers etc. in the top row. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeFirstColumn +Freezes titles etc. in the left column. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezeTopRowFirstColumn +Freezes top row and left column (equivalent to Freeze pane 2,2 ). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FreezePane +Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). + +```yaml +Type: Int32[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoFilter +Enables the Excel filter on the headers of the combined sheet. + +```yaml +Type: SwitchParameter +Parameter Sets: Default, PackageDefault +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BoldTopRow +Makes the top row boldface. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideSource +If specified, hides the sheets that the data is copied from. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Title +Text of a title to be placed in Cell A1. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleFillPattern +Sets the fill pattern for the title cell. + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBackgroundColor +Sets the cell background color for the title cell. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBold +Sets the title in boldface type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleSize +Sets the point size for the title. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 22 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTableDefinition +Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelChartDefinition +A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more \[non-pivot\] charts. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalFormat +One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalText +Applies a Conditional formatting rule defined with New-ConditionalText. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoNameRange +Makes each column a named range. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RangeName +Makes the data in the worksheet a named range. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableName +Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. + +```yaml +Type: String +Parameter Sets: Table, PackageTable +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TableStyle +Selects the style for the named table - defaults to "Medium6". + +```yaml +Type: TableStyles +Parameter Sets: Table, PackageTable +Aliases: +Accepted values: None, Custom, Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9, Light10, Light11, Light12, Light13, Light14, Light15, Light16, Light17, Light18, Light19, Light20, Light21, Medium1, Medium2, Medium3, Medium4, Medium5, Medium6, Medium7, Medium8, Medium9, Medium10, Medium11, Medium12, Medium13, Medium14, Medium15, Medium16, Medium17, Medium18, Medium19, Medium20, Medium21, Medium22, Medium23, Medium24, Medium25, Medium26, Medium27, Medium28, Dark1, Dark2, Dark3, Dark4, Dark5, Dark6, Dark7, Dark8, Dark9, Dark10, Dark11 + +Required: False +Position: Named +Default value: Medium6 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ReturnRange +If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Merge-MultipleSheets.md b/mdHelp/Merge-MultipleSheets.md new file mode 100644 index 0000000..71483ec --- /dev/null +++ b/mdHelp/Merge-MultipleSheets.md @@ -0,0 +1,330 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Merge-MultipleSheets + +## SYNOPSIS +Merges Worksheets into a single Worksheet with differences marked up. + +## SYNTAX + +``` +Merge-MultipleSheets [-Path] [[-Startrow] ] [[-Headername] ] [-NoHeader] [[-WorksheetName] ] [[-OutputFile] ] [[-OutputSheetName] ] [[-Property] ] [[-ExcludeProperty] ] [[-Key] ] [[-KeyFontColor] ] [[-ChangeBackgroundColor] ] [[-DeleteBackgroundColor] ] [[-AddBackgroundColor] ] [-HideRowNumbers] [-Passthru] [-Show] [] +``` + +## DESCRIPTION +The Merge Worksheet command combines two sheets. Merge-MultipleSheets is designed to merge more than two. + +If asked to merge sheets A,B,C which contain Services, with a Name, Displayname and Start mode, where "Name" is treated as the key, Merge-MultipleSheets: + +* Calls Merge-Worksheet to merge "Name", "Displayname" and "Startmode" from sheets A and C; the result has column headings "_Row", "Name", "DisplayName", "Startmode", "C-DisplayName", "C-StartMode", "C-Is" and "C-Row". +* Calls Merge-Worksheet again passing it the intermediate result and sheet B, comparing "Name", "Displayname" and "Start mode" columns on each side, and gets a result with columns "_Row", "Name", "DisplayName", "Startmode", "B-DisplayName", "B-StartMode", "B-Is", "B-Row", "C-DisplayName", "C-StartMode", "C-Is" and "C-Row". +Any columns on the "reference" side which are not used in the comparison are added on the right, which is why we compare the sheets in reverse order. + +The "Is" columns hold "Same", "Added", "Removed" or "Changed" and is used for conditional formatting in the output sheet (these columns are hidden by default), and when the data is written to Excel the "reference" columns, in this case "DisplayName" and "Start" are renamed to reflect their source, so they become "A-DisplayName" and "A-Start". + +Conditional formatting is also applied to the Key column ("Name" in this case) so the view can be filtered to rows with changes by filtering this +column on color. + +Note: the processing order can affect what is seen as a change.For example, if there is an extra item in sheet B in the example above, Sheet C will be processed first and that row and will not be seen to be missing. When sheet B is processed it is marked as an addition, and the conditional formatting marks the entries from sheet A to show that a values were added in at least one sheet. + +However if Sheet B is the reference sheet, A and C will be seen to have an item removed; and if B is processed before C, the extra item is known when C is processed and so C is considered to be missing that item. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> dir Server*.xlsx | Merge-MulipleSheets -WorksheetName Services -OutputFile Test2.xlsx -OutputSheetName Services -Show +``` + +Here we are auditing servers and each one has a workbook in the current directory which contains a "Services" Worksheet (the result of Get-WmiObject -Class win32_service | Select-Object -Property Name, Displayname, Startmode). No key is specified so the key is assumed to be the "Name" column. The files are merged and the result is opened on completion. + +### EXAMPLE 2 +``` +PS\> dir Serv*.xlsx | Merge-MulipleSheets -WorksheetName Software -Key "*" -ExcludeProperty Install* -OutputFile Test2.xlsx -OutputSheetName Software -Show +``` + +The server audit files in the previous example also have "Software" worksheet, but no single field on that sheet works as a key. Specifying "*" for the key +produces a compound key using all non-excluded fields (and the installation date and file location are excluded). + +### EXAMPLE 3 +``` +Merge-MulipleSheets -Path hotfixes.xlsx -WorksheetName Serv* -Key hotfixid -OutputFile test2.xlsx -OutputSheetName hotfixes -HideRowNumbers -Show +``` + +This time all the servers have written their hotfix information to their own worksheets in a shared Excel workbook named "Hotfixes.xlsx" (the information was +obtained by running Get-Hotfix | Sort-Object -Property description,hotfixid | Select-Object -Property Description,HotfixID) +This ignores any sheets which are not named "Serv*", and uses the HotfixID as the key; in this version the row numbers are hidden. + +## PARAMETERS + +### -Path +Paths to the files to be merged. +Files are also accepted + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Startrow +The row from where we start to import data, all rows above the Start row are disregarded. By default this is the first row. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headername +Specifies custom property names to use, instead of the values defined in the column headers of the Start row. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +If specified, property names will be automatically generated (P1, P2, P3, ..) instead of using the values from the start row. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +Name(s) of Worksheets to compare. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputFile +File to write output to. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: OutFile + +Required: False +Position: 5 +Default value: .\temp.xlsx +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputSheetName +Name of Worksheet to output - if none specified will use the reference Worksheet name. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: OutSheet + +Required: False +Position: 6 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Property +Properties to include in the comparison - supports wildcards, default is "*". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeProperty +Properties to exclude from the the comparison - supports wildcards. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 8 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Key +Name of a column which is unique used to pair up rows from the reference and difference sides, default is "Name". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 9 +Default value: Name +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -KeyFontColor +Sets the font color for the Key field; this means you can filter by color to get only changed rows. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 10 +Default value: [System.Drawing.Color]::Red +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChangeBackgroundColor +Sets the background color for changed rows. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 11 +Default value: [System.Drawing.Color]::Orange +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DeleteBackgroundColor +Sets the background color for rows in the reference but deleted from the difference sheet. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 12 +Default value: [System.Drawing.Color]::LightPink +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AddBackgroundColor +Sets the background color for rows not in the reference but added to the difference sheet. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 13 +Default value: [System.Drawing.Color]::Orange +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideRowNumbers +If specified, hides the columns in the spreadsheet that contain the row numbers. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Passthru +If specified, outputs the data to the pipeline (you can add -whatif so it the command only outputs to the pipeline). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +If specified, opens the output workbook. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Merge-Worksheet.md b/mdHelp/Merge-Worksheet.md new file mode 100644 index 0000000..8821125 --- /dev/null +++ b/mdHelp/Merge-Worksheet.md @@ -0,0 +1,462 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Merge-Worksheet + +## SYNOPSIS +Merges two Worksheets (or other objects) into a single Worksheet with differences marked up. + +## SYNTAX + +### C +``` +Merge-Worksheet [-Referencefile] [-Differencefile] [[-WorksheetName] ] [-Startrow ] [-NoHeader] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### B +``` +Merge-Worksheet [-Referencefile] [-Differencefile] [[-WorksheetName] ] [-Startrow ] -Headername [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### A +``` +Merge-Worksheet [-Referencefile] [-Differencefile] [[-WorksheetName] ] [-Startrow ] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### G +``` +Merge-Worksheet [-Differencefile] [[-WorksheetName] ] [-Startrow ] [-NoHeader] -ReferenceObject [[-DiffPrefix] ] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### F +``` +Merge-Worksheet [-Differencefile] [[-WorksheetName] ] [-Startrow ] -Headername -ReferenceObject [[-DiffPrefix] ] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### E +``` +Merge-Worksheet [-Differencefile] [[-WorksheetName] ] [-Startrow ] -ReferenceObject [[-DiffPrefix] ] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +### D +``` +Merge-Worksheet -ReferenceObject [-DifferenceObject] [[-DiffPrefix] ] [[-OutputFile] ] [[-OutputSheetName] ] [-Property ] [-ExcludeProperty ] [-Key ] [-KeyFontColor ] [-ChangeBackgroundColor ] [-DeleteBackgroundColor ] [-AddBackgroundColor ] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The Compare-Worksheet command takes two Worksheets and marks differences in the source document, and optionally outputs a grid showing the changes. + +By contrast the Merge-Worksheet command takes the Worksheets and combines them into a single sheet showing the old and new data side by side. Although it is designed to work with Excel data it can work with arrays of any kind of object; so it can be a merge *of* Worksheets, or a merge *to* a Worksheet. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -show +``` + +The workbooks contain audit information for two servers, one sheet contains a list of services. + +This command creates a worksheet named "54-55" in a workbook named "services.xlsx" which shows all the services and their differences, and opens the new workbook in Excel. + +### EXAMPLE 2 +``` +PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -HideEqual -AddBackgroundColor LightBlue -show +``` + +This modifies the previous command to hide the equal rows in the output sheet and changes the color used to mark rows added to the second file. + +### EXAMPLE 3 +``` +PS\> Merge-Worksheet -OutputFile .\j1.xlsx -OutputSheetName test11 -ReferenceObject (dir .\ImportExcel\4.0.7) -DifferenceObject (dir .\ImportExcel\4.0.8) -Property Length -Show +``` + +This version compares two directories, and marks what has changed. Because no "Key" property is given, "Name" is assumed to be the key and the only other property examined is length. Files which are added or deleted or have changed size will be highlighed in the output sheet. Changes to dates or other attributes will be ignored. + +### EXAMPLE 4 +``` +PS\> Merge-Worksheet -RefO (dir .\ImportExcel\4.0.7) -DiffO (dir .\ImportExcel\4.0.8) -Pr Length | Out-GridView +``` + +This time no file is written and the results - which include all properties, not just length, are output and sent to Out-Gridview. + +This version uses aliases to shorten the parameters, (OutputFileName can be "outFile" and the Sheet can be"OutSheet"; DifferenceObject & ReferenceObject can be +DiffObject & RefObject respectively). + +## PARAMETERS + +### -Referencefile +First Excel file to compare. You can compare two Excel files or two other objects or a reference obhct against a difference file, but not a reference file against an object. works with the following parameter sets + +* A = Compare two files default headers +* B = Compare two files user supplied headers +* C = Compare two files headers P1, P2, P3 etc + +```yaml +Type: Object +Parameter Sets: C, B, A +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Differencefile +Second Excel file to compare. Works with paramter sets A,B,C as well as the following + +* D = Compare two objects; +* E = Compare one object one file that uses default headers +* F = Compare one object one file that uses user supplied headers +* G = Compare one object one file that uses headers P1, P2, P3 etc + +```yaml +Type: Object +Parameter Sets: C, B, A, G, F, E +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) + +```yaml +Type: Object +Parameter Sets: C, B, A, G, F, E +Aliases: + +Required: False +Position: 3 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Startrow +The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row. Applies to all sets EXCEPT D which is two objects (no sheets, so no start row ) + +```yaml +Type: Int32 +Parameter Sets: C, B, A, G, F, E +Aliases: + +Required: False +Position: Named +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headername +Specifies custom property names to use, instead of the values defined in the column headers of the Start Row. Works with the following parameter sets: + +* B 2 sheets with user supplied headers +* F Compare object + sheet +```yaml +Type: String[] +Parameter Sets: B, F +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoHeader +Automatically generate property names (P1, P2, P3, ..) instead of using the values the top row of the sheet. Works with parameter sets + +* C 2 sheets with headers of P1, P2, P3 ... +* G Compare object + sheet +```yaml +Type: SwitchParameter +Parameter Sets: C, G +Aliases: + +Required: True +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ReferenceObject +Reference object to compare if a Worksheet is NOT being used. +Reference object can combine with a difference sheet or difference object + +```yaml +Type: Object +Parameter Sets: G, F, E, D +Aliases: RefObject + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DifferenceObject +Difference object to compare if a Worksheet is NOT being used for either half. +Can't have a reference sheet and difference object. + +```yaml +Type: Object +Parameter Sets: D +Aliases: DiffObject + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DiffPrefix +If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=\>" + +```yaml +Type: Object +Parameter Sets: G, F, E, D +Aliases: + +Required: False +Position: 3 +Default value: => +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputFile +File to hold merged data. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: OutFile + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputSheetName +Name of Worksheet to output - if none specified will use the reference Worksheet name. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: OutSheet + +Required: False +Position: 5 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Property +Properties to include in the DIFF - supports wildcards, default is "*". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeProperty +Properties to exclude from the the search - supports wildcards. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Key +Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Name +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -KeyFontColor +Sets the font color for the "key" field; this means you can filter by color to get only changed rows. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::DarkRed +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChangeBackgroundColor +Sets the background color for changed rows. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::Orange +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DeleteBackgroundColor +Sets the background color for rows in the reference but deleted from the difference sheet. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::LightPink +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AddBackgroundColor +Sets the background color for rows not in the reference but added to the difference sheet. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::PaleGreen +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideEqual +if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Passthru +If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +If specified, opens the output workbook. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/New-ConditionalFormattingIconSet.md b/mdHelp/New-ConditionalFormattingIconSet.md new file mode 100644 index 0000000..2de38f5 --- /dev/null +++ b/mdHelp/New-ConditionalFormattingIconSet.md @@ -0,0 +1,92 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-ConditionalFormattingIconSet + +## SYNOPSIS +Creates an object which describes a conditional formatting rule a for 3,4 or 5 icon set. + +## SYNTAX + +``` +New-ConditionalFormattingIconSet [-Range] [[-ConditionalFormat] ] [-Reverse] [] +``` + +## DESCRIPTION +Export-Excel takes a -ConditionalFormat parameter which can hold one or more descriptions for conditional formats; this command builds the defintion of a Conditional formatting rule for an icon set. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $cfRange = [OfficeOpenXml.ExcelAddress]::new($topRow, $column, $lastDataRow, $column) +PS\> $cfdef = New-ConditionalFormattingIconSet -Range $cfrange -ConditionalFormat ThreeIconSet -IconType Arrows +PS\> Export-Excel -ExcelPackage $excel -ConditionalFormat $cfdef -show +``` +The first line creates a range - one column wide in the column $column, running from $topRow to $lastDataRow. The second line creates a definition object using this range and the third uses Export-Excel with an open package to apply the format and save and open the file. + +## PARAMETERS + +### -Range +The range of cells that the conditional format applies to. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalFormat +The type of rule: one of "ThreeIconSet","FourIconSet" or "FiveIconSet" + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Reverse +Use the icons in the reverse order. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + +[Add-Add-ConditionalFormatting]() +[New-ConditionalText]() + diff --git a/mdHelp/New-ConditionalText.md b/mdHelp/New-ConditionalText.md new file mode 100644 index 0000000..fb55d6b --- /dev/null +++ b/mdHelp/New-ConditionalText.md @@ -0,0 +1,153 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-ConditionalText + +## SYNOPSIS +Creates an object which describes a conditional formatting rule for single valued rules. + +## SYNTAX + +``` +New-ConditionalText [[-Text] ] [[-ConditionalTextColor] ] [[-BackgroundColor] ] [[-Range] ] [[-PatternType] ] [[-ConditionalType] ] [] +``` + +## DESCRIPTION +Some Conditional formatting rules don't apply styles to a cell (IconSets and Databars); some take two parameters (Between); some take none (ThisWeek, ContainsErrors, AboveAverage etc).The others take a single parameter (Top, BottomPercent, GreaterThan, Contains etc). + +This command creates an object to describe the last two categories, which can then be passed to Export-Excel. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $ct = New-ConditionalText -Text 'Ferrari' +PS\> Export-Excel -ExcelPackage $excel -ConditionalTest $ct -show + +``` + +The first line creates a definition object which will highlight the word "Ferrari" in any cell. and the second uses Export-Excel with an open package to apply the format and save and open the file. + +### EXAMPLE 2 +``` +PS\> $ct = New-ConditionalText -Text "Ferrari" +PS\> $ct2 = New-ConditionalText -Range $worksheet.Names\["FinishPosition"\].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalTextColor Red -BackgroundColor White +PS\> Export-Excel -ExcelPackage $excel -ConditionalText $ct,$ct2 -show +``` + + +This builds on the previous example, and specifies a condition of \<=3 with a format of red text on a white background; this applies to a named range "Finish Position". + +The range could be written -Range "C:C" to specify a named column, or -Range "C2:C102" to specify certain cells in the column. + +## PARAMETERS + +### -Text +The text (or other value) to use in the rule. Note that Equals, GreaterThan/LessThan rules require text to wrapped in double quotes. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: ConditionValue + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalTextColor +The font color for the cell - by default: "DarkRed". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: ForeGroundColor + +Required: False +Position: 2 +Default value: [System.Drawing.Color]::DarkRed +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +The fill color for the cell - by default: "LightPink". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: [System.Drawing.Color]::LightPink +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Range +The range of cells that the conditional format applies to; if none is specified the range will be apply to all the data in the sheet. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternType +The background pattern for the cell - by default: "Solid" + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: 5 +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionalType +One of the supported rules; by default "ContainsText" is selected. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: RuleType + +Required: False +Position: 6 +Default value: ContainsText +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + +[Add-ConditionalFormatting]() +[New-ConditionalFormattingIconSet]() + diff --git a/mdHelp/New-ExcelChartDefinition.md b/mdHelp/New-ExcelChartDefinition.md new file mode 100644 index 0000000..fbaac1e --- /dev/null +++ b/mdHelp/New-ExcelChartDefinition.md @@ -0,0 +1,634 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-ExcelChartDefinition + +## SYNOPSIS +Creates a Definition of a chart which can be added using Export-Excel, or Add-PivotTable + +## SYNTAX + +``` +New-ExcelChartDefinition [[-Title] ] [[-Header] ] [[-ChartType] ] [[-ChartTrendLine] ] [[-XRange] ] [[-YRange] ] [[-Width] ] [[-Height] ] [[-Row] ] [[-RowOffSetPixels] ] [[-Column] ] [[-ColumnOffSetPixels] ] [[-LegendPosition] ] [[-LegendSize] ] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [[-SeriesHeader] ] [-TitleBold] [[-TitleSize] ] [[-XAxisTitleText] ] [-XAxisTitleBold] [[-XAxisTitleSize] ] [[-XAxisNumberformat] ] [[-XMajorUnit] ] [[-XMinorUnit] ] [[-XMaxValue] ] [[-XMinValue] ] [[-XAxisPosition] ] [[-YAxisTitleText] ] [-YAxisTitleBold] [[-YAxisTitleSize] ] [[-YAxisNumberformat] ] [[-YMajorUnit] ] [[-YMinorUnit] ] [[-YMaxValue] ] [[-YMinValue] ] [[-YAxisPosition] ] [] +``` + +## DESCRIPTION +All the parameters which are passed to Add-ExcelChart can be added to a chart-definition object and passed to Export-Excel with the -ExcelChartDefinition parameter, +or to Add-PivotTable with the -PivotChartDefinition parameter. This command sets up those definition objects. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $cDef = New-ExcelChartDefinition -ChartType line -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -TitleBold -TitleSize 14 -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 -SeriesHeader "Sin(x)" -LegendSize 8 -legendBold -LegendPosition Bottom +PS\> 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -now -WorkSheetname SinX -ExcelChartDefinition $cDef -Show +``` + +This reworks an example from Add-Excel-Chart but here the chart is defined and the defintion stored in $cDef and then Export-Excel uses $cDef . + +## PARAMETERS + +### -Title +The title for the chart. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: Chart Title +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Header +No longer used. This may be removed in future versions. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartType +One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". + +```yaml +Type: eChartType +Parameter Sets: (All) +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: 3 +Default value: ColumnStacked +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartTrendLine +Superimposes one of Excel's trenline types on the chart. + +```yaml +Type: eTrendLine[] +Parameter Sets: (All) +Aliases: +Accepted values: Exponential, Linear, Logarithmic, MovingAvgerage, Polynomial, Power + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XRange +The range of cells containing values for the X-Axis - usually labels. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YRange +The range(s) of cells holding values for the Y-Axis - usually "data". + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Width +Width of the chart in pixels. Defaults to 500. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 +Default value: 500 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Height +Height of the chart in pixels. Defaults to 350. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 8 +Default value: 350 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Row +Row position of the top left corner of the chart. 0 places it at the top of the sheet, 1 below row 1 and so on. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 9 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RowOffSetPixels +Offset to position the chart by a fraction of a row. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 10 +Default value: 10 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Column +Column position of the top left corner of the chart. 0 places it at the edge of the sheet, 1 to the right of column A and so on. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 11 +Default value: 6 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ColumnOffSetPixels +Offset to position the chart by a fraction of a column. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 12 +Default value: 5 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendPosition +Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". + +```yaml +Type: eLegendPosition +Parameter Sets: (All) +Aliases: +Accepted values: Top, Left, Right, Bottom, TopRight + +Required: False +Position: 13 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendSize +Font size for the key. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 14 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LegendBold +Sets the key in bold type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +If specified, turns off display of the key. If you only have one data series it may be preferable to use the title to say what the chart is. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +Attaches a category label in charts which support this. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +Attaches a percentage label in charts which support this. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SeriesHeader +Specifies explicit name(s) for the data series, which will appear in the legend/key + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 15 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleBold +Sets the title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TitleSize +Sets the point size for the title. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 16 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleText +Specifies a title for the X-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 17 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleBold +Sets the X-axis title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisTitleSize +Sets the font size for the axis title. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 18 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisNumberformat +A number formatting string, like "#,##0.00", for numbers along the X-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 19 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMajorUnit +Spacing for the major gridlines / tick marks along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 20 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMinorUnit +Spacing for the minor gridlines / tick marks along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 21 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMaxValue +Maximum value for the scale along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 22 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XMinValue +Minimum value for the scale along the X-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 23 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -XAxisPosition +Position for the X-axis ("Top" or" Bottom"). + +```yaml +Type: eAxisPosition +Parameter Sets: (All) +Aliases: +Accepted values: Left, Bottom, Right, Top + +Required: False +Position: 24 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleText +Specifies a title for the Y-axis. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 25 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleBold +Sets the Y-axis title in bold face. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisTitleSize +Sets the font size for the Y-axis title. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 26 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisNumberformat +A number formatting string, like "#,##0.00", for numbers on the Y-axis + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 27 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMajorUnit +Spacing for the major gridlines / tick marks on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 28 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMinorUnit +Spacing for the minor gridlines / tick marks on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 29 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMaxValue +Maximum value on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 30 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YMinValue +Minimum value on the Y-axis. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 31 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -YAxisPosition +Position for the Y-axis ("Left" or "Right"). + +```yaml +Type: eAxisPosition +Parameter Sets: (All) +Aliases: +Accepted values: Left, Bottom, Right, Top + +Required: False +Position: 32 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/New-PivotTableDefinition.md b/mdHelp/New-PivotTableDefinition.md new file mode 100644 index 0000000..2fbf56a --- /dev/null +++ b/mdHelp/New-PivotTableDefinition.md @@ -0,0 +1,538 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# New-PivotTableDefinition + +## SYNOPSIS +Creates PivotTable definitons for Export-Excel + +## SYNTAX + +### ChartbyDef +``` +New-PivotTableDefinition -PivotTableName [-SourceWorkSheet ] [-SourceRange ] [-PivotRows ] [-PivotData ] [-PivotColumns ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTotals ] [-NoTotalsInPivot] [-GroupDateRow ] [-GroupDatePart ] [-GroupNumericRow ] [-GroupNumericMin ] [-GroupNumericMax ] [-GroupNumericInterval ] [-PivotNumberFormat ] [-PivotTableStyle ] -PivotChartDefinition [-Activate] [] +``` + +### ChartbyParams +``` +New-PivotTableDefinition -PivotTableName [-SourceWorkSheet ] [-SourceRange ] [-PivotRows ] [-PivotData ] [-PivotColumns ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTotals ] [-NoTotalsInPivot] [-GroupDateRow ] [-GroupDatePart ] [-GroupNumericRow ] [-GroupNumericMin ] [-GroupNumericMax ] [-GroupNumericInterval ] [-PivotNumberFormat ] [-PivotTableStyle ] [-IncludePivotChart] [-ChartTitle ] [-ChartHeight ] [-ChartWidth ] [-ChartRow ] [-ChartColumn ] [-ChartRowOffSetPixels ] [-ChartColumnOffSetPixels ] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-Activate] [] +``` + +## DESCRIPTION +Export-Excel allows a single PivotTable to be defined using the parameters -IncludePivotTable, -PivotColumns, -PivotRows, -PivotData, -PivotFilter, -PivotTotals, -PivotDataToColumn, -IncludePivotChart and -ChartType. + +Its -PivotTableDefintion paramater allows multiple PivotTables to be defined, with additional parameters. New-PivotTableDefinition is a convenient way to build these definitions. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $pt = New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet "Sheet1" -PivotRows "Status" -PivotData @{Status='Count'} -PivotFilter 'StartType' -IncludePivotChart -ChartType BarClustered3D +PS\> $Pt += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet "Sheet2" -PivotRows "Company" -PivotData @{Company='Count'} -IncludePivotChart -ChartType PieExploded3D -ShowPercent -ChartTitle "Breakdown of processes by company" +PS\> Get-Service | Select-Object -Property Status,Name,DisplayName,StartType | Export-Excel -Path .\test.xlsx -AutoSize +PS\> Get-Process | Select-Object -Property Name,Company,Handles,CPU,VM | Export-Excel -Path .\test.xlsx -AutoSize -WorksheetName 'sheet2' +PS\> $excel = Export-Excel -Path .\test.xlsx -PivotTableDefinition $pt -Show +``` +This is a re-work of one of the examples in Export-Excel - instead of writing out the pivot definition hash-table, it is built by calling New-PivotTableDefinition. + +## PARAMETERS + +### -PivotTableName +Name for the new pivot table + +This command previously had a typo - and has an alias to avoid breaking scripts This will be removed in a future release + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: PivtoTableName + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SourceWorkSheet +Worksheet where the data is found + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SourceRange +Address range in the worksheet e.g "A10:F20" - the first row must contain the column names to pivot by: if the range is not specified the whole source sheet will be used. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotRows +Fields to set as rows in the PivotTable + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotData +A hash-table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotColumns +Fields to set as columns in the PivotTable + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotFilter +Fields to use to filter in the PivotTable + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotDataToColumn +If there are multiple datasets in a PivotTable, by default they are shown seperatate rows under the given row heading; this switch makes them seperate columns. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTotals +By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Both +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoTotalsInPivot +Included for compatibility - equivalent to -PivotTotals "None" + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupDateRow +The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupDatePart +The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + +```yaml +Type: eDateGroupBy[] +Parameter Sets: (All) +Aliases: +Accepted values: Years, Quarters, Months, Days, Hours, Minutes, Seconds + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericRow +The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericMin +The starting point for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericMax +The endpoint for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 1.79769313486232E+308 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GroupNumericInterval +The interval for grouping + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 100 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotNumberFormat +Number format to apply to the data cells in the PivotTable + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotTableStyle +Apply a table style to the PivotTable + +```yaml +Type: TableStyles +Parameter Sets: (All) +Aliases: +Accepted values: None, Custom, Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9, Light10, Light11, Light12, Light13, Light14, Light15, Light16, Light17, Light18, Light19, Light20, Light21, Medium1, Medium2, Medium3, Medium4, Medium5, Medium6, Medium7, Medium8, Medium9, Medium10, Medium11, Medium12, Medium13, Medium14, Medium15, Medium16, Medium17, Medium18, Medium19, Medium20, Medium21, Medium22, Medium23, Medium24, Medium25, Medium26, Medium27, Medium28, Dark1, Dark2, Dark3, Dark4, Dark5, Dark6, Dark7, Dark8, Dark9, Dark10, Dark11 + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PivotChartDefinition +Use a chart definition instead of specifying chart settings one by one + +```yaml +Type: Object +Parameter Sets: ChartbyDef +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -IncludePivotChart +If specified a chart Will be included. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartTitle +Optional title for the pivot chart, by default the title omitted. + +```yaml +Type: String +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartHeight +Height of the chart in Pixels (400 by default) + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 400 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartWidth +Width of the chart in Pixels (600 by default) + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 600 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartRow +Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartColumn +Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E) + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 4 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartRowOffSetPixels +Vertical offset of the chart from the cell corner. + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartColumnOffSetPixels +Horizontal offset of the chart from the cell corner. + +```yaml +Type: Int32 +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ChartType +Type of chart + +```yaml +Type: eChartType +Parameter Sets: ChartbyParams +Aliases: +Accepted values: Area, Line, Pie, Bubble, ColumnClustered, ColumnStacked, ColumnStacked100, ColumnClustered3D, ColumnStacked3D, ColumnStacked1003D, BarClustered, BarStacked, BarStacked100, BarClustered3D, BarStacked3D, BarStacked1003D, LineStacked, LineStacked100, LineMarkers, LineMarkersStacked, LineMarkersStacked100, PieOfPie, PieExploded, PieExploded3D, BarOfPie, XYScatterSmooth, XYScatterSmoothNoMarkers, XYScatterLines, XYScatterLinesNoMarkers, AreaStacked, AreaStacked100, AreaStacked3D, AreaStacked1003D, DoughnutExploded, RadarMarkers, RadarFilled, Surface, SurfaceWireframe, SurfaceTopView, SurfaceTopViewWireframe, Bubble3DEffect, StockHLC, StockOHLC, StockVHLC, StockVOHLC, CylinderColClustered, CylinderColStacked, CylinderColStacked100, CylinderBarClustered, CylinderBarStacked, CylinderBarStacked100, CylinderCol, ConeColClustered, ConeColStacked, ConeColStacked100, ConeBarClustered, ConeBarStacked, ConeBarStacked100, ConeCol, PyramidColClustered, PyramidColStacked, PyramidColStacked100, PyramidBarClustered, PyramidBarStacked, PyramidBarStacked100, PyramidCol, XYScatter, Radar, Doughnut, Pie3D, Line3D, Column3D, Area3D + +Required: False +Position: Named +Default value: Pie +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLegend +If specified hides the chart legend + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowCategory +if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ShowPercent +If specified attaches percentages to slices in a pie chart. + +```yaml +Type: SwitchParameter +Parameter Sets: ChartbyParams +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Activate +If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Open-ExcelPackage.md b/mdHelp/Open-ExcelPackage.md new file mode 100644 index 0000000..c16d198 --- /dev/null +++ b/mdHelp/Open-ExcelPackage.md @@ -0,0 +1,120 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Open-ExcelPackage + +## SYNOPSIS +Returns an ExcelPackage object for the specified XLSX fil.e + +## SYNTAX + +``` +Open-ExcelPackage [-Path] [-KillExcel] [[-Password] ] [-Create] [] +``` + +## DESCRIPTION +Import-Excel and Export-Excel open an Excel file, carry out their tasks and close it again. + +Sometimes it is necessary to open a file and do other work on it. Open-ExcelPackage allows the file to be opened for these tasks. + +It takes a -KillExcel switch to make sure Excel is not holding the file open; a -Password parameter for existing protected files, and a -Create switch to set-up a new file if no file already exists. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $excel = Open-ExcelPackage -Path "$env:TEMP\test99.xlsx" -Create +PS\> $ws = Add-WorkSheet -ExcelPackage $excel +``` + +This will create a new file in the temp folder if it doesn't already exist. It then adds a worksheet - because no name is specified it will use the default name of "Sheet1" + +### EXAMPLE 2 +``` +PS\> $excela= Open-ExcelPackage -path "$xlPath" -Password $password +PS\> $sheet1 = $excel.Workbook.Worksheetsa"sheet1" ] +PS\> Set-ExcelRange -Range $sheet1.Cells ["E1:S1048576" ], $sheet1.Cells ["V1:V1048576" ] -NFormat ( [cultureinfo ]::CurrentCulture.DateTimeFormat.ShortDatePattern) +PS\> Close-ExcelPackage $excel -Show + +``` + +This will open the password protected file at $xlPath using the password stored in $Password. +Sheet1 is selected and formatting applied to two blocks of the sheet; then the file is and saved and loaded into Excel. + +## PARAMETERS + +### -Path +The path to the file to open. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -KillExcel +If specified, any running instances of Excel will be terminated before opening the file. This may result in lost work, so should be used with caution. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Password +The password for a protected worksheet, as a \[normal\] string (not a secure string). + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Create +By default Open-ExcelPackage will only open an existing file; -Create instructs it to create a new file if required. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.ExcelPackage +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Remove-WorkSheet.md b/mdHelp/Remove-WorkSheet.md new file mode 100644 index 0000000..5c1f54a --- /dev/null +++ b/mdHelp/Remove-WorkSheet.md @@ -0,0 +1,135 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Remove-WorkSheet + +## SYNOPSIS +Removes one or more worksheets from one or more workbooks + +## SYNTAX + +``` +Remove-WorkSheet [[-FullName] ] [[-WorksheetName] ] [-Show] [-WhatIf] [-Confirm] [] +``` + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1 +``` + +Removes the worksheet named 'Sheet1' from 'Test1.xlsx' + +### EXAMPLE 2 +``` +PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 +``` + +Removes the worksheet named 'Sheet1' and 'Target1' from 'Test1.xlsx' + +### EXAMPLE 3 +``` +PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 -Show +``` + +Removes the worksheets and then launches the xlsx in Excel + +### EXAMPLE 1 +``` +PS\> dir c:\reports\*.xlsx | Remove-WorkSheet +``` + +Removes 'Sheet1' from all the xlsx files in the c:\reports directory + +## PARAMETERS + +### -FullName +The fully qualified path to the XLSX file(s) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Path + +Required: False +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -WorksheetName +The worksheet to be removed (sheet1 by default) + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Show +If specified the file will be opened in excel after the sheet is removed. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Select-Worksheet.md b/mdHelp/Select-Worksheet.md new file mode 100644 index 0000000..f0e93eb --- /dev/null +++ b/mdHelp/Select-Worksheet.md @@ -0,0 +1,127 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Select-Worksheet + +## SYNOPSIS +Sets the selected tab in an Excel workbook to be the chosen sheet and unselects all the others. + +## SYNTAX + +### Package +``` +Select-Worksheet [-ExcelPackage] [-WorksheetName ] [] +``` + +### Workbook +``` +Select-Worksheet [-WorksheetName ] [] +``` + +### Sheet +``` +Select-Worksheet -ExcelWorksheet [] +``` + +## DESCRIPTION +Sometimes when a sheet is added we want it to be the active sheet, sometimes we want the active sheet to be left as it was. Select-Worksheet exists to change which sheet is the selected tab when Excel opens the file. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Select-Worksheet -ExcelWorkbook $ExcelWorkbook -WorksheetName "NewSheet" +``` + +$ExcelWorkbook holds a workbook object containing a sheet named "NewSheet"; This sheet will become the \[only\] active sheet in the workbook + +### EXAMPLE 2 +``` +PS\> Select-Worksheet -ExcelPackage $Pkg -WorksheetName "NewSheet2" +``` + +$pkg holds an Excel Package, whose workbook contains a sheet named "NewSheet2" This sheet will become the \[only\] active sheet in the workbook. + +### EXAMPLE 3 +``` +PS\> Select-Worksheet -ExcelWorksheet $ws +``` + +$ws holds an Excel worksheet which will become the \[only\] active sheet in its workbook. + +## PARAMETERS + +### -ExcelPackage +An object representing an ExcelPackage. + +```yaml +Type: ExcelPackage +Parameter Sets: Package +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -ExcelWorkbook +An Excel workbook to which the Worksheet will be added - a package contains one Workbook so you can use workbook or package as it suits. + +```yaml +Type: ExcelWorkbook +Parameter Sets: WorkBook +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WorksheetName +The name of the worksheet "Sheet1" by default. + +```yaml +Type: String +Parameter Sets: Package, Workbook +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcelWorksheet +An object representing an Excel worksheet. + +```yaml +Type: ExcelWorksheet +Parameter Sets: Sheet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Send-SQLDataToExcel.md b/mdHelp/Send-SQLDataToExcel.md new file mode 100644 index 0000000..aa0067c --- /dev/null +++ b/mdHelp/Send-SQLDataToExcel.md @@ -0,0 +1,288 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Send-SQLDataToExcel + +## SYNOPSIS +Inserts a DataTable - returned by a SQL query - into an ExcelSheet + +## SYNTAX + +### none (Default) +``` +Send-SQLDataToExcel [-QueryTimeout ] [-Force] [-Path ] [-ExcelPackage ] + [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] + [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ] + [-IncludePivotTable] [-PivotTableName ] [-PivotRows ] [-PivotColumns ] + [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] + [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] + [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] + [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] + [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] + [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] + [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] + [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] + [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] + [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] + [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +### ODBCConnection +``` +Send-SQLDataToExcel -Connection -SQL [-QueryTimeout ] [-Force] [-Path ] + [-ExcelPackage ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] + [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] + [-TitleSize ] [-TitleBackgroundColor ] [-IncludePivotTable] [-PivotTableName ] + [-PivotRows ] [-PivotColumns ] [-PivotData ] [-PivotFilter ] + [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] + [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] + [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] + [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] + [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] + [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] + [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] + [-ExcludeProperty ] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] + [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] + [-Style ] [-CellStyleSB ] [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] + [-NoTotalsInPivot] [-ReZip] [] +``` + +### SQLConnection +``` +Send-SQLDataToExcel -Connection [-MsSQLserver] [-DataBase ] -SQL [-QueryTimeout ] [-Force] [-Path ] [-ExcelPackage ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ] [-IncludePivotTable] [-PivotTableName ] [-PivotRows ] [-PivotColumns ] [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +### ExistingSession +``` +Send-SQLDataToExcel -Session -SQL [-QueryTimeout ] [-Force] [-Path ] [-ExcelPackage ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ] [-IncludePivotTable] [-PivotTableName ] [-PivotRows ] [-PivotColumns ] [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +### Pre-FetchedData +``` +Send-SQLDataToExcel [-QueryTimeout ] -DataTable [-Force] [-Path ] [-ExcelPackage ] [-Calculate] [-Show] [-WorksheetName ] [-Password ] [-ClearSheet] [-Append] [-Title ] [-TitleFillPattern ] [-TitleBold] [-TitleSize ] [-TitleBackgroundColor ] [-IncludePivotTable] [-PivotTableName ] [-PivotRows ] [-PivotColumns ] [-PivotData ] [-PivotFilter ] [-PivotDataToColumn] [-PivotTableDefinition ] [-IncludePivotChart] [-ChartType ] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows ] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane ] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName ] [-TableName ] [-TableStyle ] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition ] [-HideSheet ] [-UnHideSheet ] [-MoveToStart] [-MoveToEnd] [-MoveBefore ] [-MoveAfter ] [-KillExcel] [-AutoNameRange] [-StartRow ] [-StartColumn ] [-PassThru] [-Numberformat ] [-ExcludeProperty ] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion ] [-ConditionalFormat ] [-ConditionalText ] [-Style ] [-CellStyleSB ] [-Activate] [-Now] [-ReturnRange] [-PivotTotals ] [-NoTotalsInPivot] [-ReZip] [] +``` + +## DESCRIPTION +This command takes a SQL statement and run it against a database connection; for the connection it accepts either + +* an object representing a session with a SQL server or ODBC database, or +* a connection string to make a session (if -MSSQLServer is specified it uses the SQL Native client, + and -Connection can be a server name instead of a detailed connection string. Without this switch it uses ODBC) + +The command takes all the parameters of Export-Excel, except for -InputObject (alias TargetData); after fetching the data it calls Export-Excel with the data as the value of InputParameter and whichever of Export-Excel's parameters it was passed; for details of these parameters see the help for Export-Excel. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Send-SQLDataToExcel -MsSQLserver -Connection localhost -SQL "select name,type,type_desc from [master].[sys].[all_objects]" -Path .\temp.xlsx -WorkSheetname master -AutoSize -FreezeTopRow -AutoFilter -BoldTopRow +``` + +Connects to the local SQL server and selects 3 columns from \[Sys\].\[all_objects\] and exports then to a sheet named master with some basic header management + +### EXAMPLE 2 +``` +PS\> $dbPath = 'C:\Users\James\Documents\Database1.accdb' +PS\> $Connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbPath;" +PS\> $SQL="SELECT top 25 Name,Length From TestData ORDER BY Length DESC" +PS\> Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo1.xlsx -WorkSheetname "Sizes" -AutoSize +``` + +This creates an ODBC connection string to read from an Access file and a SQL Statement to extracts data from it, and sends the resulting data to a new worksheet + +### EXAMPLE 3 +``` +PS\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' + +PS\> $Connection = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=$dbPath;" +PS\> $SQL="SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + + " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" + +PS\>Send-SQLDataToExcel -Connection $connection -SQL $sql -path .\demo2.xlsx -WorkSheetname "Winners" -AutoSize -AutoNameRange -ConditionalFormat @{DataBarColor="Blue"; Range="Wins"} +``` + +Similar to the previous example, this creates a connection string, this time for an Excel file, and runs a SQL statement to get a list of motor-racing results, outputting the resulting data to a new spreadsheet. The spreadsheet is formatted and a data bar added to show make the drivers' wins clearer. (The F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) + +### EXAMPLE 4 +``` +PS\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' + +PS\> $SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + + " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" +PS\> $null = Get-SQL -Session F1 -excel -Connection $dbPath -sql $sql -OutputVariable Table + +PS\> Send-SQLDataToExcel -DataTable $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show +``` +This uses Get-SQL (at least V1.1 - download from the PowerShell gallery with Install-Module -Name GetSQL - (note the function is Get-SQL the module is GetSQL without the "-" ) + +Get-SQL simplifies making database connections and building /submitting SQL statements. Here Get-SQL uses the same SQL statement as before; -OutputVariable leaves a System.Data.DataTable object in $table and Send-SQLDataToExcel puts $table into the worksheet and sets it as an Excel table. +The command is equivalent to running + +PS\> Export-Excel -inputObject $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show + +This is quicker than using +PS\> Get-SQL \ | export-excel -ExcludeProperty rowerror,rowstate,table,itemarray,haserrors \ + +(the F1 results database is available from https://1drv.ms/x/s!AhfYu7-CJv4ehNdZWxJE9LMAX_N5sg ) + +### EXAMPLE 5 +``` +PS\>$SQL = "SELECT top 25 DriverName, Count(Win) as Wins FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" +PS\> Send-SQLDataToExcel -Session $DbSessions\["f1"\] -SQL $sql -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -ClearSheet -autosize -ColumnChart +``` + +Like the previous example, this uses Get-SQL (download from the gallery with Install-Module -Name GetSQL). It uses the database session which Get-SQL created, rather than an ODBC connection string. The Session parameter can either be a object (as shown here), or the name used by Get-SQL ("F1" in this case). + +Here the data is presented as a quick chart. + +### EXAMPLE 6 +``` +Send-SQLDataToExcel -path .\demo4.xlsx -WorkSheetname "LR" -Connection "DSN=LR" -sql "SELECT name AS CollectionName FROM AgLibraryCollection Collection ORDER BY CollectionName" +``` + +This example uses an Existing ODBC datasource name "LR" which maps to an adobe lightroom database and gets a list of collection names into a worksheet + +## PARAMETERS + +### -Connection +A database connection string to be used to create a database session; either + +* A Data source name written in the form DSN=ODBC_Data_Source_Name, or +* A full ODBC or SQL Native Client Connection string, or +* The name of a SQL server. + +```yaml +Type: Object +Parameter Sets: ODBCConnection, SQLConnection +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Session +An active ODBC Connection or SQL connection object representing a session with a database which will be queried to get the data . + +```yaml +Type: Object +Parameter Sets: ExistingSession +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MsSQLserver +Specifies the connection string is for SQL server, not ODBC. + +```yaml +Type: SwitchParameter +Parameter Sets: SQLConnection +Aliases: + +Required: True +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataBase +Switches to a specific database on a SQL server. + +```yaml +Type: String +Parameter Sets: SQLConnection +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SQL +The SQL query to run against the session which was passed in -Session or set up from -Connection. + +```yaml +Type: String +Parameter Sets: ODBCConnection, SQLConnection, ExistingSession +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -QueryTimeout +Override the default query time of 30 seconds. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DataTable +A System.Data.DataTable object containing the data to be inserted into the spreadsheet without running a query. This remains supported to avoid breaking older scripts, but if you have a DataTable object you can pass the it into Export-Excel using -InputObject. + +```yaml +Type: DataTable +Parameter Sets: Pre-FetchedData +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Force +If specified Export-Excel will be called with parameters specified, even if there is no data to send + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + +[Export-Excel]() + diff --git a/mdHelp/Set-ExcelColumn.md b/mdHelp/Set-ExcelColumn.md new file mode 100644 index 0000000..96d0464 --- /dev/null +++ b/mdHelp/Set-ExcelColumn.md @@ -0,0 +1,567 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Set-ExcelColumn + +## SYNOPSIS +Adds or modifies a column in an Excel worksheet, filling values, setting formatting and/or creating named ranges. + +## SYNTAX + +### Package +``` +Set-ExcelColumn -ExcelPackage [-Worksheetname ] [-Column ] [-StartRow ] [-Value ] [-Heading ] [-NumberFormat ] [-BorderAround ] [-FontColor ] [-Bold] [-Italic] [-Underline] [-UnderLineType ] [-StrikeThru] [-FontShift ] [-FontName ] [-FontSize ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-WrapText] [-HorizontalAlignment ] [-VerticalAlignment ] [-TextRotation ] [-AutoSize] [-Width ] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [] +``` + +### sheet +``` +Set-ExcelColumn -Worksheet [-Column ] [-StartRow ] [-Value ] [-Heading ] [-NumberFormat ] [-BorderAround ] [-FontColor ] [-Bold] [-Italic] [-Underline] [-UnderLineType ] [-StrikeThru] [-FontShift ] [-FontName ] [-FontSize ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-WrapText] [-HorizontalAlignment ] [-VerticalAlignment ] [-TextRotation ] [-AutoSize] [-Width ] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [] +``` + +## DESCRIPTION +Set-ExcelColumn can take a value which is either a string containing a value or formula or a scriptblock which evaluates to a string, and optionally a column number and fills that value down the column. + +A column heading can be specified, and the column can be made a named range. + +The column can be formatted in the same operation. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency' +``` + +$ws contains a worksheet object - and column "E" is set to use the local currency format. + +Intelisense will complete the names of predefined number formats. + +You can see how currency is interpreted on the local computer with the command Expand-NumberFormat currency + +### EXAMPLE 2 +``` +PS\> Set-ExcelColumn -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange +``` + +Here, $WS already contains a worksheet which holds counts of races won and fastest laps recorded by racing drivers (in columns C and E). +Set-ExcelColumn specifies that Column 7 should have a heading of "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc +the new data cells should become a named range, which will also be named "WinsToFastLaps" and the column width will be set automatically. + +When a value begins with "=", it is treated as a formula. + +If value is a script block it will be evaluated, so here the string "=E$row/C$Row" will have the number of the current row inserted; see the value parameter for a list of variables which can be used. + +Note than when evaluating an expression in a string, it is necessary to wrap it in $() so $row is valid but $($row+1) is needed. + +To preventVariables merging into other parts of the string, use the back tick "$columnName\`4" will be "G4" - without the backtick the string will look for a variable named "columnName4" + +### EXAMPLE 3 +``` +Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize +``` + +In this example, the worksheet in $ws has partial links to Wikipedia pages in column B. + +The -Value parameter is a script block which outputs a string beginning "https..." and ending with the value of the cell at column B in the current row. + +When given a valid URI, Set-ExcelColumn makes it a hyperlink. + +The column will be autosized to fit the links. + +### EXAMPLE 4 +``` +4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange +``` + +Again $ws contains a worksheet. Here columns 4 to 6 are made into named ranges, row 1 is used for the range name and the rest of the column becomes the range. + +## PARAMETERS + +### -ExcelPackage +If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. + +```yaml +Type: ExcelPackage +Parameter Sets: Package +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Worksheetname +The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. + +```yaml +Type: String +Parameter Sets: Package +Aliases: + +Required: False +Position: Named +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Worksheet +This passes the worksheet object instead of passing a sheet name and an Excelpackage object. + +```yaml +Type: ExcelWorksheet +Parameter Sets: sheet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Column +Column to fill down - the first column is 1. 0 will be interpreted as first empty column. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -StartRow +First row to fill data in. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column \[number\], $columnName \[letter(s)\], $startRow, $startColumn, $endRow, $endColumn. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Heading +Optional column heading. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumberFormat +Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;\[Red\]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: NFormat + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderAround +Style of border to draw around the row. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontColor +Colour for the text - if none specified it will be left as it it is. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Bold +Make text bold; use -Bold:$false to remove bold. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Italic +Make text italic; use -Italic:$false to remove italic. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Underline +Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnderLineType +Specifies whether underlining should be single or double, normal or accounting mode. +The default is "Single". + +```yaml +Type: ExcelUnderLineType +Parameter Sets: (All) +Aliases: +Accepted values: None, Single, Double, SingleAccounting, DoubleAccounting + +Required: False +Position: Named +Default value: Single +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StrikeThru +Strike through text; use -StrikeThru:$false to remove strike through. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontShift +Subscript or Superscript (or None). + +```yaml +Type: ExcelVerticalAlignmentFont +Parameter Sets: (All) +Aliases: +Accepted values: None, Baseline, Subscript, Superscript + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontName +Font to use - Excel defaults to Calibri. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontSize +Point size for the text. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +Change background color. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundPattern +Background pattern - "Solid" by default. + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternColor +Secondary color for background pattern. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: PatternColour + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WrapText +Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HorizontalAlignment +Position cell contents to Left, Right, Center etc. Default is "General". + +```yaml +Type: ExcelHorizontalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: General, Left, Center, CenterContinuous, Right, Fill, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VerticalAlignment +Position cell contents to Top, Bottom or Center. + +```yaml +Type: ExcelVerticalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: Top, Center, Bottom, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TextRotation +Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoSize +Attempt to auto-fit cells to the width their contents. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: AutoFit + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Width +Set cells to a fixed width, ignored if -AutoSize is specified. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoNameRange +Set the inserted data to be a named range. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Hide +Hide the column. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Specified +If specified, returns the range of cells which were affected. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If specified, return an object representing the Column, to allow further work to be done on it. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.ExcelColumn +### System.String +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Set-ExcelRange.md b/mdHelp/Set-ExcelRange.md new file mode 100644 index 0000000..551b738 --- /dev/null +++ b/mdHelp/Set-ExcelRange.md @@ -0,0 +1,594 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Set-ExcelRange + +## SYNOPSIS +Applies number, font, alignment and/or color formatting, values or formulas to a range of Excel cells. + +## SYNTAX + +``` +Set-ExcelRange [[-Range] ] [-WorkSheet ] [-NumberFormat ] [-BorderAround ] [-BorderColor ] [-BorderBottom ] [-BorderTop ] [-BorderLeft ] [-BorderRight ] [-FontColor ] [-Value ] [-Formula ] [-ArrayFormula] [-ResetFont] [-Bold] [-Italic] [-Underline] [-UnderLineType ] [-StrikeThru] [-FontShift ] [-FontName ] [-FontSize ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-WrapText] [-HorizontalAlignment ] [-VerticalAlignment ] [-TextRotation ] [-AutoSize] [-Width ] [-Height ] [-Hidden] [-Locked] [-Merge] [] +``` + +## DESCRIPTION +Set-ExcelRange was created to set the style elements for a range of cells, this includes auto-sizing and hiding, setting font elements (Name, Size, Bold, Italic, Underline & UnderlineStyle and Subscript & SuperScript), font and background colors, borders, text wrapping, rotation, alignment within cells, and number format. + +It was orignally named "Set-Format", but it has been extended to set Values, Formulas and ArrayFormulas (sometimes called Ctrl-shift-Enter \[CSE\] formulas); because of this, the name has become Set-ExcelRange but the old name of Set-Format is preserved as an alias. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NumberFormat "#,###" -AutoFit +``` + +Selects column 3 from a sheet object (within a workbook object, which is a child of the ExcelPackage object) and passes it to Set-ExcelRange which formats numbers as a integers with comma-separated groups, aligns it right, and auto-fits the column to the contents. + +### EXAMPLE 2 +``` +PS\> Set-ExcelRange -Range $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###" +``` + +Instead of piping the address, this version specifies a block of cells and applies similar formatting. + +### EXAMPLE 3 +``` +PS\> Set-ExcelRange $excel.Workbook.Worksheets[1].Tables["Processes"] -Italic +``` + +This time instead of specifying a range of cells, a table is selected by name and formatted as italic. + +## PARAMETERS + +### -Range +One or more row(s), Column(s) and/or block(s) of cells to format. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Address + +Required: False +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -WorkSheet +The worksheet where the format is to be applied. + +```yaml +Type: ExcelWorksheet +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumberFormat +Number format to apply to cells for example "dd/MM/yyyy HH:mm", "£#,##0.00;\[Red\]-£#,##0.00", "0.00%" , "##/##" or "0.0E+0" etc. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: NFormat + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderAround +Style of border to draw around the range. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderColor +Color of the border. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::Black +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderBottom +Style for the bottom border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderTop +Style for the top border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderLeft +Style for the left border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderRight +Style for the right border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontColor +Colour for the text - if none is specified it will be left as it is. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: ForegroundColor + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +Value for the cell. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Formula +Formula for the cell. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ArrayFormula +Specifies formula should be an array formula (a.k.a CSE \[ctrl-shift-enter\] formula). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResetFont +Clear Bold, Italic, StrikeThrough and Underline and set color to Black. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Bold +Make text bold; use -Bold:$false to remove bold. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Italic +Make text italic; use -Italic:$false to remove italic. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Underline +Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnderLineType +Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + +```yaml +Type: ExcelUnderLineType +Parameter Sets: (All) +Aliases: +Accepted values: None, Single, Double, SingleAccounting, DoubleAccounting + +Required: False +Position: Named +Default value: Single +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StrikeThru +Strike through text; use -Strikethru:$false to remove Strike through + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontShift +Subscript or Superscript (or none). + +```yaml +Type: ExcelVerticalAlignmentFont +Parameter Sets: (All) +Aliases: +Accepted values: None, Baseline, Subscript, Superscript + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontName +Font to use - Excel defaults to Calibri. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontSize +Point size for the text. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +Change background color. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundPattern +Background pattern - Solid by default. + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternColor +Secondary color for background pattern. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: PatternColour + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WrapText +Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HorizontalAlignment +Position cell contents to Left, Right, Center etc. +default is 'General'. + +```yaml +Type: ExcelHorizontalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: General, Left, Center, CenterContinuous, Right, Fill, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VerticalAlignment +Position cell contents to Top, Bottom or Center. + +```yaml +Type: ExcelVerticalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: Top, Center, Bottom, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TextRotation +Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AutoSize +Autofit cells to width (columns or ranges only). + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: AutoFit + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Width +Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Height +Set cells to a fixed height (rows or ranges only). + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Hidden +Hide a row or column (not a range); use -Hidden:$false to unhide. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Locked +Locks cells. Cells are locked by default use -locked:$false on the whole sheet and then lock specific ones, and enable protection on the sheet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Merge +Merges cells - it is recommended that you explicitly set -HorizontalAlignment + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Set-ExcelRow.md b/mdHelp/Set-ExcelRow.md new file mode 100644 index 0000000..447b37d --- /dev/null +++ b/mdHelp/Set-ExcelRow.md @@ -0,0 +1,622 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: +schema: 2.0.0 +--- + +# Set-ExcelRow + +## SYNOPSIS +Fills values into a \[new\] row in an Excel spreadsheet, and sets row formats. + +## SYNTAX + +### Package +``` +Set-ExcelRow -ExcelPackage [-Worksheetname ] [-Row ] [-StartColumn ] [-Value ] [-Heading ] [-HeadingBold] [-HeadingSize ] [-NumberFormat ] [-BorderAround ] [-BorderColor ] [-BorderBottom ] [-BorderTop ] [-BorderLeft ] [-BorderRight ] [-FontColor ] [-Bold] [-Italic] [-Underline] [-UnderLineType ] [-StrikeThru] + [-FontShift ] [-FontName ] [-FontSize ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-WrapText] [-HorizontalAlignment ] [-VerticalAlignment ] [-TextRotation ] [-Height ] [-Hide] [-ReturnRange] [-PassThru] [] +``` + +### Sheet +``` +Set-ExcelRow -Worksheet [-Row ] [-StartColumn ] [-Value ] [-Heading ] [-HeadingBold] [-HeadingSize ] [-NumberFormat ] [-BorderAround ] [-BorderColor ] [-BorderBottom ] [-BorderTop ] [-BorderLeft ] [-BorderRight ] [-FontColor ] [-Bold] [-Italic] [-Underline] [-UnderLineType ] [-StrikeThru] [-FontShift ] [-FontName ] [-FontSize ] [-BackgroundColor ] [-BackgroundPattern ] [-PatternColor ] [-WrapText] [-HorizontalAlignment ] [-VerticalAlignment ] [-TextRotation ] [-Height ] [-Hide] [-ReturnRange] [-PassThru] [] +``` + +## DESCRIPTION +Set-ExcelRow accepts either a Worksheet object or an ExcelPackage object returned by Export-Excel and the name of a sheet, and inserts the chosen contents into a row of the sheet. + +The contents can be a constant, like "42", a formula or a script block which is converted into a constant or a formula. + +The first cell of the row can optionally be given a heading. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> Set-ExcelRow -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" } +``` + +$Ws contains a worksheet object, and no Row number is specified so Set-ExcelRow will select the next row after the end of the data in the sheet. + +The first cell in the row will contain "Total", and each of the other cells will contain =Sum(xx2:xx99) where xx is the column name, and 99 is the last row of data. + +Note the use of the backtick in the script block (\`2) to Prevent 2 becoming part of the variable "ColumnName" + +The script block can use $Worksheet, $Row, $Column (number), $ColumnName (letter), $StartRow/Column and $EndRow/Column. + +### EXAMPLE 2 +``` +PS\> Set-ExcelRow -Worksheet $ws -Heading Total -HeadingBold -Value {"=sum($columnName`2:$columnName$endrow)" } -NumberFormat 'Currency' -StartColumn 2 -Bold -BorderTop Double -BorderBottom Thin +``` + +This builds on the previous example, but this time the label "Total" appears in column 2 and the formula fills from column 3 onwards. + +The formula and heading are set in bold face, and the formula is formatted for the local currency, and given a double line border above and single line border below. + +## PARAMETERS + +### -ExcelPackage +An Excel package object - for example from Export-Excel -PassThru - if specified requires a sheet name to be passed a parameter. + +```yaml +Type: ExcelPackage +Parameter Sets: Package +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Worksheetname +The name of the sheet to update in the package. + +```yaml +Type: Object +Parameter Sets: Package +Aliases: + +Required: False +Position: Named +Default value: Sheet1 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Worksheet +A worksheet object instead of passing a name and package. + +```yaml +Type: ExcelWorksheet +Parameter Sets: Sheet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Row +Row to fill right - first row is 1. 0 will be interpreted as first unused row. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -StartColumn +Position in the row to start from. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column \[number\], $ColumnName \[letter(s)\], $startRow, $startColumn, $endRow, $endColumn. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Heading +Optional row-heading. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HeadingBold +Set the heading in bold type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HeadingSize +Change the font-size of the heading. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumberFormat +Number format to apply to cells e.g. +"dd/MM/yyyy HH:mm", "£#,##0.00;\[Red\]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: NFormat + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderAround +Style of border to draw around the row. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderColor +Color of the border. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: [System.Drawing.Color]::Black +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderBottom +Style for the bottom border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderTop +Style for the top border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderLeft +Style for the left border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BorderRight +Style for the right border. + +```yaml +Type: ExcelBorderStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Hair, Dotted, DashDot, Thin, DashDotDot, Dashed, MediumDashDotDot, MediumDashed, MediumDashDot, Thick, Medium, Double + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontColor +Color for the text - if not specified the font will be left as it it is. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Bold +Make text bold; use -Bold:$false to remove bold. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Italic +Make text italic; use -Italic:$false to remove italic. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Underline +Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnderLineType +Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". + +```yaml +Type: ExcelUnderLineType +Parameter Sets: (All) +Aliases: +Accepted values: None, Single, Double, SingleAccounting, DoubleAccounting + +Required: False +Position: Named +Default value: Single +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StrikeThru +Strike through text; use -StrikeThru:$false to remove strike through. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontShift +Subscript or Superscript (or none). + +```yaml +Type: ExcelVerticalAlignmentFont +Parameter Sets: (All) +Aliases: +Accepted values: None, Baseline, Subscript, Superscript + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontName +Font to use - Excel defaults to Calibri. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FontSize +Point size for the text. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundColor +Change background color. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BackgroundPattern +Background pattern - solid by default. + +```yaml +Type: ExcelFillStyle +Parameter Sets: (All) +Aliases: +Accepted values: None, Solid, DarkGray, MediumGray, LightGray, Gray125, Gray0625, DarkVertical, DarkHorizontal, DarkDown, DarkUp, DarkGrid, DarkTrellis, LightVertical, LightHorizontal, LightDown, LightUp, LightGrid, LightTrellis + +Required: False +Position: Named +Default value: Solid +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PatternColor +Secondary color for background pattern. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: PatternColour + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WrapText +Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HorizontalAlignment +Position cell contents to Left, Right, Center etc. +default is 'General'. + +```yaml +Type: ExcelHorizontalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: General, Left, Center, CenterContinuous, Right, Fill, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VerticalAlignment +Position cell contents to Top, Bottom or Center. + +```yaml +Type: ExcelVerticalAlignment +Parameter Sets: (All) +Aliases: +Accepted values: Top, Center, Bottom, Distributed, Justify + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TextRotation +Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Height +Set cells to a fixed height. + +```yaml +Type: Single +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Hide +Hide the row. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ReturnRange +If sepecified, returns the range of cells which were affected. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +If Specified, return a row object to allow further work to be done. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### OfficeOpenXml.ExcelRow +### System.String +## NOTES + +## RELATED LINKS diff --git a/mdHelp/Update-FirstObjectProperties.md b/mdHelp/Update-FirstObjectProperties.md new file mode 100644 index 0000000..4fd13a5 --- /dev/null +++ b/mdHelp/Update-FirstObjectProperties.md @@ -0,0 +1,94 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# Update-FirstObjectProperties + +## SYNOPSIS +Updates the first object to contain all the properties of the object with the most properties in the array. + +## SYNTAX +``` +Update-FirstObjectProperties +``` + +## DESCRIPTION +Updates the first object to contain all the properties found anywhere in the array. + +This is usefull when not all objects have the same quantity of properties and CmdLets like Out-GridView or Export-Excel are not able to show all the properties because the first object doesn't have them all. + +## EXAMPLES + +### EXAMPLE 1 +``` +PS\> $Array = @() +PS\> $Obj1 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' +} +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} +PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Out-GridView -Title 'All properties are visible' +``` + +Updates the first object of the array by adding Member3 and Member4 and shows before and after in gridviews + +### EXAMPLE 2 +``` +PS\>$ExcelParams = @{ + Path = $env:TEMP + '\Excel.xlsx' + Show = $true + Verbose = $true +} +PS\> Remove-Item -Path $ExcelParams.Path -Force -EA Ignore +PS\> $Array = @() +PS\> $Obj1 = [PSCustomObjectable@{ + Member1 = 'First' + Member2 = 'Second' +} +PS\> $Obj2 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' +} +PS\> $Obj3 = [PSCustomObject]@{ + Member1 = 'First' + Member2 = 'Second' + Member3 = 'Third' + Member4 = 'Fourth' +} +PS\> $Array = $Obj1, $Obj2, $Obj3 +PS\> $Array | Out-GridView -Title 'Not showing Member3 and Member4' +PS\> $Array | Update-FirstObjectProperties | Export-Excel @ExcelParams -WorkSheetname Numbers +``` + +Updates the first object of the array by adding property 'Member3' and 'Member4'. Afterwards, all objects are exported to an Excel file and all column headers are visible. + +## PARAMETERS + +## INPUTS + +## OUTPUTS + +## NOTES +CHANGELOG +2017/06/08 Function born + +## RELATED LINKS + +[https://github.com/dfinke/ImportExcel](https://github.com/dfinke/ImportExcel) +