错误与POI创建细胞 [英] Error creating cell with POI

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

问题描述

我从Java到XLS出口,我用POI库。

I do an export from Java to xls, i use POI library.

我createCell方式:

My createCell Method:

private Cell createCell(Row ligne, int col, String value, CellStyle style, HSSFWorkbook classeur) {        
    //org.apache.poi.hssf.usermodel.HSSFOptimiser.optimiseCellStyles(classeur);
    CellStyle styleCell = classeur.createCellStyle();
    styleCell.cloneStyleFrom(style);
    return createCell(ligne, col, value, styleCell);
}


protected Cell createCell(Row ligne, int col, String value, CellStyle style) {
    Cell cell = createCell(ligne, col, value);
    cell.setCellStyle(style);
    return cell;
}

我叫了对于这种方法,我有这个消息错误:

i call this methods in a For, i have this message error:

Echec DE L'出口:超出的单元格样式的最大数量。您
  可以在.xls的工作簿中定义多达4000个款式

Echec de l'export: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

如何重用我的手机,而无需重新创建每次迭代?

How to reuse my cell without having to recreate each iteration ?

THX

推荐答案

您不能重新使用相同的小区多行。而不是适用相同的价值观,以新建小区。但是你可以使用相同的样式到多个单元格。

You can not re-use the same cell for multiple rows. Instead of that apply same values to newly created cell. But you can use the same style to multiple cells.

CellStyle cellStyle = workSheet.getWorkbook().createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setWrapText(true);

for (int i=0; i <= records.size(); i++) {
// Create a new row
Row row = workSheet.createRow((short) i);
Cell cell001 = row.createCell(columnIndex);
cell001.setCellValue("some value");
cell001.setCellStyle(cellStyle);
}

这篇关于错误与POI创建细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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