使用Open xml在单元格中写入日期值 [英] Writing Date Value in a cell using Open xml

查看:85
本文介绍了使用Open xml在单元格中写入日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Open XML使用日期类型在单元格中写一个日期. 你能告诉我我该怎么做吗?

I need to write a date in cell using date type using Open XML. Can you please tell me how can I do this?

推荐答案

我得到了答案并与大家分享...

I got the answer and sharing with you all...

只需添加单元格即可.

 Cell cell =new Cell(){ cellReference=A1 }; //Or other necessary details
 cell.cellValue = new CellValue(DateTime.Now.ToOADate().ToString()); 

 cell.StyleIndex=5;

我在这里用过

cell.StyleIndex=5;

,这是Excel中日期的默认样式索引.因此无需添加所有外部样式表

which is By Default Style Index of date in Excel. So no need to add all the external styylesheets

享受:)

这篇关于使用Open xml在单元格中写入日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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