API Reference
Add-OfficeExcelTableRow
Appends one or more data rows to an existing Excel table.
Remarks
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.
PS>
$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.
PS>
$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.
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.
Syntax
Add-OfficeExcelTableRow -InputObject <Object> -InputPath <String> [-PassThru] [-Sheet <String>] [-SheetIndex <Nullable`1>] -TableName <String> [<CommonParameters>]#PathParameters
- InputObject Object
- Rows to append. Accepts objects, dictionaries, DataTables, DataViews, IDataReaders, and DataRows.
- InputPath String
- Workbook path to open, update, save, and close.
- 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.
- Sheet String
- Worksheet name that owns the table. Use this when table names might repeat across sheets.
- SheetIndex Nullable`1
- Zero-based worksheet index that owns the table.
- TableName String
- Existing table name or display name, for example the name returned by Get-OfficeExcelTable.
Outputs
OfficeIMO.Excel.ExcelTable
Add-OfficeExcelTableRow -Document <ExcelDocument> -InputObject <Object> [-PassThru] [-Sheet <String>] [-SheetIndex <Nullable`1>] -TableName <String> [<CommonParameters>]#DocumentParameters
- Document ExcelDocument
- Open workbook to update. The caller remains responsible for saving and closing it.
- 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.
- Sheet String
- Worksheet name that owns the table. Use this when table names might repeat across sheets.
- SheetIndex Nullable`1
- Zero-based worksheet index that owns the table.
- TableName String
- Existing table name or display name, for example the name returned by Get-OfficeExcelTable.
Outputs
OfficeIMO.Excel.ExcelTable
Add-OfficeExcelTableRow -InputObject <Object> [-PassThru] -Table <ExcelTable> [<CommonParameters>]#TableParameters
- 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.
- Table ExcelTable
- Existing OfficeIMO Excel table wrapper to append to when the table has already been resolved.
Outputs
OfficeIMO.Excel.ExcelTable