Trap invalid worksheet name in Set-ExcelRow/Column

This commit is contained in:
jhoneill
2018-11-13 10:16:51 +00:00
parent b4b5e75d28
commit 21b5a11aca
4 changed files with 19 additions and 7 deletions

View File

@@ -36,8 +36,8 @@ function New-ConditionalText {
This builds on the previous example, and specifies a condition of <=3 with
a format of red text on a white background; this applies to a named range
"Finish Position". The range could be written "C:C" to specify a named
column, or "C2:C102" to specify certain cells in the column.
"Finish Position". The range could be written -Range "C:C" to specify a
named column, or -Range "C2:C102" to specify certain cells in the column.
.Link
Add-Add-ConditionalFormatting
New-ConditionalFormattingIconSet

View File

@@ -53,11 +53,14 @@ Install-Module ImportExcel -scope CurrentUser
Install-Module ImportExcel
```
# What's new
- Set-ExcelRow and Set-ExcelColumn now check that the worksheet name they passed exists in the workbook.
# What's new 5.4
- Thank you to Conrad Agramont, Twitter: [@AGramont](https://twitter.com/@AGramont) for the `AddMultiWorkSheet.ps1` example. Much appreciated!
- Fixed several more bugs where parametrs were ignored if passed a zero value
- Fixed bug where chart series headers could not come form a cell refernce (=Sheet1!Z10 now works as a header reference)
- Fixed several more bugs where parameters were ignored if passed a zero value
- Fixed bug where chart series headers could not come form a cell reference (=Sheet1!Z10 now works as a header reference)
- Add-Chart will now allow a single X range, or as many X ranges as there are Y ranges.
- Merge-MultipleSheets is more robust.
- Set-ExcelRow and Set-ExcelColumn trap attempts to process a sheet with no rows/columns.

View File

@@ -121,7 +121,12 @@
begin {
#if we were passed a package object and a worksheet name , get the worksheet.
if ($ExcelPackage) {$Worksheet = $ExcelPackage.Workbook.Worksheets[$Worksheetname] }
if ($ExcelPackage) {
if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $Worksheetname) {
throw "The Workbook does not contain a sheet named '$Worksheetname'"
}
else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$Worksheetname] }
}
#In a script block to build a formula, we may want any of corners or the column name,
#if Column and Startrow aren't specified, assume first unused column, and first row

View File

@@ -116,8 +116,12 @@
)
begin {
#if we were passed a package object and a worksheet name , get the worksheet.
if ($ExcelPackage) {$Worksheet = $ExcelPackage.Workbook.worksheets[$Worksheetname] }
if ($ExcelPackage) {
if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $Worksheetname) {
throw "The Workbook does not contain a sheet named '$Worksheetname'"
}
else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$Worksheetname] }
}
#In a script block to build a formula, we may want any of corners or the columnname,
#if row and start column aren't specified assume first unused row, and first column
if (-not $StartColumn) {$StartColumn = $Worksheet.Dimension.Start.Column }