使用OledbCommand格式化Excel日期字段

编程入门 行业动态 更新时间:2024-10-08 22:54:08
本文介绍了使用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日期字段

本文发布于:2023-05-28 00:46:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/308211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   日期   OledbCommand   Excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!