Date conversion issue with Excel Interop and CSV file

不想你离开。 提交于 2019-12-11 03:43:48

问题


I have a CSV file which contains dates formatted as m/dd/yyyy as follows

1/06/2013,15,1,1/06/2013 0:15,1,6.44

When I open the file in Excel, the dates are correctly converted - 1/06/2013 has numeric value 41,426.00 and the MONTH() function returns 6.

When I use Microsoft.Office.Interop.Excel to open the same file using either the Open() or OpenText() method the date gets converted to 41,280.00 (6/01/2013).

Can you open a CSV file using Microsoft.Office.Interop.Excel so that it opens the same as if the user opened the file from the windows shell?

Regards Dave


回答1:


Found the answer myself buried in the bottom of this question - Excel VBA date formats/values change when file is opened programatically

workbook = workbooks.Open(filename, Local: true)

Open() has a Local property, when false it assumes the mdy order for ambiguous dates, when true it uses the local machine setting which in Australia is dmy



来源:https://stackoverflow.com/questions/25355790/date-conversion-issue-with-excel-interop-and-csv-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!