Fixed small bug with Append and simple data types

This commit is contained in:
jhoneill
2018-08-15 23:44:00 +01:00
parent bc65699068
commit d770646dc7
3 changed files with 5 additions and 4 deletions

View File

@@ -676,7 +676,7 @@
if ($firstTimeThru) { if ($firstTimeThru) {
$firstTimeThru = $false $firstTimeThru = $false
$isDataTypeValueType = $TargetData.GetType().name -match 'string|timespan|datetime|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort' $isDataTypeValueType = $TargetData.GetType().name -match 'string|timespan|datetime|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort'
if ($isDataTypeValueType) {$row -= 1} #row incremented before adding values, so it is set to the number of rows inserted at the end if ($isDataTypeValueType -and -not $Append) {$row -= 1} #row incremented before adding values, so it is set to the number of rows inserted at the end
Write-Debug "DataTypeName is '$($TargetData.GetType().name)' isDataTypeValueType '$isDataTypeValueType'" Write-Debug "DataTypeName is '$($TargetData.GetType().name)' isDataTypeValueType '$isDataTypeValueType'"
} }

View File

@@ -52,6 +52,7 @@ Install-Module ImportExcel -scope CurrentUser
Install-Module ImportExcel Install-Module ImportExcel
``` ```
# New to Aug 15h # New to Aug 15h
- Fixed a bug with -Append in Export-Excel which caused it to overwrite the last row if the new data was a simple type.
- NumberFormat in Export-Excel now sets the default for on a new / blank sheet; but [still] sets individual cells when adding to a sheet - NumberFormat in Export-Excel now sets the default for on a new / blank sheet; but [still] sets individual cells when adding to a sheet
- Added support for timespans in Export excel ; set as elapsed hours, mins, secs [h]:mm:sss - Added support for timespans in Export excel ; set as elapsed hours, mins, secs [h]:mm:sss
- In Export-Excel improved the catch-all handler for insering values to cope better with nested objects (#419) and reduce the number of parse operations - In Export-Excel improved the catch-all handler for insering values to cope better with nested objects (#419) and reduce the number of parse operations

View File

@@ -149,17 +149,17 @@ Describe ExportExcel {
Remove-Item -Path $path -ErrorAction SilentlyContinue Remove-Item -Path $path -ErrorAction SilentlyContinue
1..10 | Export-Excel -Path $path -Numberformat 'Number' 1..10 | Export-Excel -Path $path -Numberformat 'Number'
1..10 | Export-Excel -Path $path -Numberformat 'Percentage' -Append 1..10 | Export-Excel -Path $path -Numberformat 'Percentage' -Append
21..30 | Export-Excel -Path $path -Numberformat 'Currency' -StartColumn 3 21..30 | Export-Excel -Path $path -Numberformat 'Currency' -StartColumn 3
$excel = Open-ExcelPackage -Path $path $excel = Open-ExcelPackage -Path $path
$ws = $excel.Workbook.Worksheets[1] $ws = $excel.Workbook.Worksheets[1]
} }
it "Set the worksheet default number format correctly " { it "Set the worksheet default number format correctly " {
$ws.Cells.Style.Numberformat.Format | Should be "0.00" $ws.Cells.Style.Numberformat.Format | Should be "0.00"
} }
it "Set number formats on specific blocks of cells w " { it "Set number formats on specific blocks of cells " {
$ws.Cells["A2" ].Style.Numberformat.Format | Should be "0.00" $ws.Cells["A2" ].Style.Numberformat.Format | Should be "0.00"
$ws.Cells["c19"].Style.Numberformat.Format | Should be "0.00" $ws.Cells["c19"].Style.Numberformat.Format | Should be "0.00"
$ws.Cells["A19"].Style.Numberformat.Format | Should be "0.00%" $ws.Cells["A20"].Style.Numberformat.Format | Should be "0.00%"
$ws.Cells["C6" ].Style.Numberformat.Format | Should be (Expand-NumberFormat "currency") $ws.Cells["C6" ].Style.Numberformat.Format | Should be (Expand-NumberFormat "currency")
} }
} }