Open Xml 写入日期类型
2012-08-29 10:54
176 查看
效果图:
关键代码:
类型判断
Style:
其中,fonts,fills和borders需要写入,这个很关键,并且cellFormat1也需要写入。
关键代码:
类型判断
if (rIndex == 1) { cell.CellValue = new CellValue(item.ToString()); } else if (rIndex == 2) { cell.CellValue = new CellValue(((DateTime)item).ToOADate().ToString()); cell.StyleIndex = 1; } else { int index = InsertSharedStringItem(item.ToString(), m_SharedStringTablePart); cell.CellValue = new CellValue(index.ToString()); cell.DataType = new EnumValue<CellValues>(CellValues.SharedString); }
Style:
static Stylesheet CreateStylesheet() { Stylesheet stylesheet1 = new Stylesheet(); Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true }; Font font1 = new Font(); fonts1.Append(font1); Fills fills1 = new Fills() { Count = (UInt32Value)1U }; Fill fill1 = new Fill(); fills1.Append(fill1); Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); borders1.Append(border1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)2U }; CellFormat cellFormat1 = new CellFormat() ; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)22U, ApplyNumberFormat = true }; cellFormats1.Append(cellFormat1); cellFormats1.Append(cellFormat2); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellFormats1); return stylesheet1; }
其中,fonts,fills和borders需要写入,这个很关键,并且cellFormat1也需要写入。
相关文章推荐
- 如何将页面日期的String类型转换成SQL日期类型并写入数据库?
- SpringMVC 在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型
- 如何在java类中向oracle数据库写入Date类型的日期
- 关于MysQL中写入日期类型数据失败的问题
- java存取mysql中日期类型
- 关于springmvc怎么自动把前台string类型日期字段转换成date类型
- CUBRID学习笔记 11 数据类型之日期
- JSTL格式化Date类型的日期
- log4net 将日志按不同类型写入多个文件
- 2015-04-09-时间序列(1)-日期和时间数据类型及工具+时间序列基础+日期的范围、频率以及移动
- java中日期时间格式与毫秒数的转换如何将指定时间转换为Date类型
- Mysql日期类型大小比较---拉取给定时间段的记录
- 根据日期计算bigdecimal类型的数之后的日期
- SQLite日期类型
- mysql-数据类型之整型、浮点型、日期时间型、字符型
- datagrid 类型列里怎么设置日期格式{yyyy-mm-dd}
- springmvc-日期类型初始绑定报错
- 数据库开发篇(一)——转换日期类型
- 【转】oracle 数值型函数,字符型函数,日期函数,转换函数,to_char,自动类型转换,日期类型转换