Cmdlet
Set-OfficeExcelCell
Sets a cell value, formula, rich text, number format or fill.
Syntax
Set-OfficeExcelCell
[-Address] <String>
[-BackgroundColor <OfficeColor>]
[-Document <ExcelDocument>]
[-Formula <String>]
[-GradientAngle <Double>]
[-GradientFrom <OfficeColor>]
[-GradientTo <OfficeColor>]
[-NumberFormat <String>]
[-PassThru]
[-Sheet <OfficeSheetSelector>]
[[-Value] <Object>]
[<CommonParameters>]#Parameter set:
AddressSet-OfficeExcelCell
[-BackgroundColor <OfficeColor>]
-Column <Object>
[-Document <ExcelDocument>]
[-Formula <String>]
[-GradientAngle <Double>]
[-GradientFrom <OfficeColor>]
[-GradientTo <OfficeColor>]
[-NumberFormat <String>]
[-PassThru]
-Row <Int32>
[-Sheet <OfficeSheetSelector>]
[[-Value] <Object>]
[<CommonParameters>]#Parameter set:
CoordinatesExamples
Write a value to a cell
New-OfficeExcel -Path .\Budget.xlsx {
ExcelSheet 'Summary' {
ExcelCell A1 'Budget 2027'
}
}Writes a heading into A1 of the Summary sheet.
Lay out a small calculation
New-OfficeExcel -Path .\Estimates\Migration-Cost.xlsx {
ExcelSheet 'Estimate' {
ExcelCell A1 'Servers'
ExcelCell B1 42
ExcelCell A2 'Cost per server'
ExcelCell B2 1850 -NumberFormat '#,##0.00'
ExcelCell A3 'Total'
ExcelCell B3 -Formula '=B1*B2' -NumberFormat '#,##0.00' -BackgroundColor '#FEF3C7'
}
}Writes labels, inputs and formulas for a cost estimate, formatting the result as currency.
Write rich text into a cell
Open-OfficeExcel -Path .\Reports\Status.xlsx {
ExcelSheet 'Summary' {
ExcelCell B2 {
ExcelText 'Status: ' -Bold
ExcelText 'On track' -Bold -Color Success
}
}
}Passes a block of text runs as the value, so one cell mixes bold and coloured text.
Parameters
- -Address String
- A1 address of the target cell.
- -BackgroundColor OfficeColor
- Cell fill colour expressed as a literal OfficeColor or theme role.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -Formula String
- Formula text (without leading =).
- -GradientAngle Double
- Linear fill angle in degrees.
- -GradientFrom OfficeColor
- First fill colour; GradientTo is required with it.
- -GradientTo OfficeColor
- Second fill colour; GradientFrom is required with it.
- -NumberFormat String
- Number format code to apply.
- -PassThru SwitchParameter
- Emits the native result after the operation.
- -Sheet OfficeSheetSelector
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -Value Object
- Value or values consumed by the selected operation.
- -Column Object
- 1-based column index.
- -Row Int32
- 1-based row index.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.