From 29503861fb1f49a6cf34eeb1aa83d664c3825a9d Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 2 Aug 2018 13:27:49 +0100 Subject: [PATCH] Generate warning instead of aborting when a property can't be inserted into a cell. --- Export-Excel.ps1 | 7 ++++--- README.md | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 32a1f0d..beaebb5 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -635,7 +635,8 @@ if ($isDataTypeValueType) { $ColumnIndex = $StartColumn $Row += 1 - Add-CellValue -TargetCell $ws.Cells[$Row, $ColumnIndex] -CellValue $TargetData + try {Add-CellValue -TargetCell $ws.Cells[$Row, $ColumnIndex] -CellValue $TargetData} + catch {Write-Warning "Could not insert value at Row $Row. "} } else { #region Add headers @@ -667,8 +668,8 @@ foreach ($Name in $script:Header) { #region Add non header values - Add-CellValue -TargetCell $ws.Cells[$Row, $ColumnIndex] -CellValue $TargetData.$Name - + try {Add-CellValue -TargetCell $ws.Cells[$Row, $ColumnIndex] -CellValue $TargetData.$Name} + catch {Write-Warning -Message "Could not insert the $Name property at Row $Row, Column $Column"} $ColumnIndex += 1 #endregion } diff --git a/README.md b/README.md index 2574dd7..84570db 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,12 @@ Install-Module ImportExcel - The NumberFormat parameter (in Export-Excel, Set-Row, Set-Column, Set-Format and Add-ConditionalFormat) and X&YAxisNumberFormat paramaters (in New-ExcelChartDefinition and Add-ExcelChart) now have an argument completer and the names Currency, Number, Percentage, Scientific, Fraction, Short Date ,Short time,Long time, Date-Time and Text will be converted to the correct Excel formatting strings. - Added new function Select-Worksheet to make a named sheet active: Added -Activate switch to Add-Worksheet, to make current sheet active, Export-Excel and Add-PivotTable support -Activate and pass it to Add-Worksheet, and New-PivotTableDefinition allows it to be part of the Pivot TableDefinition. - Fixed a bug in Set-Format which caused -Hidden not to work +- Made the same changes to Add-Conditional format as set format so -switch:$false is processed, and 0 enums and values are processed correctly +- In Export-Excel, wraped calls to Add-CellValue in a try catch so a value which causes an issue doesn't crash the whole export but generates a warning instead (#410) . - Additional tests. # What's new to July 18 +- Changed parameter evaluation in Set-Format to support -bold:$false (and other switches so that if false is specified the attribute will be removed ), and to bug were enums with a value of zero, and other zero parameters were not set. - Moved chart creation into its own function (Add-Excel chart) within Export-Excel.ps1. Renamed New-Excelchart to New-ExcelChartDefinition to make it clearer that it is not making anything in the workbook (but for compatibility put an alias of New-ExcelChart in so existing code does not break). Found that -Header does nothing, so it isn't Add-Excel chart and there is a message that does nothing in New-ExcelChartDefinition . - Added -BarChart -ColumnChart -LineChart -PieChart parameters to Export-Excel for quick charts without giving a full chart definition. - Added parameters for managing chart Axes and legend