mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Added to psm1
This commit is contained in:
@@ -1,34 +1,2 @@
|
||||
Function Remove-WorkSheet {
|
||||
Param (
|
||||
$Path,
|
||||
$WorksheetName
|
||||
)
|
||||
|
||||
$Path = (Resolve-Path $Path).ProviderPath
|
||||
|
||||
$Excel = New-Object -TypeName OfficeOpenXml.ExcelPackage $Path
|
||||
|
||||
$workSheet = $Excel.Workbook.Worksheets[$WorkSheetName]
|
||||
|
||||
if($workSheet) {
|
||||
if($Excel.Workbook.Worksheets.Count -gt 1) {
|
||||
$Excel.Workbook.Worksheets.Delete($workSheet)
|
||||
} else {
|
||||
throw "Cannot delete $WorksheetName. A workbook must contain at least one visible worksheet"
|
||||
}
|
||||
|
||||
} else {
|
||||
throw "$WorksheetName not found"
|
||||
}
|
||||
|
||||
$Excel.Save()
|
||||
$Excel.Dispose()
|
||||
}
|
||||
|
||||
|
||||
Import-Module .\ImportExcel.psd1 -Force
|
||||
|
||||
$names = Get-ExcelSheetInfo C:\Temp\testDelete.xlsx
|
||||
$names | Foreach-Object { Remove-WorkSheet C:\Temp\testDelete.xlsx $_.Name}
|
||||
|
||||
##Remove-WorkSheet C:\Temp\testDelete.xlsx sheet6
|
||||
}
|
||||
Reference in New Issue
Block a user