mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-12 22:33:15 +00:00
Replaced -Force switch with -NoClobber switch
This commit is contained in:
@@ -59,7 +59,7 @@ function Export-Excel {
|
|||||||
[Switch]$IncludePivotChart,
|
[Switch]$IncludePivotChart,
|
||||||
[Switch]$AutoSize,
|
[Switch]$AutoSize,
|
||||||
[Switch]$Show,
|
[Switch]$Show,
|
||||||
[Switch]$Force
|
[Switch]$NoClobber
|
||||||
)
|
)
|
||||||
|
|
||||||
Begin {
|
Begin {
|
||||||
@@ -68,13 +68,22 @@ function Export-Excel {
|
|||||||
$pkg = New-Object OfficeOpenXml.ExcelPackage $Path
|
$pkg = New-Object OfficeOpenXml.ExcelPackage $Path
|
||||||
|
|
||||||
if($pkg.Workbook.Worksheets[$WorkSheetname]) {
|
if($pkg.Workbook.Worksheets[$WorkSheetname]) {
|
||||||
$pkg.Workbook.Worksheets.delete($WorkSheetname)
|
if($NoClobber) {
|
||||||
|
$AlreadyExists = $true
|
||||||
|
throw ""
|
||||||
|
} else {
|
||||||
|
$pkg.Workbook.Worksheets.delete($WorkSheetname)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ws = $pkg.Workbook.Worksheets.Add($WorkSheetname)
|
$ws = $pkg.Workbook.Worksheets.Add($WorkSheetname)
|
||||||
$Row = 1
|
$Row = 1
|
||||||
} Catch {
|
} Catch {
|
||||||
throw $Error[0].Exception.InnerException
|
if($AlreadyExists) {
|
||||||
|
throw "$WorkSheetname already exists."
|
||||||
|
} else {
|
||||||
|
throw $Error[0].Exception.InnerException
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ What's new
|
|||||||
* Renamed `AutoFitColumns` to `AutoSize`
|
* Renamed `AutoFitColumns` to `AutoSize`
|
||||||
* Implemented `Export-MultipleExcelSheets`
|
* Implemented `Export-MultipleExcelSheets`
|
||||||
* Implemented `-Password` for a worksheet
|
* Implemented `-Password` for a worksheet
|
||||||
|
* Repalce `-Force` switch with `-NoClobber` switch
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
`gsv | Export-Excel .\test.xlsx -WorkSheetname Services`
|
`gsv | Export-Excel .\test.xlsx -WorkSheetname Services`
|
||||||
|
|||||||
Reference in New Issue
Block a user