增加java中HSSFCell的最大长度

增加java中HSSFCell的最大长度,java,poi-hssf,Java,Poi Hssf,实际上,我试图使用java在HSSFCell中存储一些数据,但我得到了如下错误 java.lang.IllegalArgumentException: The maximum length of cell contents (text) i s 32,767 characters at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(HSSFCell.java:559 ) at org.apache.poi.

实际上,我试图使用java在HSSFCell中存储一些数据,但我得到了如下错误

java.lang.IllegalArgumentException: The maximum length of cell contents (text) i
s 32,767 characters
        at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(HSSFCell.java:559
)
        at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(HSSFCell.java:533
)
        at application.ExtractUI.datatoexcel(ExtractUI.java:272)
        at application.ExtractUI$3.getData(ExtractUI.java:208)
        at application.ExtractUI$3.handle(ExtractUI.java:198)
        at application.ExtractUI$3.handle(ExtractUI.java:1)
有人能给我推荐一种增加单元格长度的方法吗?即超过32767个字符

我使用了下面的代码,我得到了上面的错误

 public void datatoexcel(ResultSet rs) {
        try {
            int iter = 0;
            ResultSetMetaData rmeta = rs.getMetaData();
            int col = rmeta.getColumnCount();
            HSSFWorkbook workbook = new HSSFWorkbook();

            Date date = new Date();

            SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy HHmmss");
            String pa = pth + "\\" + sdf.format(date) + ".xlsx";
            System.out.println(pa);
            FileOutputStream out = new FileOutputStream(new File(pa));
            HSSFSheet sheet = workbook.createSheet();
            HSSFRow myRow = null;
            HSSFCell myCell = null;
            // Font style for headers
            HSSFFont boldFont = workbook.createFont();
            boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            boldFont.setColor(HSSFFont.COLOR_RED);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setFont(boldFont);
            while (rs.next()) {
                // limit the data to 1000 anad create a new sheet
                if (iter == 1000) {
                    sheet = workbook.createSheet();
                    iter = 0;
                }
                // Adding header to the first row
                if (iter == 0) {
                    myRow = sheet.createRow(iter);
                    for (int k = 1, j = 0; k <= col && j < col; k++) {
                        myCell = myRow.createCell( j);

                        myCell.setCellValue(rmeta.getColumnName(k));
                        // set style to font
                        myCell.setCellStyle(cellStyle);

                        j++;
                    }
                    iter++;
                }
                // Adding data from 2nd Row
                myRow = sheet.createRow(iter);
                for (int k = 1, j = 0; k <= col && j < col; k++) {

                    myRow.createCell( j).setCellValue(
                            rs.getString(rmeta.getColumnName(k)));
                    j++;
                }
                iter++;
            }

            workbook.write(out);

            out.close();


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
public void datatoexcel(结果集rs){
试一试{
int-iter=0;
ResultSetMetaData rmeta=rs.getMetaData();
int col=rmeta.getColumnCount();
HSSFWorkbook=新的HSSFWorkbook();
日期=新日期();
SimpleDataFormat sdf=新的SimpleDataFormat(“DDMMYYY HHmmss”);
字符串pa=pth+“\\”+sdf.format(date)+“.xlsx”;
系统输出打印LN(pa);
FileOutputStream out=新的FileOutputStream(新文件(pa));
HSSFSheet sheet=workbook.createSheet();
HSSFRow myRow=null;
HSSFCell-myCell=null;
//标题的字体样式
hssfont boldFont=工作簿.createFont();
boldFont.setBoldweight(hssfont.BOLDWEIGHT\u BOLD);
boldFont.setColor(hssfont.COLOR_-RED);
HSSFCellStyle cellStyle=工作簿.createCellStyle();
cellStyle.setFont(粗体);
while(rs.next()){
//将数据限制为1000,然后创建新工作表
如果(iter==1000){
sheet=workbook.createSheet();
iter=0;
}
//将标题添加到第一行
如果(iter==0){
myRow=sheet.createRow(iter);

对于(int k=1,j=0;k您唯一的选择是切换文件格式。32767个字符的
.xls
.xlsx
文件格式都有硬限制。Apache POI只是强制执行文件格式+Excel限制。您可以在Microsoft文档中看到这些限制的详细信息,也可以在

如果您真的需要这么长的文本,您需要切换到另一种文件格式,如CSV
private void writeIsueDataForEachRow(问题、行、单元格样式、,
private void writeIssueDataForEachRow(Issue issue, Row row, CellStyle style,
                                          List<ColumnIndex> customFieldDefinitions) {
    Cell cell = row.createCell(0);
    cell.setCellValue(issue.getId()); // 編號
    cell.setCellStyle(style);

    cell = row.createCell(1);
    cell.setCellValue(issue.getSubject()); // 主旨
    cell.setCellStyle(style);

    // substring 的原因是要避開 The maximum length of cell contents (text) is 32,767 characters
    cell = row.createCell(2);
    cell.setCellValue(StringUtils.substring(issue.getDescription(), 0, 32767)); // 敘述
    cell.setCellStyle(style);

}
列表(定义){ Cell Cell=row.createCell(0); cell.setCellValue(issue.getId());//編號 cell.setCellStyle(style); cell=row.createCell(1); cell.setCellValue(issue.getSubject());//主旨 cell.setCellStyle(style); //子串的原因是要避開 单元格内容(文本)的最大长度为32767个字符 cell=row.createCell(2); cell.setCellValue(StringUtils.substring(issue.getDescription(),032767));//敘述 cell.setCellStyle(style); }
您可以添加您的代码吗?