Add-OfficeExcelTableRow
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>]#PathAdd-OfficeExcelTableRow -Document <ExcelDocument> [-InputObject] <Object> [-PassThru] [-Sheet <String>] [-SheetIndex <Int32>] -TableName <String> [<CommonParameters>]#DocumentAdd-OfficeExcelTableRow [-InputObject] <Object> [-PassThru] -Table <ExcelTable> [<CommonParameters>]#TableDescription
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
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 -SaveUses 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 $rowsOpens the workbook from disk, appends both objects to the named table, and saves the file.
Parameters
- -InputObject Object
- Rows to append. Accepts objects, dictionaries, DataTables, DataViews, IDataReaders, and DataRows.
- -PassThru SwitchParameter
- 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
- Workbook path to open, update, save, and close.
- -Sheet String
- Worksheet name that owns the table. Use this when table names might repeat across sheets.
- -SheetIndex Int32
- Zero-based worksheet index that owns the table.
- -TableName String
- Existing table name or display name, for example the name returned by Get-OfficeExcelTable.
- -Document ExcelDocument
- Open workbook to update. The caller remains responsible for saving and closing it.
- -Table ExcelTable
- 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.