我希望使用MSExcel中的DD-MMM-YYYY格式进行编码 [英] i want the DD-MMM-YYYY format in MSExcel using coding

查看:111
本文介绍了我希望使用MSExcel中的DD-MMM-YYYY格式进行编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下;



xlsheet.Cells [1,1] =打印日期+ DateTime.Now;



当我使用上面的代码时,我的输出如下;



打印日期3/5/2013 5:37:37 PM。



我在excel中检索的上述输出。



但是我想在excel中输出如下;



印刷日期5 / Mar / 2013.



以上输出,我可以做些什么改变得到我的上述输出。





问候,

Narasiman P.

My code as follows;

xlsheet.Cells[1, 1] = "printed date" + DateTime.Now;

when i use the above code, my output as follows;

printed date 3/5/2013 5:37:37 PM.

the above output i retrieve in excel.

But i want the output as follows in excel;

Printed date 5/Mar/2013.

for the above output,what change i can do to get my above output.


Regards,
Narasiman P.

推荐答案

请看这里: http://www.csharp-examples.net/ string-format-datetime / [ ^ ]

顺便说一下: dd 会给05而不是5,而且你在标题中指定的格式与样本不符 - 所以你的问题是不同的nt。

Look here: http://www.csharp-examples.net/string-format-datetime/[^]
Btw: dd will give 05, not 5, and your format specified in the title does not match the sample - so your question is discrepant.
String.Format("{0:dd-MMM-yyyy}", DateTime.Now)




String.Format(@"{0:dd\/MMM\/yyyy}", DateTime.Now)



注意,您可能还需要指定文化信息...


Note, that you might need to specify culture info too...


也试试这段代码

also try this code
xlsheet.Cells[1, 1] = "printed date" + DateTime.Now.ToString("DD/MMM/YYYY");




将日期时间格式化为特定字符串将不会在excel文件中按预期显示,因为Excel单元格格式会覆盖它。



你需要格式化单元格而不是日期时间。



Hi,
Formatting the DateTime to specific string will not display as expected in the excel file, because the Excel cell format will override it.

you need to format the cell not the date time.

Microsoft.Office.Interop.Excel.Range range = worksheet.Cells[1,1] as Range;
range.NumberFormat = "dd/MMM/yyyy";
range.Value2 = DateTime.Now;





问候

Jegan



Regards
Jegan


这篇关于我希望使用MSExcel中的DD-MMM-YYYY格式进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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