如何将常规值转换为日期格式

时间:2016-12-15 14:45:41

标签: excel powershell csv

如何使用PowerShell更改excel中列的格式?

我有一个将CSV转换为.xlsx的脚本,它运行正常, 但我有一个日期列(“常规”格式单元格),但我需要“日期”格式单元格。

我尝试了一切,例如。 [datetime]::ParseExact, $date = Get-Date -format "yyyyMMdd"等等。

我可能会在这里添加一些内容:

$convertedDate = Get-Date ($commitime+"-"+$commitDate+"-"+$commitYearToGet)

编辑:

$FileNameCSV = "$env:WORKSPACE/masterdata.csv"
$FileNameExcel = "\\masterdata$(get-date -f yyyy-MM-dd).xlsx"


$DLLPath = "D:\EPPlus.dll"
[Reflection.Assembly]::LoadFile($DLLPath) | Out-Null


$Format = New-object -TypeName OfficeOpenXml.ExcelTextFormat
$Format.Delimiter = ","

$Format.TextQualifier = '"'
$Format.Encoding = [System.Text.Encoding]::UTF8
$Format.SkipLinesBeginning = '0'
$Format.SkipLinesEnd = '1'

$TableStyle = [OfficeOpenXml.Table.TableStyles]::Medium1

$ExcelPackage = New-Object OfficeOpenXml.ExcelPackage 
$Worksheet = $ExcelPackage.Workbook.Worksheets.Add("CM")

$null=$Worksheet.Cells.LoadFromText((Get-Item    $FileNameCSV),$Format,$TableStyle,$true) 

#$null=$Worksheet.Cells.LoadFromText($file,$format) 


$Worksheet.Cells[$Worksheet.Dimension.Address+1].AutoFitColumns()

$ExcelPackage.SaveAs($FileNameExcel)

0 个答案:

没有答案