mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
28 lines
799 B
PowerShell
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
|
|
}
|
|
}
|
|
} |