Replaced -Force switch with -NoClobber switch

This commit is contained in:
Doug Finke
2015-04-10 14:32:48 -04:00
parent ea463c9622
commit e32095d88d
2 changed files with 14 additions and 4 deletions

View File

@@ -59,7 +59,7 @@ function Export-Excel {
[Switch]$IncludePivotChart,
[Switch]$AutoSize,
[Switch]$Show,
[Switch]$Force
[Switch]$NoClobber
)
Begin {
@@ -68,13 +68,22 @@ function Export-Excel {
$pkg = New-Object OfficeOpenXml.ExcelPackage $Path
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)
$Row = 1
} Catch {
throw $Error[0].Exception.InnerException
if($AlreadyExists) {
throw "$WorkSheetname already exists."
} else {
throw $Error[0].Exception.InnerException
}
}
}

View File

@@ -15,7 +15,8 @@ What's new
#### 4/10/2015
* Renamed `AutoFitColumns` to `AutoSize`
* Implemented `Export-MultipleExcelSheets`
* Implemented `-Password` for a worksheet
* Implemented `-Password` for a worksheet
* Repalce `-Force` switch with `-NoClobber` switch
#### Examples
`gsv | Export-Excel .\test.xlsx -WorkSheetname Services`