Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Set-OfficeExcelCell

Aliases: ExcelCell
Module
PSWriteOffice
Aliases
ExcelCell
Inputs
OfficeIMO.Excel.ExcelDocument

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: Address
Set-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: Coordinates

Examples

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 requiredposition: 0sets: Address
A1 address of the target cell.
-BackgroundColor OfficeColor optional
Cell fill colour expressed as a literal OfficeColor or theme role.
-Document ExcelDocument optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-Formula String optional
Formula text (without leading =).
-GradientAngle Double optional
Linear fill angle in degrees.
-GradientFrom OfficeColor optional
First fill colour; GradientTo is required with it.
-GradientTo OfficeColor optional
Second fill colour; GradientFrom is required with it.
-NumberFormat String optional
Number format code to apply.
-PassThru SwitchParameter optional
Emits the native result after the operation.
-Sheet OfficeSheetSelector optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-Value Object optionalposition: 1
Value or values consumed by the selected operation.
-Column Object requiredsets: Coordinates
1-based column index.
-Row Int32 requiredsets: Coordinates
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.