API Reference
Cmdlet
Close-OfficeExcel
Closes an Excel workbook and optionally saves it.
Remarks
Convenience wrapper so scripts do not need to call Save or Dispose directly.
Examples
Example 1: Save, validate, and close an open workbook.
PS>
New-OfficeExcel -Path .\report.xlsx {
Add-OfficeExcelSheet -Name Data {
Set-OfficeExcelRow -Row 1 -Values 'Region', 'Revenue'
Set-OfficeExcelRow -Row 2 -Values 'EMEA', 98000
}
}
$workbook = Get-OfficeExcel -Path .\report.xlsx
$workbook | Close-OfficeExcel -Save -Path .\report-final.xlsx -SafePreflight -ValidateOpenXml
Saves pending changes through OfficeIMO's normal save path, validates the package, and releases the workbook.
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
Close-OfficeExcel [-ClearCachedFormulaResults] [-DateSystem <1900|1904|NineteenHundred|NineteenFour>] [-DisableFastPackageWriter] -Document <ExcelDocument> [-EvaluateFormulas] [-ForceFullCalculationOnOpen] [-MarkFormulasDirty] [-Password <String>] [-Path <String>] [-SafePreflight] [-SafeRepairDefinedNames] [-Save] [-Show] [-ValidateOpenXml] [<CommonParameters>]#Parameter set:
All Parameter SetsParameters
- ClearCachedFormulaResults SwitchParameter
- Remove cached formula results before saving.
- DateSystem String
- Workbook date system for Excel date serials.
- Possible values:
1900,1904,NineteenHundred,NineteenFour - DisableFastPackageWriter SwitchParameter
- Disable OfficeIMO fast package writers for this save.
- Document ExcelDocument
- Workbook to close.
- EvaluateFormulas SwitchParameter
- Evaluate supported formulas and write cached values before saving.
- ForceFullCalculationOnOpen SwitchParameter
- Request a full workbook recalculation when opened in Excel-compatible applications.
- MarkFormulasDirty SwitchParameter
- Mark formula cells dirty before saving.
- Password String
- Password used to save the workbook as an encrypted package.
- Path String
- Optional output path when saving.
- SafePreflight SwitchParameter
- Run OfficeIMO worksheet preflight cleanup before saving.
- SafeRepairDefinedNames SwitchParameter
- Repair common defined-name issues before saving.
- Save SwitchParameter
- Persist changes before closing.
- Show SwitchParameter
- Open the workbook in Excel after saving.
- ValidateOpenXml SwitchParameter
- Validate the saved package with OpenXmlValidator and throw on errors.