mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-01-03 09:03:15 +00:00
Move help from Comment-based to md. Relocate functions (sans help)
This commit is contained in:
34
ExportedCommands/Close-ExcelPackage.ps1
Normal file
34
ExportedCommands/Close-ExcelPackage.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
Function Close-ExcelPackage {
|
||||
[CmdLetBinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")]
|
||||
Param (
|
||||
[parameter(Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[OfficeOpenXml.ExcelPackage]$ExcelPackage,
|
||||
[switch]$Show,
|
||||
[Switch]$NoSave,
|
||||
$SaveAs,
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$Password,
|
||||
[switch]$Calculate
|
||||
)
|
||||
if ( $NoSave) {$ExcelPackage.Dispose()}
|
||||
else {
|
||||
if ($Calculate) {
|
||||
try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) }
|
||||
Catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."}
|
||||
}
|
||||
if ($SaveAs) {
|
||||
$SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs)
|
||||
if ($Password) {$ExcelPackage.SaveAs( $SaveAs, $Password ) }
|
||||
else {$ExcelPackage.SaveAs( $SaveAs)}
|
||||
}
|
||||
else {
|
||||
if ($Password) {$ExcelPackage.Save($Password) }
|
||||
else {$ExcelPackage.Save() }
|
||||
$SaveAs = $ExcelPackage.File.FullName
|
||||
}
|
||||
$ExcelPackage.Dispose()
|
||||
if ($Show) {Start-Process -FilePath $SaveAs }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user