Files
ImportExcel/Public/Remove-Worksheet.ps1
2019-12-01 17:04:27 +00:00

28 lines
799 B
PowerShell

function Remove-Worksheet {
[CmdletBinding(SupportsShouldProcess=$true)]
param(
# [Parameter(ValueFromPipelineByPropertyName)]
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Path')]
$FullName,
[String[]]$WorksheetName = "Sheet1",
[Switch]$Show
)
Process {
if (!$FullName) {
throw "Remove-Worksheet requires the and Excel file"
}
$pkg = Open-ExcelPackage -Path $FullName
if ($pkg) {
foreach ($wsn in $WorksheetName) {
if ($PSCmdlet.ShouldProcess($FullName,"Remove Sheet $wsn")) {
$pkg.Workbook.Worksheets.Delete($wsn)
}
}
Close-ExcelPackage -ExcelPackage $pkg -Show:$Show
}
}
}