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] <Object> [[-WorkSheetname] <Object>] [-Range] <Object> [[-Destination] <Object>] [-Show] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Path to the Excel file | true | False | None | |
none | Worksheet name - if none is specified "Sheet1" will be assumed | false | False | Sheet1 | |
none | Range of cells within the sheet, e.g "A1:Z99" | true | False | None | |
none | A bmp, png or jpg file where the result will be saved | false | False | "$pwd\temp.png" | |
none | If specified opens the image in the default viewer. | false | False | False |
Exports Sheets from Excel Workbooks to CSV files.
This command provides a convenient way to run Import-Excel @ImportParameters | Select-Object @selectParameters | export-Csv @ ExportParameters It can take the parameters -AsText , as used in Import-Excel, )Properties & -ExcludeProperties as used in Select-Object and -Append, -Delimiter and -Encoding as used in Export-CSV
ConvertFrom-ExcelSheet [-Path] <String> [[-OutputPath] <String>] [[-SheetName] <String>] [[-Encoding] <Encoding>] [[-Extension] {.txt | .log | .csv}] [[-Delimiter] {; | | }] [[-Property] <Object>] [[-ExcludeProperty] <Object>] [[-AsText] <String[]>] [[-AsDate] <String[]>] [-Append] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Use this parameter to have the export add output to the end of the file. Without this parameter, the command replaces the file contents without warning. | false | False | False | |
none | AsText allows selected columns to be returned as the text displayed in their cells, instead of their value. (* is supported as a wildcard.) | false | False | None | |
none | Not all date formats are recognized as indicating the number in the cell represents a date AsDate forces the number which would be returned to be converted to a date. (* is supported as a wildcard.) | false | False | None | |
none | Selects , or ; as the delimeter for the exported data - if not specified , is used by default. | false | False | None | |
none | Sets the text encoding for the output data file; UTF8 bu default | false | False | None | |
none | Specifies the properties that to exclude from the export. Wildcards are permitted. This parameter is effective only when the command also includes the Property parameter. | false | False | None | |
none | Sets the file extension for the exported data, defaults to CSV | false | False | None | |
none | The directory where the output file(s) will be created. The file name(s) will match the name of the workbook page which contained the data. | false | False | None | |
none | The path to the .XLSX file which will be exported. | true | False | None | |
none | Specifies the properties to select. Wildcards are permitted - the default is "*". The value of the Property parameter can be a new calculated property, and follows the same pattern as Select-Item | false | False | None | |
none | The name of a sheet to export, or a regular expression which is used to identify sheets | false | False | None |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText GridPosition,date
PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText "GridPosition" -Property driver, @{n="date"; e={[datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#")}} , FinishPosition, GridPosition
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] <Object>] [[-RowOffSetPixels] <Object>] [[-Column] <Object>] [[-ColumnOffSetPixels] <Object>] [[-LegendPosition] {Top | Left | Right | Bottom | TopRight}] [[-LegendSize] <Object>] [[-SeriesHeader] <Object>] [[-TitleSize] <Int32>] [[-XAxisTitleText] <String>] [[-XAxisTitleSize] <Object>] [[-XAxisNumberformat] <String>] [[-Header] <Object>] [[-XMajorUnit] <Object>] [[-XMinorUnit] <Object>] [[-XMaxValue] <Object>] [[-XMinValue] <Object>] [[-XAxisPosition] {Left | Bottom | Right | Top}] [[-YAxisTitleText] <String>] [[-YAxisTitleSize] <Object>] [[-YAxisNumberformat] <String>] [[-YMajorUnit] <Object>] [[-YMinorUnit] <Object>] [[-ChartType] {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}] [[-YMaxValue] <Object>] [[-YMinValue] <Object>] [[-YAxisPosition] {Left | Bottom | Right | Top}] [[-ChartTrendLine] {Exponential | Linear | Logarithmic | MovingAvgerage | Polynomial | Power}] [[-XRange] <Object>] [[-YRange] <Object>] [[-Width] <Object>] [[-Height] <Object>] [[-Row] <Object>] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-TitleBold] [-XAxisTitleBold] [-YAxisTitleBold] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The title for the chart. | false | False | Chart Title | |
none | No longer used. This may be removed in future versions. | false | False | None | |
none | One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". | false | False | ColumnStacked | |
none | Superimposes one of Excel's trenline types on the chart. | false | False | None | |
none | The range of cells containing values for the X-Axis - usually labels. | false | False | None | |
none | The range(s) of cells holding values for the Y-Axis - usually "data". | false | False | None | |
none | Width of the chart in pixels. Defaults to 500. | false | False | 500 | |
none | Height of the chart in pixels. Defaults to 350. | false | False | 350 | |
none | 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. | false | False | 0 | |
none | Offset to position the chart by a fraction of a row. | false | False | 10 | |
none | 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. | false | False | 6 | |
none | Offset to position the chart by a fraction of a column. | false | False | 5 | |
none | Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". | false | False | None | |
none | Font size for the key. | false | False | None | |
none | Sets the key in bold type. | false | False | False | |
none | 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. | false | False | False | |
none | Attaches a category label in charts which support this. | false | False | False | |
none | Attaches a percentage label in charts which support this. | false | False | False | |
none | Specifies explicit name(s) for the data series, which will appear in the legend/key | false | False | None | |
none | Sets the title in bold face. | false | False | False | |
none | Sets the point size for the title. | false | False | 0 | |
none | Specifies a title for the X-axis. | false | False | None | |
none | Sets the X-axis title in bold face. | false | False | False | |
none | Sets the font size for the axis title. | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers along the X-axis. | false | False | None | |
none | Spacing for the major gridlines / tick marks along the X-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks along the X-axis. | false | False | None | |
none | Maximum value for the scale along the X-axis. | false | False | None | |
none | Minimum value for the scale along the X-axis. | false | False | None | |
none | Position for the X-axis ("Top" or" Bottom"). | false | False | None | |
none | Specifies a title for the Y-axis. | false | False | None | |
none | Sets the Y-axis title in bold face. | false | False | False | |
none | Sets the font size for the Y-axis title. | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers on the Y-axis | false | False | None | |
none | Spacing for the major gridlines / tick marks on the Y-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks on the Y-axis. | false | False | None | |
none | Maximum value on the Y-axis. | false | False | None | |
none | Minimum value on the Y-axis. | false | False | None | |
none | Position for the Y-axis ("Left" or "Right"). | false | False | None |
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
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 <ExcelPackage> [-Worksheetname <String>] [-Column <Object>] [-StartRow <Int32>] [-Value <Object>] [-Heading <Object>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [<CommonParameters>] Set-ExcelColumn -Worksheet <ExcelWorksheet> [-Column <Object>] [-StartRow <Int32>] [-Value <Object>] [-Heading <Object>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. | true | False | None | |
none | The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. | false | False | Sheet1 | |
none | This passes the worksheet object instead of passing a sheet name and an Excelpackage object. | true | False | None | |
none | Column to fill down - the first column is 1. 0 will be interpreted as first empty column. | false | True (ByValue) | 0 | |
none | First row to fill data in. | false | False | 0 | |
none | A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. | false | False | None | |
none | Optional column heading. | false | False | None | |
NFormat | 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. | false | False | None | |
none | Style of border to draw around the row. | false | False | None | |
none | Colour for the text - if none specified it will be left as it it is. | false | False | None | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -StrikeThru:$false to remove strike through. | false | False | False | |
none | Subscript or Superscript (or None). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - "Solid" by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. Default is "General". | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
AutoFit | Attempt to auto-fit cells to the width their contents. | false | False | False | |
none | Set cells to a fixed width, ignored if -AutoSize is specified. | false | False | 0 | |
none | Set the inserted data to be a named range. | false | False | False | |
Hidden | Hide the column. | false | False | False | |
none | If specified, returns the range of cells which were affected. | false | False | False | |
none | If specified, return an object representing the Column, to allow further work to be done on it. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency'
PS\> Set-ExcelColumn -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange
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] <Object>] [-WorkSheet <ExcelWorksheet>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Value <Object>] [-Formula <Object>] [-ArrayFormula] [-ResetFont] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-Height <Single>] [-Hidden] [-Locked] [-Merge] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Address | One or more row(s), Column(s) and/or block(s) of cells to format. | false | True (ByValue) | None | |
none | The worksheet where the format is to be applied. | false | False | None | |
NFormat | 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. | false | False | None | |
none | Style of border to draw around the range. | false | False | None | |
none | Color of the border. | false | False | [System.Drawing.Color]::Black | |
none | Style for the bottom border. | false | False | None | |
none | Style for the top border. | false | False | None | |
none | Style for the left border. | false | False | None | |
none | Style for the right border. | false | False | None | |
ForegroundColor | Colour for the text - if none is specified it will be left as it is. | false | False | None | |
none | Value for the cell. | false | False | None | |
none | Formula for the cell. | false | False | None | |
none | Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). | false | False | False | |
none | Clear Bold, Italic, StrikeThrough and Underline and set color to Black. | false | False | False | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -Strikethru:$false to remove Strike through | false | False | False | |
none | Subscript or Superscript (or none). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - Solid by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. default is 'General'. | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
AutoFit | Autofit cells to width (columns or ranges only). | false | False | False | |
none | Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. | false | False | 0 | |
none | Set cells to a fixed height (rows or ranges only). | false | False | 0 | |
Hide | Hide a row or column (not a range); use -Hidden:$false to unhide. | false | False | False | |
none | 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. | false | False | False | |
none | Merges cells - it is recommended that you explicitly set -HorizontalAlignment | false | False | False |
PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NumberFormat "#,###" -AutoFit
PS\> Set-ExcelRange -Range $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###"
PS\> Set-ExcelRange $excel.Workbook.Worksheets[1].Tables["Processes"] -Italic
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 <ExcelPackage> [-Worksheetname <Object>] [-Row <Object>] [-StartColumn <Int32>] [-Value <Object>] [-Heading <Object>] [-HeadingBold] [-HeadingSize <Int32>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-Height <Single>] [-Hide] [-ReturnRange] [-PassThru] [<CommonParameters>] Set-ExcelRow -Worksheet <ExcelWorksheet> [-Row <Object>] [-StartColumn <Int32>] [-Value <Object>] [-Heading <Object>] [-HeadingBold] [-HeadingSize <Int32>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-Height <Single>] [-Hide] [-ReturnRange] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | An Excel package object - for example from Export-Excel -PassThru - if specified requires a sheet name to be passed a parameter. | true | False | None | |
none | The name of the sheet to update in the package. | false | False | Sheet1 | |
none | A worksheet object instead of passing a name and package. | true | False | None | |
none | Row to fill right - first row is 1. 0 will be interpreted as first unused row. | false | True (ByValue) | 0 | |
none | Position in the row to start from. | false | False | 0 | |
none | Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. | false | False | None | |
none | Optional row-heading. | false | False | None | |
none | Set the heading in bold type. | false | False | False | |
none | Change the font-size of the heading. | false | False | 0 | |
NFormat | Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. | false | False | None | |
none | Style of border to draw around the row. | false | False | None | |
none | Color of the border. | false | False | [System.Drawing.Color]::Black | |
none | Style for the bottom border. | false | False | None | |
none | Style for the top border. | false | False | None | |
none | Style for the left border. | false | False | None | |
none | Style for the right border. | false | False | None | |
none | Color for the text - if not specified the font will be left as it it is. | false | False | None | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -StrikeThru:$false to remove strike through. | false | False | False | |
none | Subscript or Superscript (or none). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - solid by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. default is 'General'. | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
none | Set cells to a fixed height. | false | False | 0 | |
Hidden | Hide the row. | false | False | False | |
none | If sepecified, returns the range of cells which were affected. | false | False | False | |
none | If Specified, return a row object to allow further work to be done. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Set-ExcelRow -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" }
PS\> Set-ExcelRow -Worksheet $ws -Heading Total -HeadingBold -Value {"=sum($columnName`2:$columnName$endrow)" } -NumberFormat 'Currency' -StartColumn 2 -Bold -BorderTop Double -BorderBottom Thin
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
FullName | true | true (ByValue, ByPropertyName) | |||
None | false | false | |||
Sheet | false | false |
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] <Object> [-RuleType] {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} [[-ConditionValue] <Object>] [[-ConditionValue2] <Object>] [-WorkSheet <ExcelWorksheet>] [-ForegroundColor <Object>] [-Reverse] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-NumberFormat <Object>] [-Bold] [-Italic] [-Underline] [-StrikeThru] [-StopIfTrue] [-Priority <Int32>] [-PassThru] [<CommonParameters>] Add-ConditionalFormatting [-Address] <Object> [-WorkSheet <ExcelWorksheet>] -DataBarColor <Object> [-Priority <Int32>] [-PassThru] [<CommonParameters>] Add-ConditionalFormatting [-Address] <Object> [-WorkSheet <ExcelWorksheet>] -ThreeIconsSet {Arrows | ArrowsGray | Flags | Signs | Symbols | Symbols2 | TrafficLights1 | TrafficLights2} [-Reverse] [-Priority <Int32>] [-PassThru] [<CommonParameters>] Add-ConditionalFormatting [-Address] <Object> [-WorkSheet <ExcelWorksheet>] -FourIconsSet {Arrows | ArrowsGray | Rating | RedToBlack | TrafficLights} [-Reverse] [-Priority <Int32>] [-PassThru] [<CommonParameters>] Add-ConditionalFormatting [-Address] <Object> [-WorkSheet <ExcelWorksheet>] -FiveIconsSet {Arrows | ArrowsGray | Quarters | Rating} [-Reverse] [-Priority <Int32>] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Range | A block of cells to format - you can use a named range with -Address $ws.names[1] or $ws.cells["RangeName"] | true | False | None | |
none | The worksheet where the format is to be applied | false | False | None | |
none | A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc. | true | False | None | |
ForegroundColour, FontColor | Text color for matching objects | false | False | None | |
DataBarColour | Color for databar type charts | true | False | None | |
none | One of the three-icon set types (e.g. Traffic Lights) | true | False | None | |
none | A four-icon set name | true | False | None | |
none | A five-icon set name | true | False | None | |
none | Use the Icon-Set in reverse order, or reverse the orders of Two- & Three-Color Scales | false | False | False | |
none | A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" ) | false | False | None | |
none | A second value for the conditions like "Between X and Y" | false | False | None | |
none | Background color for matching items | false | False | None | |
none | Background pattern for matching items | false | False | None | |
none | Secondary color when a background pattern requires it | false | False | None | |
none | Sets the numeric format for matching items | false | False | None | |
none | Put matching items in bold face | false | False | False | |
none | Put matching items in italic | false | False | False | |
none | Underline matching items | false | False | False | |
none | Strikethrough text of matching items | false | False | False | |
none | Prevent the processing of subsequent rules | false | False | False | |
none | Set the sequence for rule processing | false | False | 0 | |
none | If specified pass the rule back to the caller to allow additional customization. | false | False | False |
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()
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
PS\> Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red
PS\> Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue
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
PS\> Add-ConditionalFormatting $ws.Cells["B:B"] GreaterThan 10000000 -Fore Red -Stop -Pri 1
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 <ExcelWorksheet> [-Title <String>] [-ChartType {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}] [-ChartTrendLine {Exponential | Linear | Logarithmic | MovingAvgerage | Polynomial | Power}] [-XRange <Object>] [-YRange <Object>] [-Width <Int32>] [-Height <Int32>] [-Row <Int32>] [-RowOffSetPixels <Int32>] [-Column <Int32>] [-ColumnOffSetPixels <Int32>] [-LegendPosition {Top | Left | Right | Bottom | TopRight}] [-LegendSize <Object>] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-SeriesHeader <String[]>] [-TitleBold] [-TitleSize <Int32>] [-XAxisTitleText <String>] [-XAxisTitleBold] [-XAxisTitleSize <Object>] [-XAxisNumberformat <String>] [-XMajorUnit <Object>] [-XMinorUnit <Object>] [-XMaxValue <Object>] [-XMinValue <Object>] [-XAxisPosition {Left | Bottom | Right | Top}] [-YAxisTitleText <String>] [-YAxisTitleBold] [-YAxisTitleSize <Object>] [-YAxisNumberformat <String>] [-YMajorUnit <Object>] [-YMinorUnit <Object>] [-YMaxValue <Object>] [-YMinValue <Object>] [-YAxisPosition {Left | Bottom | Right | Top}] [-PassThru] [<CommonParameters>] Add-ExcelChart -PivotTable <ExcelPivotTable> [-Title <String>] [-ChartType {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}] [-ChartTrendLine {Exponential | Linear | Logarithmic | MovingAvgerage | Polynomial | Power}] [-XRange <Object>] [-YRange <Object>] [-Width <Int32>] [-Height <Int32>] [-Row <Int32>] [-RowOffSetPixels <Int32>] [-Column <Int32>] [-ColumnOffSetPixels <Int32>] [-LegendPosition {Top | Left | Right | Bottom | TopRight}] [-LegendSize <Object>] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-SeriesHeader <String[]>] [-TitleBold] [-TitleSize <Int32>] [-XAxisTitleText <String>] [-XAxisTitleBold] [-XAxisTitleSize <Object>] [-XAxisNumberformat <String>] [-XMajorUnit <Object>] [-XMinorUnit <Object>] [-XMaxValue <Object>] [-XMinValue <Object>] [-XAxisPosition {Left | Bottom | Right | Top}] [-YAxisTitleText <String>] [-YAxisTitleBold] [-YAxisTitleSize <Object>] [-YAxisNumberformat <String>] [-YMajorUnit <Object>] [-YMinorUnit <Object>] [-YMaxValue <Object>] [-YMinValue <Object>] [-YAxisPosition {Left | Bottom | Right | Top}] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | An existing Sheet where the chart will be created. | true | False | None | |
none | Instead of specify X and Y ranges, get data from a PivotTable by passing a PivotTable Object. | true | False | None | |
none | The title for the chart. | false | False | None | |
none | One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". | false | False | ColumnStacked | |
none | {{ Fill ChartTrendLine Description }} | false | False | None | |
none | The range of cells containing values for the X-Axis - usually labels. | false | False | None | |
none | The range(s) of cells holding values for the Y-Axis - usually "data". | false | False | None | |
none | Width of the chart in Pixels; defaults to 500. | false | False | 500 | |
none | Height of the chart in Pixels; defaults to 350. | false | False | 350 | |
none | Row position of the top left corner of the chart. ) places at the top of the sheet, 1 below row 1 and so on. | false | False | 0 | |
none | Offset to position the chart by a fraction of a row. | false | False | 10 | |
none | 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. | false | False | 6 | |
none | Offset to position the chart by a fraction of a column. | false | False | 5 | |
none | Location of the key, either left, right, top, bottom or TopRight. | false | False | None | |
none | Font size for the key. | false | False | None | |
none | Sets the key in bold type. | false | False | False | |
none | 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. | false | False | False | |
none | Attaches a category label, in charts which support this. | false | False | False | |
none | Attaches a percentage label, in charts which support this. | false | False | False | |
none | 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 . | false | False | None | |
none | Sets the title in bold face. | false | False | False | |
none | Sets the point size for the title. | false | False | 0 | |
none | Specifies a title for the X-axis. | false | False | None | |
none | Sets the X-axis title in bold face. | false | False | False | |
none | Sets the font size for the axis title. | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers along the X-axis. | false | False | None | |
none | Spacing for the major gridlines / tick marks along the X-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks along the X-axis. | false | False | None | |
none | Maximum value for the scale along the X-axis. | false | False | None | |
none | Minimum value for the scale along the X-axis. | false | False | None | |
none | Position for the X-axis (Top or Bottom). | false | False | None | |
none | Specifies a title for the Y-axis. | false | False | None | |
none | Sets the Y-axis title in bold face. | false | False | False | |
none | Sets the font size for the Y-axis title | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers on the Y-axis. | false | False | None | |
none | Spacing for the major gridlines / tick marks on the Y-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks on the Y-axis. | false | False | None | |
none | Maximum value on the Y-axis. | false | False | None | |
none | Minimum value on the Y-axis. | false | False | None | |
none | Position for the Y-axis (Left or Right). | false | False | None | |
none | 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. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
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
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
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
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
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] <Object>] [-WorkSheet <ExcelWorksheet>] [-ValidationType <Object>] [-Operator {between | notBetween | equal | notEqual | lessThan | lessThanOrEqual | greaterThan | greaterThanOrEqual}] [-Value <Object>] [-Value2 <Object>] [-Formula <Object>] [-Formula2 <Object>] [-ValueSet <Object>] [-ShowErrorMessage] [-ErrorStyle {undefined | stop | warning | information}] [-ErrorTitle <String>] [-ErrorBody <String>] [-ShowPromptMessage] [-PromptBody <String>] [-PromptTitle <String>] [-NoBlank <String>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Address | The range of cells to be validate, for example, "B2:C100" | false | True (ByValue) | None | |
none | The worksheet where the cells should be validated | false | False | None | |
none | 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 | false | False | None | |
none | The operator to apply to Decimal, Integer, TextLength, DateTime and time fields, for example "equal" or "between" | false | False | Equal | |
none | For Decimal, Integer, TextLength, DateTime the [first] data value | false | False | None | |
none | When using the between operator, the second data value | false | False | None | |
none | 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 | false | False | None | |
none | When using the between operator, the second data value as a formula | false | False | None | |
none | When using the list validation type, a set of values (rather than refering to Sheet!B$2:B$100 ) | false | False | None | |
none | Corresponds to the the 'Show Error alert ...' check box on error alert page in the Excel dialog | false | False | False | |
none | Stop, Warning, or Infomation, corresponding to to the style setting in the Excel dialog | false | False | None | |
none | The title for the message box corresponding to to the title setting in the Excel dialog | false | False | None | |
none | The error message corresponding to to the Error message setting in the Excel dialog | false | False | None | |
none | Corresponds to the the 'Show Input message ...' check box on input message page in the Excel dialog | false | False | False | |
none | The prompt message corresponding to to the Input message setting in the Excel dialog | false | False | None | |
none | The title for the message box corresponding to to the title setting in the Excel dialog | false | False | None | |
none | By default the 'Ignore blank' option will be selected, unless NoBlank is sepcified. | false | False | None |
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'
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'
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"
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] <ExcelRange> [[-RangeName] <String>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The range of cells to assign as a name. | true | False | None | |
none | 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. | false | False | None |
PS\> Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $rangeName
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] <ExcelRange> [[-TableName] <String>] [[-TableStyle] {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}] [[-TotalSettings] <Hashtable>] [-ShowHeader] [-ShowFilter] [-ShowTotal] [-ShowFirstColumn] [-ShowLastColumn] [-ShowRowStripes] [-ShowColumnStripes] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The range of cells to assign to a table. | true | False | None | |
none | The name for the Table - this should be unqiue in the Workbook - auto generated names will be used if this is left empty. | false | False | None | |
none | The Style for the table, by default "Medium6" is used | false | False | Medium6 | |
none | By default the header row is shown - it can be turned off with -ShowHeader:$false. | false | False | False | |
none | By default the filter is enabled - it can be turned off with -ShowFilter:$false. | false | False | False | |
none | 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 | false | False | False | |
none | A HashTable in the form ColumnName = "Average"|"Count"|"CountNums"|"Max"|"Min"|"None"|"StdDev"|"Sum"|"Var" - if specified, -ShowTotal is not needed. | false | False | None | |
none | Highlights the first column in bold. | false | False | False | |
none | Highlights the last column in bold. | false | False | False | |
none | By default the table formats show striped rows, the can be turned off with -ShowRowStripes:$false | false | False | False | |
none | Turns on column stripes. | false | False | False | |
none | If -PassThru is specified, the table object will be returned to allow additional changes to be made. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName
PS\> Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName Musictable -ShowFilter:$false -ShowTotal -ShowFirstColumn
Adds a PivotTable (and optional PivotChart) to a workbook.
If the PivotTable already exists, the source data will be updated.
Add-PivotTable -PivotTableName <String> [-Address <ExcelAddressBase>] [-ExcelPackage <Object>] [-SourceWorkSheet <Object>] [-SourceRange <Object>] [-PivotRows <Object>] [-PivotData <Object>] [-PivotColumns <Object>] [-PivotFilter <Object>] [-PivotDataToColumn] [-PivotTotals <String>] [-NoTotalsInPivot] [-GroupDateRow <String>] [-GroupDatePart {Years | Quarters | Months | Days | Hours | Minutes | Seconds}] [-GroupNumericRow <String>] [-GroupNumericMin <Double>] [-GroupNumericMax <Double>] [-GroupNumericInterval <Double>] [-PivotNumberFormat <String>] [-PivotTableStyle {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}] -PivotChartDefinition <Object> [-Activate] [-PassThru] [<CommonParameters>] Add-PivotTable -PivotTableName <String> [-Address <ExcelAddressBase>] [-ExcelPackage <Object>] [-SourceWorkSheet <Object>] [-SourceRange <Object>] [-PivotRows <Object>] [-PivotData <Object>] [-PivotColumns <Object>] [-PivotFilter <Object>] [-PivotDataToColumn] [-PivotTotals <String>] [-NoTotalsInPivot] [-GroupDateRow <String>] [-GroupDatePart {Years | Quarters | Months | Days | Hours | Minutes | Seconds}] [-GroupNumericRow <String>] [-GroupNumericMin <Double>] [-GroupNumericMax <Double>] [-GroupNumericInterval <Double>] [-PivotNumberFormat <String>] [-PivotTableStyle {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}] [-IncludePivotChart] [-ChartTitle <String>] [-ChartHeight <Int32>] [-ChartWidth <Int32>] [-ChartRow <Int32>] [-ChartColumn <Int32>] [-ChartRowOffSetPixels <Int32>] [-ChartColumnOffSetPixels <Int32>] [-ChartType {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}] [-NoLegend] [-ShowCategory] [-ShowPercent] [-Activate] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Name for the new PivotTable - this will be the name of a sheet in the Workbook. | true | False | None | |
none | 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.) | false | False | None | |
none | An Excel-package object for the workbook. | false | False | None | |
none | Worksheet where the data is found. | false | False | None | |
none | 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. | false | False | None | |
none | Fields to set as rows in the PivotTable. | false | False | None | |
none | A hash table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP. | false | False | None | |
none | Fields to set as columns in the PivotTable. | false | False | None | |
none | Fields to use to filter in the PivotTable. | false | False | None | |
none | If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. | false | False | False | |
none | Define whether totals should be added to rows, columns neither, or both (the default is both). | false | False | Both | |
none | Included for compatibility - equivalent to -PivotTotals "None". | false | False | False | |
none | The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) | false | False | None | |
none | The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) | false | False | None | |
none | The name of a row field which should be grouped by Number (e.g. 0-99, 100-199, 200-299 ) | false | False | None | |
none | The starting point for grouping | false | False | 0 | |
none | The endpoint for grouping | false | False | 1.79769313486232E+308 | |
none | The interval for grouping | false | False | 100 | |
none | Number format to apply to the data cells in the PivotTable. | false | False | None | |
none | Apply a table style to the PivotTable. | false | False | None | |
none | Use a chart definition instead of specifying chart settings one by one. | true | True (ByPropertyName) | None | |
none | If specified, a chart will be included. | false | False | False | |
none | Optional title for the pivot chart, by default the title omitted. | false | False | None | |
none | Height of the chart in Pixels (400 by default). | false | False | 400 | |
none | Width of the chart in Pixels (600 by default). | false | False | 600 | |
none | 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). | false | False | 0 | |
none | 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). | false | False | 4 | |
none | Vertical offset of the chart from the cell corner. | false | False | 0 | |
none | Horizontal offset of the chart from the cell corner. | false | False | 0 | |
none | Type of chart; defaults to "Pie". | false | False | Pie | |
none | If specified hides the chart legend. | false | False | False | |
none | 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. | false | False | False | |
none | If specified attaches percentages to slices in a pie chart. | false | False | False | |
none | If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. | false | False | False | |
none | Return the PivotTable so it can be customized. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
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
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
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
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] <ExcelPackage> [-WorksheetName <String>] [-ClearSheet] [-MoveToStart] [-MoveToEnd] [-MoveBefore <Object>] [-MoveAfter <Object>] [-Activate] [-CopySource <ExcelWorksheet>] [-NoClobber] [<CommonParameters>] Add-WorkSheet -ExcelWorkbook <ExcelWorkbook> [-WorksheetName <String>] [-ClearSheet] [-MoveToStart] [-MoveToEnd] [-MoveBefore <Object>] [-MoveAfter <Object>] [-Activate] [-CopySource <ExcelWorksheet>] [-NoClobber] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | An object representing an Excel Package. | true | True (ByValue) | None | |
none | An Excel Workbook to which the Worksheet will be added - a Package contains one Workbook, so you can use whichever fits at the time. | true | False | None | |
none | The name of the worksheet, 'Sheet1' by default. | false | False | None | |
none | If the worksheet already exists, by default it will returned, unless -ClearSheet is specified in which case it will be deleted and re-created. | false | False | False | |
none | 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. |
false | False | False | |
none | 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.) |
false | False | False | |
none | 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. |
false | False | None | |
none | 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. |
false | False | None | |
none | If there is already content in the workbook the new sheet will not be active UNLESS Activate is specified. | false | False | False | |
none | 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. | false | False | None | |
none | Ignored but retained for backwards compatibility. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> $WorksheetActors = $ExcelPackage | Add-WorkSheet -WorkSheetname Actors
PS\> $WorksheetActors = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname "Actors" -ClearSheet -MoveToStart
PS\> $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationName -CopySource $sourceWs -Activate
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | true (ByValue) | |||
None | false | false |
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] <ExcelPackage> [[-SaveAs] <Object>] [[-Password] <String>] [-Show] [-NoSave] [-Calculate] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Package to close. | true | True (ByValue) | None | |
none | Open the file in Excel. | false | False | False | |
none | Abandon the file without saving. | false | False | False | |
none | Save file with a new name (ignored if -NoSave Specified). | false | False | None | |
none | Password to protect the file. | false | False | None | |
none | Attempt to recalculation the workbook before saving | false | False | False |
Close-ExcelPackage -show $excel
Close-ExcelPackage -NoSave $excel
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | true (ByValue) | |||
None | false | false |
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] <Object> [-Differencefile] <Object> [-WorkSheetName <Object>] [-Property <Object>] [-ExcludeProperty <Object>] -Headername <String[]> [-Startrow <Int32>] [-AllDataBackgroundColor <Object>] [-BackgroundColor <Object>] [-TabColor <Object>] [-Key <Object>] [-FontColor <Object>] [-Show] [-GridView] [-PassThru] [-IncludeEqual] [-ExcludeDifferent] [<CommonParameters>] Compare-WorkSheet [-Referencefile] <Object> [-Differencefile] <Object> [-WorkSheetName <Object>] [-Property <Object>] [-ExcludeProperty <Object>] -NoHeader [-Startrow <Int32>] [-AllDataBackgroundColor <Object>] [-BackgroundColor <Object>] [-TabColor <Object>] [-Key <Object>] [-FontColor <Object>] [-Show] [-GridView] [-PassThru] [-IncludeEqual] [-ExcludeDifferent] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | First file to compare. | true | False | None | |
none | Second file to compare. | true | False | None | |
none | Name(s) of worksheets to compare. | false | False | Sheet1 | |
none | Properties to include in the comparison - supports wildcards, default is "*". | false | False | * | |
none | Properties to exclude from the comparison - supports wildcards. | false | False | None | |
none | Specifies custom property names to use, instead of the values defined in the starting row of the sheet. | true | False | None | |
none | Automatically generate property names (P1, P2, P3 ...) instead of the using the values the starting row of the sheet. | true | False | False | |
none | The row from where we start to import data: all rows above the start row are disregarded. By default, this is the first row. | false | False | 1 | |
none | If specified, highlights all the cells - so you can make Equal cells one color, and Different cells another. | false | False | None | |
none | If specified, highlights the rows with differences. | false | False | None | |
none | If specified identifies the tabs which contain difference rows (ignored if -BackgroundColor is omitted). | false | False | None | |
none | Name of a column which is unique and will be used to add a row to the DIFF object, defaults to "Name". | false | False | Name | |
none | If specified, highlights the DIFF columns in rows which have the same key. | false | False | None | |
none | If specified, opens the Excel workbooks instead of outputting the diff to the console (unless -PassThru is also specified). | false | False | False | |
none | 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. | false | False | False | |
none | If specified a full set of DIFF data is returned without filtering to the specified properties. | false | False | False | |
none | If specified the result will include equal rows as well. By default only different rows are returned. | false | False | False | |
none | If specified, the result includes only the rows where both are equal. | false | False | False |
PS\> Compare-WorkSheet -Referencefile 'Server56.xlsx' -Differencefile 'Server57.xlsx' -WorkSheetName Products -key IdentifyingNumber -ExcludeProperty Install* | Format-Table
PS\> Compare-WorkSheet "Server54.xlsx" "Server55.xlsx" -WorkSheetName Services -GridView
PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen
PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName Services -BackgroundColor lightGreen -FontColor Red -Show
PS\> Compare-WorkSheet 'Pester-tests.xlsx' 'Pester-tests.xlsx' -WorkSheetName 'Server1','Server2' -Property "full Description","Executed","Result" -Key "full Description"
PS\> Compare-WorkSheet 'Server54.xlsx' 'Server55.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -GridView -ExcludeDifferent
PS\>Compare-WorkSheet 'Server1.xlsx' 'Server2.xlsx' -WorkSheetName general -Startrow 2 -Headername Label,value -Key Label -BackgroundColor White -Show -AllDataBackgroundColor LightGray
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] <Object> [[-WorkSheetname] <Object>] [-Range] <Object> [[-Destination] <Object>] [-Show] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Path to the Excel file | true | False | None | |
none | Worksheet name - if none is specified "Sheet1" will be assumed | false | False | Sheet1 | |
none | Range of cells within the sheet, e.g "A1:Z99" | true | False | None | |
none | A bmp, png or jpg file where the result will be saved | false | False | "$pwd\temp.png" | |
none | If specified opens the image in the default viewer. | false | False | False |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
FullName | true | true (ByValue, ByPropertyName) | |||
None | false | false | |||
Sheet | false | false |
Exports Sheets from Excel Workbooks to CSV files.
This command provides a convenient way to run Import-Excel @ImportParameters | Select-Object @selectParameters | export-Csv @ ExportParameters It can take the parameters -AsText , as used in Import-Excel, )Properties & -ExcludeProperties as used in Select-Object and -Append, -Delimiter and -Encoding as used in Export-CSV
ConvertFrom-ExcelSheet [-Path] <String> [[-OutputPath] <String>] [[-SheetName] <String>] [[-Encoding] <Encoding>] [[-Extension] {.txt | .log | .csv}] [[-Delimiter] {; | | }] [[-Property] <Object>] [[-ExcludeProperty] <Object>] [[-AsText] <String[]>] [[-AsDate] <String[]>] [-Append] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Use this parameter to have the export add output to the end of the file. Without this parameter, the command replaces the file contents without warning. | false | False | False | |
none | AsText allows selected columns to be returned as the text displayed in their cells, instead of their value. (* is supported as a wildcard.) | false | False | None | |
none | Not all date formats are recognized as indicating the number in the cell represents a date AsDate forces the number which would be returned to be converted to a date. (* is supported as a wildcard.) | false | False | None | |
none | Selects , or ; as the delimeter for the exported data - if not specified , is used by default. | false | False | None | |
none | Sets the text encoding for the output data file; UTF8 bu default | false | False | None | |
none | Specifies the properties that to exclude from the export. Wildcards are permitted. This parameter is effective only when the command also includes the Property parameter. | false | False | None | |
none | Sets the file extension for the exported data, defaults to CSV | false | False | None | |
none | The directory where the output file(s) will be created. The file name(s) will match the name of the workbook page which contained the data. | false | False | None | |
none | The path to the .XLSX file which will be exported. | true | False | None | |
none | Specifies the properties to select. Wildcards are permitted - the default is "*". The value of the Property parameter can be a new calculated property, and follows the same pattern as Select-Item | false | False | None | |
none | The name of a sheet to export, or a regular expression which is used to identify sheets | false | False | None |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText GridPosition,date
PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText "GridPosition" -Property driver, @{n="date"; e={[datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#")}} , FinishPosition, GridPosition
Generate SQL insert statements from Excel spreadsheet.
Generate SQL insert statements from Excel spreadsheet.
ConvertFrom-ExcelToSQLInsert [-TableName] <Object> [-Path] <Object> [[-WorkSheetname] <Object>] [[-StartRow] <Int32>] [[-Header] <String[]>] [-NoHeader] [-DataOnly] [-ConvertEmptyStringsToNull] [-UseMSSQLSyntax] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Name of the target database table. | true | False | None | |
FullName | Path to an existing .XLSX file This parameter is passed to Import-Excel as is. | true | True (ByPropertyName, ByValue) | None | |
Sheet | 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. | false | False | 1 | |
HeaderRow, TopRow | 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. | false | False | 0 | |
none | 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. | false | False | None | |
none | 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. | false | False | False | |
none | Import only rows and columns that contain data, empty rows and empty columns are not imported. | false | False | False | |
none | 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. | false | False | False | |
none | {{ Fill UseMSSQLSyntax Description }} | false | False | False |
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);
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | true | true (ByValue) |
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] <Object> [[-SourceWorkSheet] <Object>] [-DestinationWorkbook] <Object> [[-DestinationWorksheet] <Object>] [-Show] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
SourceWorkbook | An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found. | true | True (ByValue) | None | |
none | Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1). | false | False | 1 | |
none | An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied. | true | False | None | |
none | 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. | false | False | None | |
none | if the destination is an excel package or a path, launch excel and open the file on completion. | false | False | False |
Copy-ExcelWorkSheet -SourceWorkbook Test1.xlsx -DestinationWorkbook Test2.xlsx
Copy-ExcelWorkSheet -SourceWorkbook Server1.xlsx -sourceWorksheet "Settings" -DestinationWorkbook Settings.xlsx -DestinationWorksheet "Server1"
$excel = Open-ExcelPackage .\test.xlsx
$excel = Open-ExcelPackage .\test.xlsx
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false |
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] <Object>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The format string to Expand | false | False | None |
The output type is the type of the objects that the cmdlet emits.
Expand-NumberFormat percentage
Expand-NumberFormat Currency
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] <String>] [-InputObject <Object>] [-Calculate] [-Show] [-WorksheetName <String>] [-Password <String>] [-ClearSheet] [-Append] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBold] [-TitleSize <Int32>] [-TitleBackgroundColor <Object>] [-IncludePivotTable] [-PivotTableName <String>] [-PivotRows <String[]>] [-PivotColumns <String[]>] [-PivotData <Object>] [-PivotFilter <String[]>] [-PivotDataToColumn] [-PivotTableDefinition <Hashtable>] [-IncludePivotChart] [-ChartType {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}] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows <Object>] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName <String>] [-TableName <Object>] [-TableStyle {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}] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition <Object[]>] [-HideSheet <String[]>] [-UnHideSheet <String[]>] [-MoveToStart] [-MoveToEnd] [-MoveBefore <Object>] [-MoveAfter <Object>] [-KillExcel] [-AutoNameRange] [-StartRow <Int32>] [-StartColumn <Int32>] [-PassThru] [-Numberformat <String>] [-ExcludeProperty <String[]>] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion <String[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-Style <Object[]>] [-CellStyleSB <ScriptBlock>] [-Activate] [-Now] [-ReturnRange] [-PivotTotals <String>] [-NoTotalsInPivot] [-ReZip] [<CommonParameters>] Export-Excel -ExcelPackage <ExcelPackage> [-InputObject <Object>] [-Calculate] [-Show] [-WorksheetName <String>] [-Password <String>] [-ClearSheet] [-Append] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBold] [-TitleSize <Int32>] [-TitleBackgroundColor <Object>] [-IncludePivotTable] [-PivotTableName <String>] [-PivotRows <String[]>] [-PivotColumns <String[]>] [-PivotData <Object>] [-PivotFilter <String[]>] [-PivotDataToColumn] [-PivotTableDefinition <Hashtable>] [-IncludePivotChart] [-ChartType {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}] [-NoLegend] [-ShowCategory] [-ShowPercent] [-AutoSize] [-MaxAutoSizeRows <Object>] [-NoClobber] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-AutoFilter] [-BoldTopRow] [-NoHeader] [-RangeName <String>] [-TableName <Object>] [-TableStyle {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}] [-Barchart] [-PieChart] [-LineChart] [-ColumnChart] [-ExcelChartDefinition <Object[]>] [-HideSheet <String[]>] [-UnHideSheet <String[]>] [-MoveToStart] [-MoveToEnd] [-MoveBefore <Object>] [-MoveAfter <Object>] [-KillExcel] [-AutoNameRange] [-StartRow <Int32>] [-StartColumn <Int32>] [-PassThru] [-Numberformat <String>] [-ExcludeProperty <String[]>] [-NoAliasOrScriptPropeties] [-DisplayPropertySet] [-NoNumberConversion <String[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-Style <Object[]>] [-CellStyleSB <ScriptBlock>] [-Activate] [-ReturnRange] [-PivotTotals <String>] [-NoTotalsInPivot] [-ReZip] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Path to a new or existing .XLSX file. | false | False | None | |
none | 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. | true | False | None | |
TargetData | Date is usually piped into Export-Excel, but it also accepts data through the InputObject parameter | false | True (ByValue) | None | |
none | If specified, a recalculation of the worksheet will be requested before saving. | false | False | False | |
none | Opens the Excel file immediately after creation; convenient for viewing the results instantly without having to search for the file first. | false | False | False | |
none | The name of a sheet within the workbook - "Sheet1" by default. | false | False | Sheet1 | |
PW | Sets password protection on the workbook. | false | False | None | |
none | 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). |
false | False | False | |
none | If specified data will be added to the end of an existing sheet, using the same column headings. | false | False | False | |
none | Text of a title to be placed in the top left cell. | false | False | None | |
none | Sets the fill pattern for the title cell. | false | False | Solid | |
none | Sets the title in boldface type. | false | False | False | |
none | Sets the point size for the title. | false | False | 22 | |
none | Sets the cell background color for the title cell. | false | False | None | |
none | Adds a PivotTable using the data in the worksheet. | false | False | False | |
none | If a PivotTable is created from command line parameters, specifies the name of the new sheet holding the pivot. Defaults to "WorksheetName-PivotTable". | false | False | None | |
none | Name(s) of column(s) from the spreadsheet which will provide the Row name(s) in a PivotTable created from command line parameters. | false | False | None | |
none | Name(s) of columns from the spreadsheet which will provide the Column name(s) in a PivotTable created from command line parameters. | false | False | None | |
none | 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. |
false | False | None | |
none | Name(s) columns from the spreadsheet which will provide the Filter name(s) in a PivotTable created from command line parameters. | false | False | None | |
none | 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. | false | False | False | |
none | 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. |
false | False | None | |
none | Include a chart with the PivotTable - implies -IncludePivotTable. | false | False | False | |
none | The type for PivotChart (one of Excel's defined chart types). | false | False | Pie | |
none | Exclude the legend from the PivotChart. | false | False | False | |
none | Add category labels to the PivotChart. | false | False | False | |
none | Add percentage labels to the PivotChart. | false | False | False | |
none | Sizes the width of the Excel column to the maximum width needed to display all the containing data in that cell. | false | False | False | |
none | 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 | false | False | 1000 | |
none | Not used. Left in to avoid problems with older scripts, it may be removed in future versions. | false | False | False | |
none | Freezes headers etc. in the top row. | false | False | False | |
none | Freezes titles etc. in the left column. | false | False | False | |
none | Freezes top row and left column (equivalent to Freeze pane 2,2 ). | false | False | False | |
none | Freezes panes at specified coordinates (in the form RowNumber, ColumnNumber). | false | False | None | |
none | Enables the Excel filter on the complete header row, so users can easily sort, filter and/or search the data in the selected column. | false | False | False | |
none | Makes the top row boldface. | false | False | False | |
none | Specifies that field names should not be put at the top of columns. | false | False | False | |
none | Makes the data in the worksheet a named range. | false | False | None | |
Table | 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. | false | False | None | |
none | Selects the style for the named table - if the Tablename parameter is specified without giving a style, 'Medium6' is used as a default. | false | False | Medium6 | |
none | Creates a "quick" bar chart using the first text column as labels and the first numeric column as values. | false | False | False | |
none | Creates a "quick" pie chart using the first text column as labels and the first numeric column as values. | false | False | False | |
none | Creates a "quick" line chart using the first text column as labels and the first numeric column as values. | false | False | False | |
none | Creates a "quick" column chart using the first text column as labels and the first numeric column as values. | false | False | False | |
none | 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. | false | False | None | |
none | 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. | false | False | None | |
none | Name(s) of Sheet(s) to reveal in the workbook, supports wildcards. | false | False | None | |
none | 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. |
false | False | False | |
none | 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.) | false | False | False | |
none | 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. |
false | False | None | |
none | 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. |
false | False | None | |
none | Closes Excel without stopping to ask if work should be saved - prevents errors writing to the file because Excel has it open. | false | False | False | |
none | Makes each column a named range. | false | False | False | |
none | 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. | false | False | 1 | |
none | Column to start adding data - 1 by default. | false | False | 1 | |
PT | 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. | false | False | False | |
none | 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 |
false | False | General | |
none | Specifies properties which may exist in the target data but should not be placed on the worksheet. | false | False | None | |
none | 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 | false | False | False | |
none | 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. | false | False | False | |
none | 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 |
false | False | None | |
none | One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. | false | False | None | |
none | Applies a Conditional formatting rule defined with New-ConditionalText. When specific conditions are met the format is applied. | false | False | None | |
none | 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. | false | False | None | |
none | 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. | false | False | None | |
none | 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. | false | False | False | |
none | The -Now switch is a shortcut that automatically creates a temporary file, enables "AutoSize", "TableName" and "Show", and opens the file immediately. | false | False | False | |
none | If specified, Export-Excel returns the range of added cells in the format "A1:Z100". | false | False | False | |
none | 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. | false | False | Both | |
none | In a PivotTable created from command line parameters, prevents the addition of totals to rows and columns. | false | False | False | |
none | If specified, Export-Excel will expand the contents of the .XLSX file (which is multiple files in a zip archive) and rebuild it. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Get-Process | Export-Excel .\Test.xlsx -show
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'
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
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 *
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 )
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 )
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
PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -IncludePivotTable -Show -PivotRows Company -PivotData PMEXAMPLE 9
PS\> Get-Process | Export-Excel .\test.xlsx -WorksheetName Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PMEXAMPLE 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
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
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
PS\> 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | Export-Excel -now -LineChart -AutoNameRange
PS\> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | true (ByValue) |
Gets summary information on an Excel file like number of rows, columns, and more
Get-ExcelFileSummary [-Path] <Object> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
FullName | true | true (ByPropertyName) |
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] <Object> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
FullName | Specifies the path to the Excel file. (This parameter is required.) | true | True (ByPropertyName, ByValue) | None |
Get-ExcelSheetInfo .\Test.xlsx
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] <String> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
FullName | Specifies the path to the Excel file. This parameter is required. | true | True (ByPropertyName, ByValue) | None |
Get-ExcelWorkbookInfo .\Test.xlsx
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | true | false | |||
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
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] <String> [[-WorksheetName] <String>] -NoHeader [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>] Import-Excel [-Path] <String> [[-WorksheetName] <String>] -HeaderName <String[]> [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>] Import-Excel [-Path] <String> [[-WorksheetName] <String>] [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>] Import-Excel [[-WorksheetName] <String>] -ExcelPackage <ExcelPackage> -NoHeader [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>] Import-Excel [[-WorksheetName] <String>] -ExcelPackage <ExcelPackage> -HeaderName <String[]> [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>] Import-Excel [[-WorksheetName] <String>] -ExcelPackage <ExcelPackage> [-StartRow <Int32>] [-EndRow <Int32>] [-StartColumn <Int32>] [-EndColumn <Int32>] [-DataOnly] [-AsText <String[]>] [-AsDate <String[]>] [-Password <String>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
FullName | Specifies the path to the Excel file. | true | True (ByPropertyName, ByValue) | None | |
none | 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. |
true | False | None | |
Sheet | 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. | false | False | None | |
none | 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. |
true | False | None | |
none | 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. |
true | False | False | |
HeaderRow, TopRow | 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. |
false | False | 1 | |
StopRow, BottomRow | By default all rows up to the last cell in the sheet will be imported. If specified, import stops at this row. | false | False | 0 | |
LeftColumn | The number of the first column to read data from (1 by default). | false | False | 1 | |
RightColumn | By default the import reads up to the last populated column, -EndColumn tells the import to stop at an earlier number. | false | False | 0 | |
none | Import only rows and columns that contain data, empty rows and empty columns are not imported. | false | False | False | |
none | 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.) | false | False | None | |
none | Not all date formats are recognized as indicating the number in the cell represents a date AsDate forces the number which would be returned to be converted to a date. (* is supported as a wildcard.) | false | False | None | |
none | Accepts a string that will be used to open a password protected Excel file. | false | False | None |
---------------------------------------------- | 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
---------------------------------------------- | 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
---------------------------------------------------------- | 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 :
---------------------------------------------------------- | 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
---------------------------------------------------------- | 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
PS\> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false |
Helper method for executing Read-OleDbData with some basic defaults. For additional help, see documentation for Read-OleDbData cmdlet.
Uses Read-OleDbData to execute a sql statement against a xlsx file. For finer grained control over the interaction, you may use that cmdlet. This cmdlet assumes a file path will be passed in and the connection string will be built with no headers and treating all results as text.
Running this command is equivalent to running the following:
$FullName = (Get-ChildItem $Path).FullName
Read-OleDbData `
-ConnectionString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$FullName;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" `
-SqlStatement $Query
Note that this command uses the MICROSOFT.ACE.OLEDB provider and will not work without it.
If needed, please download the appropriate package from https://www.microsoft.com/en-us/download/details.aspx?id=54920.
Invoke-ExcelQuery [-Path] <String> [-Query] <String> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The path to the file to open. | true | false | |||
var name consistent with Import-Excel var name consistent with Invoke-Sqlcmd |
true | false |
Invoke-ExcelQuery .\test.xlsx 'select ROUND(F1) as [A1] from [sheet3$A1:A1]'EXAMPLE 2
$Path = (Get-ChildItem 'test.xlsx').FullName $Query = "select ROUND(F1) as [A] from [sheet1$A1:A1]" Read-XlsxUsingOleDb -Path $Path -Query $QueryEXAMPLE 3
$ReadDataArgs = @{ Path = .\test.xlsx Query = Get-Content query.sql -Raw } $Results = Invoke-ExcelQuery @ReadDataArgs
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false |
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] <String>] [-WorkSheetName <Object>] [-Clearsheet] [-NoHeader] [-FromLabel <String>] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-AutoFilter] [-BoldTopRow] [-HideSource] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBackgroundColor <Object>] [-TitleBold] [-TitleSize <Int32>] [-PivotTableDefinition <Hashtable>] [-ExcelChartDefinition <Object[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-AutoNameRange] [-RangeName <String>] [-ReturnRange] [-Show] [-PassThru] [<CommonParameters>] Join-Worksheet [[-Path] <String>] [-WorkSheetName <Object>] [-Clearsheet] [-NoHeader] [-FromLabel <String>] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-BoldTopRow] [-HideSource] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBackgroundColor <Object>] [-TitleBold] [-TitleSize <Int32>] [-PivotTableDefinition <Hashtable>] [-ExcelChartDefinition <Object[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-AutoNameRange] [-RangeName <String>] -TableName <String> [-TableStyle {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}] [-ReturnRange] [-Show] [-PassThru] [<CommonParameters>] Join-Worksheet -ExcelPackage <ExcelPackage> [-WorkSheetName <Object>] [-Clearsheet] [-NoHeader] [-FromLabel <String>] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-BoldTopRow] [-HideSource] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBackgroundColor <Object>] [-TitleBold] [-TitleSize <Int32>] [-PivotTableDefinition <Hashtable>] [-ExcelChartDefinition <Object[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-AutoNameRange] [-RangeName <String>] -TableName <String> [-TableStyle {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}] [-ReturnRange] [-Show] [-PassThru] [<CommonParameters>] Join-Worksheet -ExcelPackage <ExcelPackage> [-WorkSheetName <Object>] [-Clearsheet] [-NoHeader] [-FromLabel <String>] [-LabelBlocks] [-AutoSize] [-FreezeTopRow] [-FreezeFirstColumn] [-FreezeTopRowFirstColumn] [-FreezePane <Int32[]>] [-AutoFilter] [-BoldTopRow] [-HideSource] [-Title <String>] [-TitleFillPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-TitleBackgroundColor <Object>] [-TitleBold] [-TitleSize <Int32>] [-PivotTableDefinition <Hashtable>] [-ExcelChartDefinition <Object[]>] [-ConditionalFormat <Object[]>] [-ConditionalText <Object[]>] [-AutoNameRange] [-RangeName <String>] [-ReturnRange] [-Show] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Path to a new or existing .XLSX file. | false | False | None | |
none | An object representing an Excel Package - either from Open-ExcelPackage or specifying -PassThru to Export-Excel. | true | False | None | |
none | The name of a sheet within the workbook where the other sheets will be joined together - "Combined" by default. | false | False | Combined | |
none | If specified ,any pre-existing target for the joined data will be deleted and re-created; otherwise data will be appended on this sheet. | false | False | False | |
none | Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. | false | False | False | |
none | 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. | false | False | From | |
none | If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. | false | False | False | |
none | Sets the width of the Excel columns to display all the data in their cells. | false | False | False | |
none | Freezes headers etc. in the top row. | false | False | False | |
none | Freezes titles etc. in the left column. | false | False | False | |
none | Freezes top row and left column (equivalent to Freeze pane 2,2 ). | false | False | False | |
none | Freezes panes at specified coordinates (in the formRowNumber , ColumnNumber). | false | False | None | |
none | Enables the Excel filter on the headers of the combined sheet. | false | False | False | |
none | Makes the top row boldface. | false | False | False | |
none | If specified, hides the sheets that the data is copied from. | false | False | False | |
none | Text of a title to be placed in Cell A1. | false | False | None | |
none | Sets the fill pattern for the title cell. | false | False | Solid | |
none | Sets the cell background color for the title cell. | false | False | None | |
none | Sets the title in boldface type. | false | False | False | |
none | Sets the point size for the title. | false | False | 22 | |
none | Hashtable(s) with Sheet PivotRows, PivotColumns, PivotData, IncludePivotChart and ChartType values to specify a definition for one or morePivotTable(s). | false | False | None | |
none | A hashtable containing ChartType, Title, NoLegend, ShowCategory, ShowPercent, Yrange, Xrange and SeriesHeader for one or more [non-pivot] charts. | false | False | None | |
none | One or more conditional formatting rules defined with New-ConditionalFormattingIconSet. | false | False | None | |
none | Applies a Conditional formatting rule defined with New-ConditionalText. | false | False | None | |
none | Makes each column a named range. | false | False | False | |
none | Makes the data in the worksheet a named range. | false | False | None | |
none | Makes the data in the worksheet a table with a name and applies a style to it. Name must not contain spaces. | true | False | None | |
none | Selects the style for the named table - defaults to "Medium6". | false | False | Medium6 | |
none | If specified, returns the range of cells in the combined sheet, in the format "A1:Z100". | false | False | False | |
none | Opens the Excel file immediately after creation. Convenient for viewing the results instantly without having to search for the file first. | false | False | False | |
none | If specified, an object representing the unsaved Excel package will be returned, it then needs to be saved. | false | False | False |
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
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
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | true (ByValue) | |||
None | false | false |
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] <Object> [[-KeyFontColor] <Object>] [[-ChangeBackgroundColor] <Object>] [[-DeleteBackgroundColor] <Object>] [[-AddBackgroundColor] <Object>] [[-Startrow] <Int32>] [[-Headername] <String[]>] [[-WorksheetName] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [[-Property] <Object>] [[-ExcludeProperty] <Object>] [[-Key] <Object>] [-NoHeader] [-HideRowNumbers] [-Passthru] [-Show] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | Paths to the files to be merged. Files are also accepted | true | True (ByValue) | None | |
none | The row from where we start to import data, all rows above the Start row are disregarded. By default this is the first row. | false | False | 1 | |
none | Specifies custom property names to use, instead of the values defined in the column headers of the Start row. | false | False | None | |
none | If specified, property names will be automatically generated (P1, P2, P3, ..) instead of using the values from the start row. | false | False | False | |
none | Name(s) of Worksheets to compare. | false | False | Sheet1 | |
OutFile | File to write output to. | false | False | .\temp.xlsx | |
OutSheet | Name of Worksheet to output - if none specified will use the reference Worksheet name. | false | False | Sheet1 | |
none | Properties to include in the comparison - supports wildcards, default is "*". | false | False | * | |
none | Properties to exclude from the the comparison - supports wildcards. | false | False | None | |
none | Name of a column which is unique used to pair up rows from the reference and difference sides, default is "Name". | false | False | Name | |
none | Sets the font color for the Key field; this means you can filter by color to get only changed rows. | false | False | [System.Drawing.Color]::Red | |
none | Sets the background color for changed rows. | false | False | [System.Drawing.Color]::Orange | |
none | Sets the background color for rows in the reference but deleted from the difference sheet. | false | False | [System.Drawing.Color]::LightPink | |
none | Sets the background color for rows not in the reference but added to the difference sheet. | false | False | [System.Drawing.Color]::Orange | |
none | If specified, hides the columns in the spreadsheet that contain the row numbers. | false | False | False | |
none | If specified, outputs the data to the pipeline (you can add -whatif so it the command only outputs to the pipeline). | false | False | False | |
none | If specified, opens the output workbook. | false | False | False |
PS\> dir Server*.xlsx | Merge-MulipleSheets -WorksheetName Services -OutputFile Test2.xlsx -OutputSheetName Services -Show
PS\> dir Serv*.xlsx | Merge-MulipleSheets -WorksheetName Software -Key "*" -ExcludeProperty Install* -OutputFile Test2.xlsx -OutputSheetName Software -Show
Merge-MulipleSheets -Path hotfixes.xlsx -WorksheetName Serv* -Key hotfixid -OutputFile test2.xlsx -OutputSheetName hotfixes -HideRowNumbers -Show
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] <Object> [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] -NoHeader [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-Referencefile] <Object> [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] -Headername <String[]> [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-Referencefile] <Object> [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-DiffPrefix] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] -NoHeader -ReferenceObject <Object> [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-DiffPrefix] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] -Headername <String[]> -ReferenceObject <Object> [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-Differencefile] <Object> [[-WorksheetName] <Object>] [[-DiffPrefix] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] [-Startrow <Int32>] -ReferenceObject <Object> [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>] Merge-Worksheet [-DifferenceObject] <Object> [[-DiffPrefix] <Object>] [[-OutputFile] <Object>] [[-OutputSheetName] <Object>] -ReferenceObject <Object> [-Property <Object>] [-ExcludeProperty <Object>] [-Key <Object>] [-KeyFontColor <Object>] [-ChangeBackgroundColor <Object>] [-DeleteBackgroundColor <Object>] [-AddBackgroundColor <Object>] [-HideEqual] [-Passthru] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | 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 |
true | False | None | |
none | 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 |
true | False | None | |
none | Name(s) of Worksheets to compare. Applies to all parameter sets EXCEPT D which is two objects (no sheets) | false | False | Sheet1 | |
none | 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 ) | false | False | 1 | |
none | 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 |
true | False | None | |
none | 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 |
true | False | False | |
RefObject | Reference object to compare if a Worksheet is NOT being used. Reference object can combine with a difference sheet or difference object | true | False | None | |
DiffObject | Difference object to compare if a Worksheet is NOT being used for either half. Can't have a reference sheet and difference object. | true | False | None | |
none | If there isn't a filename to use to label data from the "Difference" side, DiffPrefix is used, it defaults to "=>" | false | False | => | |
OutFile | File to hold merged data. | false | False | None | |
OutSheet | Name of Worksheet to output - if none specified will use the reference Worksheet name. | false | False | Sheet1 | |
none | Properties to include in the DIFF - supports wildcards, default is "*". | false | False | * | |
none | Properties to exclude from the the search - supports wildcards. | false | False | None | |
none | Name of a column which is unique used to pair up rows from the refence and difference side, default is "Name". | false | False | Name | |
none | Sets the font color for the "key" field; this means you can filter by color to get only changed rows. | false | False | [System.Drawing.Color]::DarkRed | |
none | Sets the background color for changed rows. | false | False | [System.Drawing.Color]::Orange | |
none | Sets the background color for rows in the reference but deleted from the difference sheet. | false | False | [System.Drawing.Color]::LightPink | |
none | Sets the background color for rows not in the reference but added to the difference sheet. | false | False | [System.Drawing.Color]::PaleGreen | |
none | if specified, hides the rows in the spreadsheet that are equal and only shows changes, added or deleted rows. | false | False | False | |
none | If specified, outputs the data to the pipeline (you can add -WhatIf so the command only outputs to the pipeline). | false | False | False | |
none | If specified, opens the output workbook. | false | False | False | |
wi | Shows what would happen if the cmdlet runs. The cmdlet is not run. | false | False | False | |
cf | Prompts you for confirmation before running the cmdlet. | false | False | False |
PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -show
PS\> Merge-Worksheet "Server54.xlsx" "Server55.xlsx" -WorksheetName services -OutputFile Services.xlsx -OutputSheetName 54-55 -HideEqual -AddBackgroundColor LightBlue -show
PS\> Merge-Worksheet -OutputFile .\j1.xlsx -OutputSheetName test11 -ReferenceObject (dir .\ImportExcel\4.0.7) -DifferenceObject (dir .\ImportExcel\4.0.8) -Property Length -Show
PS\> Merge-Worksheet -RefO (dir .\ImportExcel\4.0.7) -DiffO (dir .\ImportExcel\4.0.8) -Pr Length | Out-GridView
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] <Object> [[-ConditionalFormat] <Object>] [-Reverse] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The range of cells that the conditional format applies to. | true | False | None | |
none | The type of rule: one of "ThreeIconSet","FourIconSet" or "FiveIconSet" | false | False | None | |
none | Use the icons in the reverse order. | false | False | False |
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
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] <Object>] [[-ConditionalTextColor] <Object>] [[-BackgroundColor] <Object>] [[-Range] <String>] [[-PatternType] {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [[-ConditionalType] <Object>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
ConditionValue | The text (or other value) to use in the rule. Note that Equals, GreaterThan/LessThan rules require text to wrapped in double quotes. | false | False | None | |
ForeGroundColor | The font color for the cell - by default: "DarkRed". | false | False | [System.Drawing.Color]::DarkRed | |
none | The fill color for the cell - by default: "LightPink". | false | False | [System.Drawing.Color]::LightPink | |
none | 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. | false | False | None | |
none | The background pattern for the cell - by default: "Solid" | false | False | Solid | |
RuleType | One of the supported rules; by default "ContainsText" is selected. | false | False | ContainsText |
PS\> $ct = New-ConditionalText -Text 'Ferrari' PS\> Export-Excel -ExcelPackage $excel -ConditionalTest $ct -show
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
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] <Object>] [[-RowOffSetPixels] <Object>] [[-Column] <Object>] [[-ColumnOffSetPixels] <Object>] [[-LegendPosition] {Top | Left | Right | Bottom | TopRight}] [[-LegendSize] <Object>] [[-SeriesHeader] <Object>] [[-TitleSize] <Int32>] [[-XAxisTitleText] <String>] [[-XAxisTitleSize] <Object>] [[-XAxisNumberformat] <String>] [[-Header] <Object>] [[-XMajorUnit] <Object>] [[-XMinorUnit] <Object>] [[-XMaxValue] <Object>] [[-XMinValue] <Object>] [[-XAxisPosition] {Left | Bottom | Right | Top}] [[-YAxisTitleText] <String>] [[-YAxisTitleSize] <Object>] [[-YAxisNumberformat] <String>] [[-YMajorUnit] <Object>] [[-YMinorUnit] <Object>] [[-ChartType] {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}] [[-YMaxValue] <Object>] [[-YMinValue] <Object>] [[-YAxisPosition] {Left | Bottom | Right | Top}] [[-ChartTrendLine] {Exponential | Linear | Logarithmic | MovingAvgerage | Polynomial | Power}] [[-XRange] <Object>] [[-YRange] <Object>] [[-Width] <Object>] [[-Height] <Object>] [[-Row] <Object>] [-LegendBold] [-NoLegend] [-ShowCategory] [-ShowPercent] [-TitleBold] [-XAxisTitleBold] [-YAxisTitleBold] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The title for the chart. | false | False | Chart Title | |
none | No longer used. This may be removed in future versions. | false | False | None | |
none | One of the built-in chart types, such as Pie, ClusteredColumn, Line etc. Defaults to "ColumnStacked". | false | False | ColumnStacked | |
none | Superimposes one of Excel's trenline types on the chart. | false | False | None | |
none | The range of cells containing values for the X-Axis - usually labels. | false | False | None | |
none | The range(s) of cells holding values for the Y-Axis - usually "data". | false | False | None | |
none | Width of the chart in pixels. Defaults to 500. | false | False | 500 | |
none | Height of the chart in pixels. Defaults to 350. | false | False | 350 | |
none | 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. | false | False | 0 | |
none | Offset to position the chart by a fraction of a row. | false | False | 10 | |
none | 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. | false | False | 6 | |
none | Offset to position the chart by a fraction of a column. | false | False | 5 | |
none | Location of the key, either "Left", "Right", "Top", "Bottom" or "TopRight". | false | False | None | |
none | Font size for the key. | false | False | None | |
none | Sets the key in bold type. | false | False | False | |
none | 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. | false | False | False | |
none | Attaches a category label in charts which support this. | false | False | False | |
none | Attaches a percentage label in charts which support this. | false | False | False | |
none | Specifies explicit name(s) for the data series, which will appear in the legend/key | false | False | None | |
none | Sets the title in bold face. | false | False | False | |
none | Sets the point size for the title. | false | False | 0 | |
none | Specifies a title for the X-axis. | false | False | None | |
none | Sets the X-axis title in bold face. | false | False | False | |
none | Sets the font size for the axis title. | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers along the X-axis. | false | False | None | |
none | Spacing for the major gridlines / tick marks along the X-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks along the X-axis. | false | False | None | |
none | Maximum value for the scale along the X-axis. | false | False | None | |
none | Minimum value for the scale along the X-axis. | false | False | None | |
none | Position for the X-axis ("Top" or" Bottom"). | false | False | None | |
none | Specifies a title for the Y-axis. | false | False | None | |
none | Sets the Y-axis title in bold face. | false | False | False | |
none | Sets the font size for the Y-axis title. | false | False | None | |
none | A number formatting string, like "#,##0.00", for numbers on the Y-axis | false | False | None | |
none | Spacing for the major gridlines / tick marks on the Y-axis. | false | False | None | |
none | Spacing for the minor gridlines / tick marks on the Y-axis. | false | False | None | |
none | Maximum value on the Y-axis. | false | False | None | |
none | Minimum value on the Y-axis. | false | False | None | |
none | Position for the Y-axis ("Left" or "Right"). | false | False | None |
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
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
AutoFit | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
ForegroundColor | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
Hide | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
NFormat | false | false | |||
PatternColour | false | false | |||
Address | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false |
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 <Object> [-SourceWorkSheet <Object>] [-SourceRange <Object>] [-PivotRows <Object>] [-PivotData <Hashtable>] [-PivotColumns <Object>] [-PivotFilter <Object>] [-PivotDataToColumn] [-PivotTotals <String>] [-NoTotalsInPivot] [-GroupDateRow <String>] [-GroupDatePart {Years | Quarters | Months | Days | Hours | Minutes | Seconds}] [-GroupNumericRow <String>] [-GroupNumericMin <Double>] [-GroupNumericMax <Double>] [-GroupNumericInterval <Double>] [-PivotNumberFormat <String>] [-PivotTableStyle {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}] -PivotChartDefinition <Object> [-Activate] [<CommonParameters>] New-PivotTableDefinition -PivotTableName <Object> [-SourceWorkSheet <Object>] [-SourceRange <Object>] [-PivotRows <Object>] [-PivotData <Hashtable>] [-PivotColumns <Object>] [-PivotFilter <Object>] [-PivotDataToColumn] [-PivotTotals <String>] [-NoTotalsInPivot] [-GroupDateRow <String>] [-GroupDatePart {Years | Quarters | Months | Days | Hours | Minutes | Seconds}] [-GroupNumericRow <String>] [-GroupNumericMin <Double>] [-GroupNumericMax <Double>] [-GroupNumericInterval <Double>] [-PivotNumberFormat <String>] [-PivotTableStyle {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}] [-IncludePivotChart] [-ChartTitle <String>] [-ChartHeight <Int32>] [-ChartWidth <Int32>] [-ChartRow <Int32>] [-ChartColumn <Int32>] [-ChartRowOffSetPixels <Int32>] [-ChartColumnOffSetPixels <Int32>] [-ChartType {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}] [-NoLegend] [-ShowCategory] [-ShowPercent] [-Activate] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
PivtoTableName | 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 |
true | False | None | |
none | Worksheet where the data is found | false | False | None | |
none | 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. | false | False | None | |
none | Fields to set as rows in the PivotTable | false | False | None | |
none | A hash-table in form "FieldName"="Function", where function is one of Average, Count, CountNums, Max, Min, Product, None, StdDev, StdDevP, Sum, Var, VarP | false | False | None | |
none | Fields to set as columns in the PivotTable | false | False | None | |
none | Fields to use to filter in the PivotTable | false | False | None | |
none | 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. | false | False | False | |
none | 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. | false | False | Both | |
none | Included for compatibility - equivalent to -PivotTotals "None" | false | False | False | |
none | The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) | false | False | None | |
none | The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) | false | False | None | |
none | The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) | false | False | None | |
none | The starting point for grouping | false | False | 0 | |
none | The endpoint for grouping | false | False | 1.79769313486232E+308 | |
none | The interval for grouping | false | False | 100 | |
none | Number format to apply to the data cells in the PivotTable | false | False | None | |
none | Apply a table style to the PivotTable | false | False | None | |
none | Use a chart definition instead of specifying chart settings one by one | true | True (ByPropertyName) | None | |
none | If specified a chart Will be included. | false | False | False | |
none | Optional title for the pivot chart, by default the title omitted. | false | False | None | |
none | Height of the chart in Pixels (400 by default) | false | False | 400 | |
none | Width of the chart in Pixels (600 by default) | false | False | 600 | |
none | 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). | false | False | 0 | |
none | 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) | false | False | 4 | |
none | Vertical offset of the chart from the cell corner. | false | False | 0 | |
none | Horizontal offset of the chart from the cell corner. | false | False | 0 | |
none | Type of chart | false | False | Pie | |
none | If specified hides the chart legend | false | False | False | |
none | 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. | false | False | False | |
none | If specified attaches percentages to slices in a pie chart. | false | False | False | |
none | If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified | false | False | False |
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
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|
Returns an ExcelPackage object for the specified XLSX file.
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] <Object> [[-Password] <String>] [-KillExcel] [-Create] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | The path to the file to open. | true | False | None | |
none | 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. | false | False | False | |
none | The password for a protected worksheet, as a [normal] string (not a secure string). | false | False | None | |
none | By default Open-ExcelPackage will only open an existing file; -Create instructs it to create a new file if required. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> $excel = Open-ExcelPackage -Path "$env:TEMP\test99.xlsx" -Create PS\> $ws = Add-WorkSheet -ExcelPackage $excel
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
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | true (ByValue) | |||
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false |
Read text from clipboard and pass to either ConvertFrom-Csv or ConvertFrom-Json. Check out the how to video - https://youtu.be/dv2GOH5sbpA
Read text from clipboard. It can read CSV or JSON. Plus, you can specify the delimiter and headers.
Read-Clipboard [[-Delimiter] <Object>] [[-Header] <Object>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
false | false | ||||
false | false |
Read-Clipboard # Detects if the clipboard contains CSV, JSON, or Tab delimited data.EXAMPLE 2
Read-Clipboard -Delimiter '|' # Converts data using a pipe delimiterEXAMPLE 3
Read-Clipboard -Header 'P1', 'P2', 'P3' # Specify the header columns to be used
Read data from an OleDb source using dotnet classes. This allows for OleDb queries against excel spreadsheets. Examples will only be for querying xlsx files. For additional documentation, see Microsoft's documentation on the System.Data OleDb namespace here: https://docs.microsoft.com/en-us/dotnet/api/system.data.oledb
Read data from an OleDb source using dotnet classes. This allows for OleDb queries against excel spreadsheets. Examples will only be for querying xlsx files using ACE.
Read-OleDbData [-ConnectionString] <String> [-SqlStatement] <String> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
true | false | ||||
true | false |
Read-OleDbData ` -ConnectionString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=file.xlsx;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" ` -SqlStatement "select ROUND(F1) as [A] from [sheet1$A1:A1]"EXAMPLE 2
$ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=file.xlsx;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" $SqlStatement = "select ROUND(F1) as [A] from [sheet1$A1:A1]" Read-OleDbData -ConnectionString $ConnectionString -SqlStatement $SqlStatementEXAMPLE 3
$ReadDataArgs = @{ SqlStatement = Get-Content query.sql -Raw ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=file.xlsx;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" } $Results = Read-OleDbData @ReadDataArgs
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | true | false |
Removes one or more worksheets from one or more workbooks
Remove-WorkSheet [[-FullName] <Object>] [[-WorksheetName] <String[]>] [-Show] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Path | The fully qualified path to the XLSX file(s) | false | True (ByPropertyName) | None | |
none | The worksheet to be removed (sheet1 by default) | false | False | Sheet1 | |
none | If specified the file will be opened in excel after the sheet is removed. | false | False | False | |
wi | Shows what would happen if the cmdlet runs. The cmdlet is not run. | false | False | False | |
cf | Prompts you for confirmation before running the cmdlet. | false | False | False |
PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1
PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1
PS\> Remove-WorkSheet -Path Test1.xlsx -WorksheetName Sheet1,Target1 -Show
PS\> dir c:\reports\*.xlsx | Remove-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] <ExcelPackage> [-WorksheetName <String>] [<CommonParameters>] Select-Worksheet -ExcelWorkbook <ExcelWorkbook> [-WorksheetName <String>] [<CommonParameters>] Select-Worksheet -ExcelWorksheet <ExcelWorksheet> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | An object representing an ExcelPackage. | true | True (ByValue) | None | |
none | 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. | true | False | None | |
none | The name of the worksheet "Sheet1" by default. | false | False | None | |
none | An object representing an Excel worksheet. | true | False | None |
PS\> Select-Worksheet -ExcelWorkbook $ExcelWorkbook -WorksheetName "NewSheet"
PS\> Select-Worksheet -ExcelPackage $Pkg -WorksheetName "NewSheet2"
PS\> Select-Worksheet -ExcelWorksheet $ws
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 <Object> -SQL <String> [-QueryTimeout <Int32>] [-Force] [<CommonParameters>] Send-SQLDataToExcel -Connection <Object> -MsSQLserver [-DataBase <String>] -SQL <String> [-QueryTimeout <Int32>] [-Force] [<CommonParameters>] Send-SQLDataToExcel -Session <Object> -SQL <String> [-QueryTimeout <Int32>] [-Force] [<CommonParameters>] Send-SQLDataToExcel [-QueryTimeout <Int32>] -DataTable <DataTable> [-Force] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | 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. |
true | False | None | |
none | An active ODBC Connection or SQL connection object representing a session with a database which will be queried to get the data . | true | False | None | |
none | Specifies the connection string is for SQL server, not ODBC. | true | False | False | |
none | Switches to a specific database on a SQL server. | false | False | None | |
none | The SQL query to run against the session which was passed in -Session or set up from -Connection. | true | False | None | |
none | Override the default query time of 30 seconds. | false | False | 0 | |
none | 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. | true | False | None | |
none | If specified Export-Excel will be called with parameters specified, even if there is no data to send | false | False | False |
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
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
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"}
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
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
Send-SQLDataToExcel -path .\demo4.xlsx -WorkSheetname "LR" -Connection "DSN=LR" -sql "SELECT name AS CollectionName FROM AgLibraryCollection Collection ORDER BY CollectionName"
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false |
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 <ExcelPackage> [-Worksheetname <String>] [-Column <Object>] [-StartRow <Int32>] [-Value <Object>] [-Heading <Object>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [<CommonParameters>] Set-ExcelColumn -Worksheet <ExcelWorksheet> [-Column <Object>] [-StartRow <Int32>] [-Value <Object>] [-Heading <Object>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-AutoNameRange] [-Hide] [-Specified] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed. | true | False | None | |
none | The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name. | false | False | Sheet1 | |
none | This passes the worksheet object instead of passing a sheet name and an Excelpackage object. | true | False | None | |
none | Column to fill down - the first column is 1. 0 will be interpreted as first empty column. | false | True (ByValue) | 0 | |
none | First row to fill data in. | false | False | 0 | |
none | A value, formula or scriptblock to fill in. A script block can use $worksheet, $row, $column [number], $columnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. | false | False | None | |
none | Optional column heading. | false | False | None | |
NFormat | 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. | false | False | None | |
none | Style of border to draw around the row. | false | False | None | |
none | Colour for the text - if none specified it will be left as it it is. | false | False | None | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -StrikeThru:$false to remove strike through. | false | False | False | |
none | Subscript or Superscript (or None). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - "Solid" by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. Default is "General". | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
AutoFit | Attempt to auto-fit cells to the width their contents. | false | False | False | |
none | Set cells to a fixed width, ignored if -AutoSize is specified. | false | False | 0 | |
none | Set the inserted data to be a named range. | false | False | False | |
Hidden | Hide the column. | false | False | False | |
none | If specified, returns the range of cells which were affected. | false | False | False | |
none | If specified, return an object representing the Column, to allow further work to be done on it. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency'
PS\> Set-ExcelColumn -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange
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] <Object>] [-WorkSheet <ExcelWorksheet>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Value <Object>] [-Formula <Object>] [-ArrayFormula] [-ResetFont] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-AutoSize] [-Width <Single>] [-Height <Single>] [-Hidden] [-Locked] [-Merge] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Address | One or more row(s), Column(s) and/or block(s) of cells to format. | false | True (ByValue) | None | |
none | The worksheet where the format is to be applied. | false | False | None | |
NFormat | 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. | false | False | None | |
none | Style of border to draw around the range. | false | False | None | |
none | Color of the border. | false | False | [System.Drawing.Color]::Black | |
none | Style for the bottom border. | false | False | None | |
none | Style for the top border. | false | False | None | |
none | Style for the left border. | false | False | None | |
none | Style for the right border. | false | False | None | |
ForegroundColor | Colour for the text - if none is specified it will be left as it is. | false | False | None | |
none | Value for the cell. | false | False | None | |
none | Formula for the cell. | false | False | None | |
none | Specifies formula should be an array formula (a.k.a CSE [ctrl-shift-enter] formula). | false | False | False | |
none | Clear Bold, Italic, StrikeThrough and Underline and set color to Black. | false | False | False | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -Strikethru:$false to remove Strike through | false | False | False | |
none | Subscript or Superscript (or none). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - Solid by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. default is 'General'. | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text; up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
AutoFit | Autofit cells to width (columns or ranges only). | false | False | False | |
none | Set cells to a fixed width (columns or ranges only), ignored if Autosize is specified. | false | False | 0 | |
none | Set cells to a fixed height (rows or ranges only). | false | False | 0 | |
Hide | Hide a row or column (not a range); use -Hidden:$false to unhide. | false | False | False | |
none | 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. | false | False | False | |
none | Merges cells - it is recommended that you explicitly set -HorizontalAlignment | false | False | False |
PS\> $sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NumberFormat "#,###" -AutoFit
PS\> Set-ExcelRange -Range $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###"
PS\> Set-ExcelRange $excel.Workbook.Worksheets[1].Tables["Processes"] -Italic
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 <ExcelPackage> [-Worksheetname <Object>] [-Row <Object>] [-StartColumn <Int32>] [-Value <Object>] [-Heading <Object>] [-HeadingBold] [-HeadingSize <Int32>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-Height <Single>] [-Hide] [-ReturnRange] [-PassThru] [<CommonParameters>] Set-ExcelRow -Worksheet <ExcelWorksheet> [-Row <Object>] [-StartColumn <Int32>] [-Value <Object>] [-Heading <Object>] [-HeadingBold] [-HeadingSize <Int32>] [-NumberFormat <Object>] [-BorderAround {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderColor <Object>] [-BorderBottom {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderTop {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderLeft {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-BorderRight {None | Hair | Dotted | DashDot | Thin | DashDotDot | Dashed | MediumDashDotDot | MediumDashed | MediumDashDot | Thick | Medium | Double}] [-FontColor <Object>] [-Bold] [-Italic] [-Underline] [-UnderLineType {None | Single | Double | SingleAccounting | DoubleAccounting}] [-StrikeThru] [-FontShift {None | Baseline | Subscript | Superscript}] [-FontName <String>] [-FontSize <Single>] [-BackgroundColor <Object>] [-BackgroundPattern {None | Solid | DarkGray | MediumGray | LightGray | Gray125 | Gray0625 | DarkVertical | DarkHorizontal | DarkDown | DarkUp | DarkGrid | DarkTrellis | LightVertical | LightHorizontal | LightDown | LightUp | LightGrid | LightTrellis}] [-PatternColor <Object>] [-WrapText] [-HorizontalAlignment {General | Left | Center | CenterContinuous | Right | Fill | Distributed | Justify}] [-VerticalAlignment {Top | Center | Bottom | Distributed | Justify}] [-TextRotation <Int32>] [-Height <Single>] [-Hide] [-ReturnRange] [-PassThru] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
none | An Excel package object - for example from Export-Excel -PassThru - if specified requires a sheet name to be passed a parameter. | true | False | None | |
none | The name of the sheet to update in the package. | false | False | Sheet1 | |
none | A worksheet object instead of passing a name and package. | true | False | None | |
none | Row to fill right - first row is 1. 0 will be interpreted as first unused row. | false | True (ByValue) | 0 | |
none | Position in the row to start from. | false | False | 0 | |
none | Value, Formula or ScriptBlock to fill in. A ScriptBlock can use $worksheet, $row, $Column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn. | false | False | None | |
none | Optional row-heading. | false | False | None | |
none | Set the heading in bold type. | false | False | False | |
none | Change the font-size of the heading. | false | False | 0 | |
NFormat | Number format to apply to cells e.g. "dd/MM/yyyy HH:mm", "£#,##0.00;[Red]-£#,##0.00", "0.00%" , "##/##" , "0.0E+0" etc. | false | False | None | |
none | Style of border to draw around the row. | false | False | None | |
none | Color of the border. | false | False | [System.Drawing.Color]::Black | |
none | Style for the bottom border. | false | False | None | |
none | Style for the top border. | false | False | None | |
none | Style for the left border. | false | False | None | |
none | Style for the right border. | false | False | None | |
none | Color for the text - if not specified the font will be left as it it is. | false | False | None | |
none | Make text bold; use -Bold:$false to remove bold. | false | False | False | |
none | Make text italic; use -Italic:$false to remove italic. | false | False | False | |
none | Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining. | false | False | False | |
none | Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single". | false | False | Single | |
none | Strike through text; use -StrikeThru:$false to remove strike through. | false | False | False | |
none | Subscript or Superscript (or none). | false | False | None | |
none | Font to use - Excel defaults to Calibri. | false | False | None | |
none | Point size for the text. | false | False | 0 | |
none | Change background color. | false | False | None | |
none | Background pattern - solid by default. | false | False | Solid | |
PatternColour | Secondary color for background pattern. | false | False | None | |
none | Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping. | false | False | False | |
none | Position cell contents to Left, Right, Center etc. default is 'General'. | false | False | None | |
none | Position cell contents to Top, Bottom or Center. | false | False | None | |
none | Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise. | false | False | 0 | |
none | Set cells to a fixed height. | false | False | 0 | |
Hidden | Hide the row. | false | False | False | |
none | If sepecified, returns the range of cells which were affected. | false | False | False | |
none | If Specified, return a row object to allow further work to be done. | false | False | False |
The output type is the type of the objects that the cmdlet emits.
PS\> Set-ExcelRow -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" }
PS\> Set-ExcelRow -Worksheet $ws -Heading Total -HeadingBold -Value {"=sum($columnName`2:$columnName$endrow)" } -NumberFormat 'Currency' -StartColumn 2 -Bold -BorderTop Double -BorderBottom Thin
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | false | false | |||
None | true | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
None | false | false |
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 [<CommonParameters>]
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'
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