# Edit-OfficeExcelRow

Runs a script block against each editable row of a range and writes the changes back.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Excel.ExcelDocument` `System.String[]`

**Source**

[EditOfficeExcelRowCommand.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Excel/EditOfficeExcelRowCommand.cs#L49) 

Runs a script block against each editable row of a range and writes the changes back.

## Syntax

```
Edit-OfficeExcelRow
[-Document <ExcelDocument>]
[-NumericAsDecimal]
[-PassThru]
[-Range <String>]
[-ScriptBlock] <ScriptBlock>
[-Sheet <OfficeSheetSelector>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-edit-officeexcelrow-exceldocument-switchparameter-switchparameter-string-scriptblock-officesheetselector-switchparameter-switchparameter)

Parameter set: `Document`

```
Edit-OfficeExcelRow
[-NumericAsDecimal]
[-PassThru]
[-Path] <String[]>
[-Range <String>]
[-ScriptBlock] <ScriptBlock>
[-Sheet <OfficeSheetSelector>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-edit-officeexcelrow-switchparameter-switchparameter-string-string-scriptblock-officesheetselector-switchparameter-switchparameter)

Parameter set: `Path`

```
Edit-OfficeExcelRow
-LiteralPath <String[]>
[-NumericAsDecimal]
[-PassThru]
[-Range <String>]
[-ScriptBlock] <ScriptBlock>
[-Sheet <OfficeSheetSelector>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-edit-officeexcelrow-string-switchparameter-switchparameter-string-scriptblock-officesheetselector-switchparameter-switchparameter)

Parameter set: `LiteralPath`

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Update Existing Excel Workbooks](/docs/pswriteoffice/excel-update-existing/) Guide
  
  Replace values, edit rows, append table data, and make targeted workbook changes without rebuilding every sheet.

## Examples

### Update rows in place

```powershell
Edit-OfficeExcelRow -Path .\Reports\Releases.xlsx -Sheet Releases -ScriptBlock {
    param($row)
    if ($row['Status'].Value -eq 'Draft') { $row.Set('Status', 'Ready') }
}
```

Marks every draft row on the Releases sheet as ready and saves the workbook.

### Recalculate renewal dates in an open workbook

```powershell
$book = Open-OfficeExcel -Path .\Contracts\Licences.xlsx
Edit-OfficeExcelRow -Document $book -Sheet Licences -Range A1:F400 -ScriptBlock {
    param($row)
    if ($row['State'].Value -eq 'Active') {
        $row.Set('RenewalDate', $row.Get[datetime]('StartDate').AddYears(1))
    }
}
Save-OfficeExcel -Document $book -PassThru | Close-OfficeExcel
```

Sets the renewal date of each active licence to one year after its start date in a live workbook, which the script then saves.

### Edit rows while building a workbook

```powershell
$tickets = Import-OfficeCsv -Path .\Data\Tickets.csv
New-OfficeExcel -Path .\Reports\Tickets.xlsx {
    ExcelSheet 'Tickets' {
        ExcelTable $tickets -Name Tickets
    }
    Edit-OfficeExcelRow -Sheet Tickets -ScriptBlock {
        param($row)
        if (-not $row['Owner'].Value) { $row.Set('Owner', 'Unassigned') }
    }
}
```

Writes imported rows and then fixes up their status inside the same block, without a -Document variable.

## Parameters

**-Document ExcelDocument optionalpipeline: True (ByValue)sets: Document**

Caller-owned workbook; omission uses the enclosing Excel content block.

**-NumericAsDecimal SwitchParameter optional**

Prefer decimals instead of doubles for numeric values.

**-PassThru SwitchParameter optional**

Emits the native result after the operation.

**-Range String optional**

A1 cell range on the selected worksheet.

**-ScriptBlock ScriptBlock requiredposition: 1**

Script block to run once per editable row. The row is passed as the first argument.

**-Sheet OfficeSheetSelector optionalaliases: WorksheetName**

Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.

**-WhatIf SwitchParameter optional**

Shows what would happen if the command runs.

**-Confirm SwitchParameter optional**

Prompts for confirmation before running the command.

**-Path String[] requiredposition: 0pipeline: True (ByValue)aliases: FilePathsets: Path**

Workbook paths resolved with filesystem wildcard support.

**-LiteralPath String[] requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath**

Literal workbook paths, including FileInfo.FullName and provider PSPath.

## 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:6175E237653722EDA2553AACD30916F2FBA399D9EE0A641163C3773E399C91BC -->
