mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 15:53:32 +00:00
Added timespan support to export Excel
This commit is contained in:
@@ -486,13 +486,19 @@
|
|||||||
#The write-verbose commands have been commented out below - even if verbose is silenced they cause a significiant performance impact and if it's on they will cause a flood of messages.
|
#The write-verbose commands have been commented out below - even if verbose is silenced they cause a significiant performance impact and if it's on they will cause a flood of messages.
|
||||||
Switch ($CellValue) {
|
Switch ($CellValue) {
|
||||||
{ $_ -is [DateTime]} {
|
{ $_ -is [DateTime]} {
|
||||||
# Save a date with an international valid format
|
# Save a date with one of Excel's built in formats format
|
||||||
$TargetCell.Value = $_
|
$TargetCell.Value = $_
|
||||||
$TargetCell.Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized.
|
$TargetCell.Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized.
|
||||||
#Write-Verbose "Cell '$Row`:$ColumnIndex' header '$Name' add value '$_' as date"
|
#Write-Verbose "Cell '$Row`:$ColumnIndex' header '$Name' add value '$_' as date"
|
||||||
break
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
|
{ $_ -is [TimeSpan]} {
|
||||||
|
#Save a timespans with a built in format for elapsed hours, minutes and seconds
|
||||||
|
$TargetCell.Value = $_
|
||||||
|
$TargetCell.Style.Numberformat.Format = '[h]:mm:ss'
|
||||||
|
break
|
||||||
|
}
|
||||||
{ $_ -is [System.ValueType]} {
|
{ $_ -is [System.ValueType]} {
|
||||||
# Save numerics, setting format if need be.
|
# Save numerics, setting format if need be.
|
||||||
$TargetCell.Value = $_
|
$TargetCell.Value = $_
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ Install-Module ImportExcel -scope CurrentUser
|
|||||||
Install-Module ImportExcel
|
Install-Module ImportExcel
|
||||||
```
|
```
|
||||||
# New to Aug 14th
|
# New to Aug 14th
|
||||||
- In Export-Excel improved the catch-all handler for insering values to cope better with nested objects and reduce the number of parse operations
|
- Added support for timespans in Export excel ; set as elapsed hours, mins, secs [h]:mm:sss
|
||||||
- Added -Calculate switch to Export-Excel and Close-Excel Package; EPPlus needs formulas to OMIT the leading = sign so where formula is set it now strips a leading =
|
- 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
|
||||||
|
- Added -Calculate switch to Export-Excel and Close-Excel Package; EPPlus needs formulas to OMIT the leading = sign so where formula is set it now strips a leading = sign
|
||||||
- Added -PivotTotals parameter where there was already -NoTotalsInPivot new one allows None, Both, Rows, Columns. (#415)
|
- Added -PivotTotals parameter where there was already -NoTotalsInPivot new one allows None, Both, Rows, Columns. (#415)
|
||||||
- When appending Export-Excel only extended tables and ranges if they were explicitly specified. It now does it automatically.
|
- When appending Export-Excel only extended tables and ranges if they were explicitly specified. It now does it automatically.
|
||||||
- Compare and Merge worksheet originally had a problem with > 26 columns, I fixed merge turns out I hadn't fixed compare ... I have now
|
- Compare and Merge worksheet originally had a problem with > 26 columns, I fixed merge turns out I hadn't fixed compare ... I have now
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ Describe ExportExcel {
|
|||||||
Link3 = "xl://internal/sheet1!A1"
|
Link3 = "xl://internal/sheet1!A1"
|
||||||
Link4 = "xl://internal/sheet1!C5"
|
Link4 = "xl://internal/sheet1!C5"
|
||||||
Process = (Get-Process -Id $PID)
|
Process = (Get-Process -Id $PID)
|
||||||
|
TimeSpan = [datetime]::Now.Subtract([datetime]::Today)
|
||||||
} | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -Path $path -Calculate -WarningVariable $warnVar
|
} | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -Path $path -Calculate -WarningVariable $warnVar
|
||||||
it "Created a new file " {
|
it "Created a new file " {
|
||||||
Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true
|
Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true
|
||||||
@@ -189,7 +190,7 @@ Describe ExportExcel {
|
|||||||
$ws = $Excel.Workbook.Worksheets[1]
|
$ws = $Excel.Workbook.Worksheets[1]
|
||||||
it "Created the worksheet with the expected name, number of rows and number of columns " {
|
it "Created the worksheet with the expected name, number of rows and number of columns " {
|
||||||
$ws.Name | Should be "sheet1"
|
$ws.Name | Should be "sheet1"
|
||||||
$ws.Dimension.Columns | Should be 25
|
$ws.Dimension.Columns | Should be 26
|
||||||
$ws.Dimension.Rows | Should be 2
|
$ws.Dimension.Rows | Should be 2
|
||||||
}
|
}
|
||||||
it "Set a date in Cell A2 " {
|
it "Set a date in Cell A2 " {
|
||||||
@@ -251,6 +252,11 @@ Describe ExportExcel {
|
|||||||
it "Converted a nested object to a string (Y2) " {
|
it "Converted a nested object to a string (Y2) " {
|
||||||
$ws.Cells[2, 25].Value | should match '^System\.Diagnostics\.Process\s+\(.*\)$'
|
$ws.Cells[2, 25].Value | should match '^System\.Diagnostics\.Process\s+\(.*\)$'
|
||||||
}
|
}
|
||||||
|
it "Processed a timespan object (Z2) " {
|
||||||
|
$ws.cells[2, 26].Value.ToOADate() | should beGreaterThan 0
|
||||||
|
$ws.cells[2, 26].Value.ToOADate() | should beLessThan 1
|
||||||
|
$ws.cells[2, 26].Style.Numberformat.Format | should be '[h]:mm:ss'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "# # Setting cells for different data types with -noHeader" {
|
Context "# # Setting cells for different data types with -noHeader" {
|
||||||
|
|||||||
Reference in New Issue
Block a user