Apache的POI Excel单元格的格式不工作超越32748细胞的表 [英] Apache POI Excel cell formatting is not working beyond 32748 cell in a sheet

查看:283
本文介绍了Apache的POI Excel单元格的格式不工作超越32748细胞的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我需要生成一个特定时期的所有交易报告的要求,我需要申请相应单元格的格式。在这种情况下,单元格格未在表创建32748个单元格后特别是工作时间。这似乎是错误的API中,请提供一些投入,如果有人已经面临这个问题,并发现有任何修补程序。

I have a requirement where I need to generate a report for all transaction for a given period, and I need to apply the cell format accordingly. In this case cell formatting is not working especially for Date after creating 32748 cells in the sheet. This seems to be bug in the API, please provide some inputs if anybody already faced this issue and found any fix.

有关参考,在这里是样本code:

For reference, here is the sample code :

public class TestFormat {

public static void main(String args[]){
    try {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Excel Sheet");

    HSSFDataFormat format = wb.createDataFormat();


    for(int i = 1; i<65535;i++ ) {

            HSSFRow row = sheet.createRow(i);
            HSSFCell cell = row.createCell(1);
            HSSFCellStyle style = wb.createCellStyle();
            cell.setCellValue((Date) new Date());
            style.setDataFormat(format.getFormat("MM/dd/yyyy HH:mm:ss"));
            cell.setCellStyle(style);

    }
    FileOutputStream fileOut;

        fileOut = new FileOutputStream("c:\\test\\excelFile.xls");
         wb.write(fileOut);
            fileOut.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println("Data is saved in excel file.");
}

}

推荐答案

您正在创建您的单元格样式的的循环。不要!

You're creating your cell style inside the loop. Don't!

Excel有上的单元样式的数,它允许在文件格式的限制。你需要做的是将你的单元格样式的创建/设置你的循环之外,因此它只能创建一次,它应该被罚款

Excel has a limit on the number of cell styles that it allows in the file format. What you need to do is to move the creation/setup of your cell style outside of your loop, so it's only created once, and it should be fine

您code的核心部分会再看看这样的:

The core part of your code would then look something like:

HSSFDataFormat format = wb.createDataFormat();
HSSFCellStyle style = wb.createCellStyle();
cell.setCellValue((Date) new Date());
style.setDataFormat(format.getFormat("MM/dd/yyyy HH:mm:ss"));

for(int i = 1; i<65535;i++ ) {
        HSSFRow row = sheet.createRow(i);
        HSSFCell cell = row.createCell(1);
        cell.setCellStyle(style);
}

这篇关于Apache的POI Excel单元格的格式不工作超越32748细胞的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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