乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 使用poi在java中将数据库中的<em>日期</em>格式的字段生成exce...-java导

使用poi在java中将数据库中的<em>日期</em>格式的字段生成exce...-java导

作者:乔山办公网日期:

返回目录:excel表格制作


提问虽然已经过去很长时间了,但是这个问题很普遍。我来补充一下,希望大copy家能看到吧、、
给导出时间格式的字段增加zhidao一个css样式:mso-number-format:'\@' 即可('\@'是格式化为文本方式)。
例:<td style="mso-number-format:'\@';"><%=myDateTime %></td>

问题描述不清楚e799bee5baa6e997aee7ad94e58685e5aeb9361,new File(文件名);这样不可以吗?

你应该是想把这个字段写入excel文件中的一列吧?

Cell cell = row.createCell(1);  
     cell.setCellValue(new Date());  
     CreationHelper createHelper = wb.getCreationHelper();  
     CellStyle cellStyle = wb.createCellStyle();  
     cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-MM-dd"));  
     cell.setCellStyle(cellStyle);

参考地址:

http://blog.csdn.net/yy_done/article/details/7090018


java读取excel时间格式出现数字的处理方法:
Excel存储日期、时间均以数值类型进行存储,读取时POI先判断是是否是数值类型,再进行判断转化
1、数值格式(CELL_TYPE_NUMERIC):
1.纯数值格式:getNumericCellValue() 直接获取数据
2.日期格式:处理yyyy-MM-dd, d/m/yyyy h:mm, HH:mm 等不含文字的日期格式
1).判断是否是日期格式:HSSFDateUtil.isCellDateFormatted(cell)
2).判断是日期或者时间
cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm")
OR: cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd")
3.自定义e799bee5baa6e79fa5e98193e78988e69d83332日期格式:处理yyyy年m月d日,h时mm分,yyyy年m月等含文字的日期格式
判断cell.getCellStyle().getDataFormat()值,解析数值格式
yyyy年m月d日----->31
m月d日---->58
h时mm分--->32
举例说明:
private String parseExcel(Cell cell) {
String result = new String();

Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网