Excel错误使用Microsoft.Office.Interop.Excel处理文本文件中的日期 [英] Excel bug handling dates in Text files using Microsoft.Office.Interop.Excel

查看:201
本文介绍了Excel错误使用Microsoft.Office.Interop.Excel处理文本文件中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我上传Excel文件然后保存为文本文件,但是我的日期格式有问题。



我的excel日期格式是dd / MM / yyyy但是当我将其保存为文本文件时,其格式为MM / dd / yyyy





So I upload Excel file then save it as Text file but I have problem with date format.

My excel the date format is dd/MM/yyyy but when I save it as Text File its format is 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()





在myExcel.xlsx中日期是31/01 / 2014

在myExcelData.txt中日期是2014年1月31日



In myExcel.xlsx Date is 31/01/2014
In myExcelData.txt Date is 1/31/2014

推荐答案

简单:您在SaveAs调用中需要更多参数。具体来说,您需要将Local设置为True:

Simple: you need more parameters on your SaveAs call. Specifically, you need to set Local to True:
xlSheet.SaveAs(FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlTextWindows, Type.Missing, Type.Missing, Type.Missing, Type.Missing, _
    Type.Missing, Type.Missing, Type.Missing, True)



如果您将其保留为默认值,则Excel默认为美国日期格式。


If you leave it at the default, then Excel defaults to US date format.


这篇关于Excel错误使用Microsoft.Office.Interop.Excel处理文本文件中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆