Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Add-OfficeExcelTableRow

Module PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument OfficeIMO.Excel.ExcelTable System.Object
Outputs
OfficeIMO.Excel.ExcelTable

Appends one or more data rows to an existing Excel table.

Syntax

Add-OfficeExcelTableRow [-InputObject] <Object> [-PassThru] [-Path] <String> [-Sheet <String>] [-SheetIndex <Int32>] -TableName <String> [<CommonParameters>]
#
Parameter set: Path
Add-OfficeExcelTableRow -Document <ExcelDocument> [-InputObject] <Object> [-PassThru] [-Sheet <String>] [-SheetIndex <Int32>] -TableName <String> [<CommonParameters>]
#
Parameter set: Document
Add-OfficeExcelTableRow [-InputObject] <Object> [-PassThru] -Table <ExcelTable> [<CommonParameters>]
#
Parameter set: Table

Description

Use this command when a workbook already contains a named table and the script should extend that table without recreating the worksheet through the Excel DSL. The command accepts a workbook path, an open ExcelDocument, or an existing ExcelTable object. Objects, dictionaries, DataTable, DataView, IDataReader, and DataRow input are normalized through the same table input pipeline used by Add-OfficeExcelTable.

When a path is supplied, PSWriteOffice opens the workbook, appends the rows, saves the workbook, and releases the document. When an open workbook or table is supplied, the caller controls the lifetime and should close or save the workbook after all edits are complete.

Examples

Authored help example

Append a row to a named table in an open workbook.

$doc = Get-OfficeExcel -Path .\Report.xlsx
$doc | Add-OfficeExcelTableRow -Sheet Data -TableName Sales -InputObject ([pscustomobject]@{ Region='APAC'; Revenue=300 })
$doc | Close-OfficeExcel -Save

Uses the existing OfficeIMO Excel table append API and keeps the workbook open for further changes.

Append several service-readiness rows to an existing table.

$rows = @(
    [pscustomobject]@{ Service='Identity'; Status='Ready'; Owner='IAM' }
    [pscustomobject]@{ Service='Network'; Status='Investigating'; Owner='Platform' }
)
Add-OfficeExcelTableRow -Path .\Readiness.xlsx -Sheet Readiness -TableName ServiceReadiness -InputObject $rows

Opens the workbook from disk, appends both objects to the named table, and saves the file.

Parameters

-InputObject Object requiredposition: 1pipeline: True (ByValue)aliases: Data, Values
Rows to append. Accepts objects, dictionaries, DataTables, DataViews, IDataReaders, and DataRows.
-PassThru SwitchParameter optional
Emit the updated table wrapper for open document or table inputs. Path-owned workbooks are saved and closed by this command, so they do not emit a live table wrapper.
-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Workbook path to open, update, save, and close.
-Sheet String optionalaliases: WorksheetNamesets: Path, Document
Worksheet name that owns the table. Use this when table names might repeat across sheets.
-SheetIndex Int32 optionalsets: Path, Document
Zero-based worksheet index that owns the table.
-TableName String requiredaliases: Namesets: Path, Document
Existing table name or display name, for example the name returned by Get-OfficeExcelTable.
-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document
Open workbook to update. The caller remains responsible for saving and closing it.
-Table ExcelTable requiredpipeline: True (ByValue)sets: Table
Existing OfficeIMO Excel table wrapper to append to when the table has already been resolved.

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.