From 243ba0bb3c036672fc7e3797db00f5173bbc1e20 Mon Sep 17 00:00:00 2001 From: JustinGrote Date: Mon, 9 Apr 2018 14:35:28 -0700 Subject: [PATCH] Add ReZip Parameter for MSOnline compatability --- Export-Excel.ps1 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index b8d3b63..5748505 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -400,7 +400,8 @@ # [Parameter(ParameterSetName = 'TableNow')] [Switch]$Now, [Switch]$ReturnRange, - [Switch]$NoTotalsInPivot + [Switch]$NoTotalsInPivot, + [Switch]$ReZip ) Begin { @@ -1000,7 +1001,26 @@ $ws.Dimension.Address } + + $pkg.Save() + + if ($ReZip) { + write-verbose "Re-Zipping $($pkg.file) using .NET ZIP library" + $zipAssembly = "System.IO.Compression.Filesystem" + try { + Add-Type -assembly $zipAssembly -ErrorAction stop + } catch { + write-error "The -ReZip parameter requires .NET Framework 4.5 or later to be installed. Recommend to install Powershell v4+" + continue + } + + $TempZipPath = Join-Path -path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName()) + [io.compression.zipfile]::ExtractToDirectory($pkg.File,$TempZipPath) | Out-Null + Remove-Item $pkg.File -Force + [io.compression.zipfile]::CreateFromDirectory($TempZipPath,$pkg.File) | Out-Null + } + $pkg.Dispose() if ($Show) {