C#Excel以日期格式读取字符? [英] C# Excel Reads Characters at Date Format ?
问题描述
我正在使用c#将表格导出到excel.
有一个类型为double的字段.此字段有十进制值.
但是当我将表格导出到excel时,它将值转换为日期格式.
对于值4,5,excel会显示该值,如 04.May.
我用."替换了包含,"的值.在发送到Excel之前.但这是行不通的.它再次显示日期格式的值.
如何预防这种情况?
感谢您的提前答复..
Hi,
I am exporting a table to the excel at c#.
There is a field which type is double. There are deciamal values at this field.
But when I export table to the excel, it converts the values to the date format.
For the value 4,5 , excel shows this value like 04.May.
I replaced values which contains "," with "." before sending to the excel. But that does not work. It shows the values at date format again.
How can I prevent this situation ?
Thanks for the replies in advance..
推荐答案
使用 ^ ]属性可更改单元格/范围格式.
例如:
Use Range.NumberFormat[^] property to change cell/range format.
For example:
Excel.Range oRange = objSheet.get_Range("A:A",system.type.missing);
oRange.NumberFormat = "General";
//or
oRange.NumberFormat = "# ##0.00";
注意:您需要先进行更改,然后再将数据保存到MS Excel工作表中.
Note: You need to change it before saving data into MS Excel sheet.
这篇关于C#Excel以日期格式读取字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!