mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 21:33:16 +00:00
Send-SQLDataToExcel applies formatting to date fields.
This commit is contained in:
@@ -269,6 +269,13 @@
|
|||||||
$excelPackage = Export-Excel -Path $Path -WorkSheetname $WorkSheetname -PassThru
|
$excelPackage = Export-Excel -Path $Path -WorkSheetname $WorkSheetname -PassThru
|
||||||
$excelPackage.Workbook.Worksheets[$WorkSheetname].Cells[$r,$StartColumn].LoadFromDataTable($dataTable, $printHeaders ) | Out-Null
|
$excelPackage.Workbook.Worksheets[$WorkSheetname].Cells[$r,$StartColumn].LoadFromDataTable($dataTable, $printHeaders ) | Out-Null
|
||||||
|
|
||||||
|
#Apply date format
|
||||||
|
for ($c=0 ; $c -lt $DataTable.Columns.Count ; $c++) {
|
||||||
|
if ($DataTable.Columns[$c].DataType -eq [datetime]) {
|
||||||
|
Set-ExcelColumn -Worksheet $excelPackage.Workbook.Worksheets[$WorkSheetname] -Column ($c +1) -NumberFormat 'Date-Time'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Call export-excel with any parameters which don't relate to the SQL query
|
#Call export-excel with any parameters which don't relate to the SQL query
|
||||||
"Connection", "Database" , "Session", "MsSQLserver", "Destination" , "SQL" , "DataTable", "Path" | ForEach-Object {$null = $PSBoundParameters.Remove($_) }
|
"Connection", "Database" , "Session", "MsSQLserver", "Destination" , "SQL" , "DataTable", "Path" | ForEach-Object {$null = $PSBoundParameters.Remove($_) }
|
||||||
Export-Excel -ExcelPackage $excelPackage @PSBoundParameters
|
Export-Excel -ExcelPackage $excelPackage @PSBoundParameters
|
||||||
|
|||||||
Reference in New Issue
Block a user