读书人

POI3.8组件研究(2)-基于User API (H

发布时间: 2012-06-30 17:20:12 作者: rapoo

POI3.8组件研究(二)---基于User API (HSSF and XSSF)解析Excel2003和2007文件

??????????????? 在解析生成excel2003和2007时候,由于生成的对象不同可能需要创建workbook的不同对象。

判断代码如下:

?针对YY-MM-dd时间格式的转换时间格式源代码:

?

?

注意:在读取excel时候需要解读HH:MM或者HH:MM:SS或者YYYY/MM/DD的转换,必须确定时间的格式,才可以转换。

?

?

?

?

?

?针对2003和2007的excel中向单元格中写入内容是:

???????? 可能有点不同,需要使用CreationHelper生成数据:

??????????? Calling the empty HSSFWorkbook remains as the way to create a new, empty Workbook object. To open an existing Worbook, you should now call WorkbookFactory.create(inp).

For all other cases when you would have called a Usermodel constructor, such as 'new HSSFRichTextString()' or 'new HSSFDataFormat', you should instead use a CreationHelper. There's a method on the Workbook to get a CreationHelper, and the CreationHelper will then handle constructing new objects for you.

?

例如:

Cell cell = row.createCell(index);cell.setCellValue(createHelper.createRichTextString(headerTitle));

?

读书人网 >开源软件

热点推荐