现在有个需求就是通过解析一个Excel模板来生成Excel报表,取写数据不谈,但得保证的一个是生成的这个Excel报表与模板的样式肯定是一样的,这样就遇到个问题,比如报表的标题,通常都是几个单元格合并起来的,通过poi读取的时候,第一行只有第一列有数据,其他都为空(Excel本身就是这样的吧),那这样我如何取到模板的合并单元格的样式再写入另外的excel中呢?
3条回答 默认 最新
- iteye_8576 2011-05-12 17:16关注
以前的一个例子,你参考下:
[code="java"] FileOutputStream fileOut = null;
try {
String rootPath = "C:/TimeReport.xls";
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(rootPath));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
//数据操作。。。// Write the output to a file fileOut = new FileOutputStream("C://TimeReport_1011.xls"); wb.write(fileOut); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } finally { if (fileOut != null) { fileOut.close(); } }[/code]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报