【问题标题】:Reading date time form an excel file using Powershell使用Powershell从excel文件中读取日期时间
【发布时间】:2018-12-09 12:56:20
【问题描述】:

我正在使用以下代码使用 powershell 读取 excel 文件。 excel 文件中有几个日期列,格式为 yyyy-mm-dd 格式。当 PowerShell 读取日期列时,它会呈现一个数字。如何将此数字更改为真实的日期时间。

$oldci = [System.Threading.Thread]::CurrentThread.CurrentCulture
$newci = [System.Globalization.CultureInfo]"en-US"

$path="C:\project1\Spreadsheet2.xlsx"
$objExcel = New-Object -ComObject "Excel.Application"
$objExcel.visible = $false
[system.threading.Thread]::CurrentThread.CurrentCulture = $newci
$objWorkbook =$objExcel.Workbooks.Open($path)  
$worksheet = $objWorkbook.sheets.item("Temp")

Write-Host $worksheet.cells.item(3, 3).value2 //here is a digit.

【问题讨论】:

标签: excel date powershell


【解决方案1】:

我会将其发布到评论部分,但我不能因为声誉限制而受到限制。 在这里查看这篇文章:Powershell reading Excel date as 5 digit number

【讨论】:

    【解决方案2】:

    text 属性将正确返回日期而不是 value2。

    写入主机 $worksheet.cells.item(3, 3).text

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多