Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Close-OfficeExcel

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument

Closes an Excel workbook and optionally saves it.

Syntax

Close-OfficeExcel
[-ClearCachedFormulaResults]
[-DateSystem <1900|1904|NineteenHundred|NineteenFour>]
[-DisableFastPackageWriter]
-Document <ExcelDocument>
[-EvaluateFormulas]
[-ForceFullCalculationOnOpen]
[-MarkFormulasDirty]
[-Open]
[-Password <String>]
[-Path <String>]
[-SafePreflight]
[-SafeRepairDefinedNames]
[-Save]
[-ValidateOpenXml]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Convenience wrapper so scripts do not need to call Save or Dispose directly.

Examples

Save, validate, and close an open workbook.

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.

Parameters

-ClearCachedFormulaResults SwitchParameter optional
Remove cached formula results before saving.
-DateSystem String optional
Workbook date system for Excel date serials.
Possible values: 1900, 1904, NineteenHundred, NineteenFour
-DisableFastPackageWriter SwitchParameter optional
Disable OfficeIMO fast package writers for this save.
-Document ExcelDocument requiredpipeline: True (ByValue)
Workbook to close.
-EvaluateFormulas SwitchParameter optional
Evaluate supported formulas and write cached values before saving.
-ForceFullCalculationOnOpen SwitchParameter optional
Request a full workbook recalculation when opened in Excel-compatible applications.
-MarkFormulasDirty SwitchParameter optional
Mark formula cells dirty before saving.
-Open SwitchParameter optionalaliases: Show
Open the workbook after saving. Requires -Save or -Path.
-Password String optional
Password used to save the workbook as an encrypted package.
-Path String optional
Optional output path when saving.
-SafePreflight SwitchParameter optional
Run OfficeIMO worksheet preflight cleanup before saving.
-SafeRepairDefinedNames SwitchParameter optional
Repair common defined-name issues before saving.
-Save SwitchParameter optional
Persist changes before closing.
-ValidateOpenXml SwitchParameter optional
Validate the saved package with OpenXmlValidator and throw on errors.

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.