From 9f8183a7b166c974aa6e71d9f87ae44906cb00e0 Mon Sep 17 00:00:00 2001 From: Doug Finke Date: Mon, 27 Apr 2015 10:07:28 -0400 Subject: [PATCH] Format datetime propeties --- ImportExcel.psm1 | 12 +++++++++--- README.md | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 0c14c02..80c0c02 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -176,15 +176,20 @@ function Export-Excel { $ColumnIndex = 1 foreach ($Name in $Header) { - $ws.Cells[$Row, $ColumnIndex].Value = $TargetData.$Name + + $targetCell = $ws.Cells[$Row, $ColumnIndex] + $targetCell.Value = $TargetData.$Name + + switch ($TargetData.$Name) { + {$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"} + } + $ColumnIndex += 1 } } End { - if($AutoSize) {$ws.Cells.AutoFitColumns()} - if($IncludePivotTable) { $pivotTableName = $WorkSheetname + "PivotTable" $wsPivot = $pkg.Workbook.Worksheets.Add($pivotTableName) @@ -223,6 +228,7 @@ function Export-Excel { } } + if($AutoSize) { $ws.Cells.AutoFitColumns() } if($Password) { $ws.Protection.SetPassword($Password) } $pkg.Save() diff --git a/README.md b/README.md index 90e7016..4bf9ca5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ Know Issues What's new - +#### 4/27/2015 +* datetime properties were displaying as ints, now are formatted + #### 4/25/2015 * Now you can create multiple Pivot tables in one pass * Thanks to [pscookiemonster](https://twitter.com/pscookiemonster), he submitted a repro case to the EPPlus CodePlex project and got it fixed