获取使用POI HSSF错误 [英] Getting error using POI HSSF

查看:165
本文介绍了获取使用POI HSSF错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开一个Excel工作表与MS Office的时候得到一个错误2003这Excel表,使用HSSFWorkbook,实施的usermodel范围内创建org.apache.poi.hssf.usermodel

I'm getting an error when trying to open an Excel sheet with MS office 2003. This Excel sheet is created using HSSFWorkbook, implementing the usermodel scope org.apache.poi.hssf.usermodel

在Microsoft Excel 2003:太多不同的单元格格式。在Microsoft Excel 2007/2010,文件可能产生以下错误信息:Excel中在文件中找到无法读取内容。这是关于细胞格式,请参考下面的页:

In Microsoft Excel 2003: "Too many different cell formats". In Microsoft Excel 2007/2010, files may produce the following error message: "Excel found unreadable content in the file". This is regarding cell formats, please refer to the below page:

http://support.microsoft.com/kb/213904

那么,如何可以修复code这个问题?

So how can I fix this issue in code?

推荐答案

Excel中对不同细胞的风格,你可以有数量限制,它是出奇的低。人们刚开始使用POI工作的一个共同问题是,他们跳过了一点关于单元格样式是工作簿宽,而是他们创造每单元一个单元格样式。这很快促使他们在Excel中的限制...

Excel has a limit on the number of different cells styles you can have, and it's surprisingly low. A common problem for people new to working with POI is that they skip over the bit about cell styles being workbook wide, and instead they create one cell style per cell. This quickly pushes them over the limit in Excel...

您code可能pviously $ P $看过类似

Where you code might previously have looked something like

Sheet s = wb.createSheet();
for (int rn=0; rn<=10; rn++) {
    Row r = s.createRow(rn);
    for (int cn=0; cn<=4; cn++) {
        Cell c = r.createCell(c);
        c.setCellValue( getMyCellValue(rn,cn) );

        CellStyle cs = wb.createCellStyle();
        cs.setBold(true);
        if (cn == 2) { 
            cs.setDataFormat( DataFormat.getFormat(yyyy/mm/dd) );
        }
        c.setCellStyle(cs);
    }
}

您需要,而不是拉你单元格样式创作出来开始,像

You instead need to pull your cell style creation out to the start, something like

CellStyle bold = wb.createCellStyle();
bold.setBold(true);

CellStyle boldDate = wb.createCellStyle();
boldDate.setBold(true);
boldDate.setDataFormat( DataFormat.getFormat(yyyy/mm/dd) );

Sheet s = wb.createSheet();
for (int rn=0; rn<=10; rn++) {
    Row r = s.createRow(rn);
    for (int cn=0; cn<=4; cn++) {
        Cell c = r.createCell(c);
        c.setCellValue( getMyCellValue(rn,cn) );

        CellStyle cs = bold;
        if (cn == 2) { 
            cs = boldDate;
        }
        c.setCellStyle(cs);
    }
}

这篇关于获取使用POI HSSF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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