mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-11 05:43:17 +00:00
Replaced -Force switch with -NoClobber switch
This commit is contained in:
@@ -59,7 +59,7 @@ function Export-Excel {
|
||||
[Switch]$IncludePivotChart,
|
||||
[Switch]$AutoSize,
|
||||
[Switch]$Show,
|
||||
[Switch]$Force
|
||||
[Switch]$NoClobber
|
||||
)
|
||||
|
||||
Begin {
|
||||
@@ -68,15 +68,24 @@ function Export-Excel {
|
||||
$pkg = New-Object OfficeOpenXml.ExcelPackage $Path
|
||||
|
||||
if($pkg.Workbook.Worksheets[$WorkSheetname]) {
|
||||
if($NoClobber) {
|
||||
$AlreadyExists = $true
|
||||
throw ""
|
||||
} else {
|
||||
$pkg.Workbook.Worksheets.delete($WorkSheetname)
|
||||
}
|
||||
}
|
||||
|
||||
$ws = $pkg.Workbook.Worksheets.Add($WorkSheetname)
|
||||
$Row = 1
|
||||
} Catch {
|
||||
if($AlreadyExists) {
|
||||
throw "$WorkSheetname already exists."
|
||||
} else {
|
||||
throw $Error[0].Exception.InnerException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user