[英]Excel bug handling dates in Text files using Microsoft.Office.Interop.Excel
So I upload Excel file then save it as Text file but I have problem with date format. 所以我上传Excel文件,然后将其另存为文本文件,但是日期格式有问题。
My excel the date format is dd/MM/yyyy but when I save it as Text File its format is MM/dd/yyyy 我的excel日期格式为dd / MM / yyyy,但是当我将其保存为文本文件时,其格式为MM / dd / yyyy
Imports Microsoft.Office.Interop
Dim FileName As String = "C:\myExcelData.txt"
Dim xl As New Excel.Application
Dim xlBook As Excel.Workbook = xl.Workbooks.Open("C:\myExcel.xlsx")
Dim xlSheet As Excel.Worksheet = xlBook.Sheets("Sheet1")
xl.DisplayAlerts = False
xlSheet.SaveAs(FileName, Excel.XlFileFormat.xlTextWindows)
xlBook.Close()
In myExcel.xlsx Date is 31/01/2014 在myExcel.xlsx中,日期为2014年1月31日
In myExcelData.txt Date is 1/31/2014 在myExcelData.txt中日期为1/31/2014
尝试添加最后一个参数Local:=True
:
xlSheet.SaveAs(Filename:=FileName, FileFormat:=Excel.XlFileFormat.xlTextWindows,Local:=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.