使用OledbCommand格式化Excel日期字段 [英] Format excel date fields using OledbCommand

查看:201
本文介绍了使用OledbCommand格式化Excel日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向Excel编写值,如下所示

I''m writing values to excel as follows

OleDbConnection excelConnection = null;
excelConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + location + ";Mode=ReadWrite;Extended Properties=Excel 8.0;");
excelConnection.Open();

OleDbCommand cmd = new OleDbCommand(createCommand, excelConnection);
cmd.ExecuteNonQuery();



然后,我创建插入命令,并将记录插入到Excel工作表中.



Then I create Insert command and insert records to excel sheet.

insertCommand.ExecuteNonQuery();



但是,当我以"yyy.mm.dd"格式插入Date值时,它将使用当前区域语言格式将日期写入excel.

有没有办法使用OleDbCommand



But when I insert Date value with the format of "yyy.mm.dd" it writes date with the current regional language format to the excel.

Is there any way to set date format in excel using OleDbCommand

推荐答案

我认为没有解决方案.
Excel将日期的当前区域设置用于日期格式是一件好事. Excel文档可以来自使用不同区域设置的计算机,而不会出现任何问题.

确定要以特定的区域格式存储日期时,最好使用String数据类型.

Piet
I don''t think there is a solution for it.
It is a good thing that Excel uses the current regional settings for the date format. Excel documents can be from computers using different regional settings without any problem.

When you''re sure you want to store a date in a specific regional format best use a String data type for it.

Piet


Excel将数值字段(例如Number/Date等)转换为机器上设置的适当格式.在改变系统文化时,我们可以改变格式.不确定OleDB代码.
Excel converts value fields like Number/Date etc to the appropriate format set on the machine. On changing the system culture, we can change the format; not sure about OleDB code.


这篇关于使用OledbCommand格式化Excel日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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