forked from dfinke/ImportExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-Worksheet.ps1
More file actions
28 lines (25 loc) · 799 Bytes
/
Copy pathRemove-Worksheet.ps1
File metadata and controls
28 lines (25 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
}
}
}