mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Bumped version. Added url for how to videos
This commit is contained in:
35
RemoveWorksheet.ps1
Normal file
35
RemoveWorksheet.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
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()
|
||||
}
|
||||
|
||||
cls
|
||||
|
||||
ipmo .\ImportExcel.psd1 -Force
|
||||
|
||||
$names = Get-ExcelSheetInfo C:\Temp\testDelete.xlsx
|
||||
$names | % { Remove-WorkSheet C:\Temp\testDelete.xlsx $_.Name}
|
||||
|
||||
##Remove-WorkSheet C:\Temp\testDelete.xlsx sheet6
|
||||
Reference in New Issue
Block a user