Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Save-OfficeExcel

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
System.IO.FileInfo

Saves a live Excel workbook without closing it.

Syntax

Save-OfficeExcel
[-AllowLoss]
[-Document] <ExcelDocument>
[-PassThru]
[-Password <SecureString>]
[-Path <String>]
[-SaveOptions <ExcelSaveOptions>]
[-Show]
[<CommonParameters>]
#
Parameter set: Default

Description

Omitted Password preserves loaded encryption; an explicit null removes it. SaveOptions accepts native options or a hashtable. PassThru returns the saved FileInfo. The workbook must use explicit persistence.

Examples

Save pending edits and then close the workbook.

Save-OfficeExcel -Document $workbook -Path ./Reviewed.xlsx -SaveOptions @{ Preflight = $true; ValidateOpenXml = $true } -PassThru
Close-OfficeExcel -Document $workbook

Save a live workbook

$book = Open-OfficeExcel -Path .\Reports\Inventory.xlsx
Save-OfficeExcel -Document $book
Close-OfficeExcel -Document $book

Saves a workbook opened without a content block back to its own path and closes it.

Save a validated copy under a new name

$book = New-OfficeExcel
Add-OfficeExcelSheet -Document $book -Name 'Changes' {
    ExcelTable (Import-OfficeCsv -Path .\Data\Changes-Week43.csv)
}
$book |
    Save-OfficeExcel -Path .\Reports\Changes-Week43.xlsx -SaveOptions @{ ValidateOpenXml = $true } -PassThru
Close-OfficeExcel -Document $book

Writes this week's change log to a new file with Open XML validation, returns the saved file, and closes the live workbook explicitly.

Save with a password

$password = Read-Host -AsSecureString -Prompt 'Workbook password'
$book = Open-OfficeExcel -Path .\Reports\Salaries-2027.xlsx
Save-OfficeExcel -Document $book -Path .\Secure\Salaries-2027.xlsx -Password $password
Close-OfficeExcel -Document $book

Encrypts the saved file with a password read at the prompt, so it never appears in the script or history.

Parameters

-AllowLoss SwitchParameter optional
Explicitly accept reported native-save reductions; overrides SaveOptions when supplied.
-Document ExcelDocument requiredposition: 0pipeline: True (ByValue)
Live workbook to save.
-PassThru SwitchParameter optional
Return the saved FileInfo.
-Password SecureString optional
Override the output password; omission retains loaded encryption.
-Path String optional
Optional new destination; omission uses the associated path.
-SaveOptions ExcelSaveOptions optional
Native save settings, or a hashtable using the save-option factory's names.
-Show SwitchParameter optional
Open the saved file in its registered default application.

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.