保存到桌面时,电子表格中的空白单元格不再空白

时间:2016-11-23 11:55:44

标签: java excel apache-poi

我有一个java应用程序,它使用POI将一些数据导出到电子表格中。问题是,有时(并非总是)有几行没有信息(它们是"空白")但是当我将XLS文档保存到我的桌面并打开它时,单元格被填充正确的信息。

我正在使用POI 3.7。

在这里,你有一个关于发生了什么的例子。

Excel

[编辑] - 我添加了一些代码:

这是将数据插入工作表的方法:

public void setTransactionDetailsData(HSSFSheet sheet, String[][] records){
    HSSFRow rowContent = null;
    HSSFCell cellContent = null;        
    String cell = "";

    Integer recordNumber = records.length;
    Integer columnNumber = records[0].length;

    Integer nextDataIndex = 0;          

    String styleText = "";      

    boolean customStyles = styles.size()>0;

    short alignment;

    CellStyle cellStyle = null;

    for(int i = 0; i<recordNumber;i++){         
        //New row           
        rowContent = sheet.createRow(lastRowCreated);           
        rowContent.setHeightInPoints((customDataCellHeight * sheet.getDefaultRowHeightInPoints()));                         

        for(int j = 0; j<columnNumber;j++){

            cellContent = null;
            cellContent = rowContent.createCell((nextDataIndex));

            cell = records[i][j];   

            if(customStyles){
                try{
                    styleText = styles.get(nextDataIndex);
                    alignment = getAlignment(styleText);
                }catch(IndexOutOfBoundsException e){
                    LOG.info("Error while obtaining style for position " +nextDataIndex+ ", max index is " +(styles.size()-1)+ ". Check the list of styles you send");
                    styleText = "";
                    alignment = 1;
                }
            }else{
                alignment = 1;
            }                   

            cellStyle = getCellStyle(i,Integer.valueOf(alignment),styleText);

            //Text
            if("".equals(styleText) || "value_left".equals(styleText) || "value".equalsIgnoreCase(styleText)){
                cellContent.setCellValue(cell);                     
            }else{
                if(isNumeric(cell)){                        
                    try{
                        cellContent.setCellValue(convertoToParseableNumber(cell));
                        cellContent.setCellType(0);
                    }catch(NumberFormatException e){
                        LOG.info("Error ocurred while parsing value " +cell+ " no number");
                        cellContent.setCellValue(cell);
                    }                   
                }else{                      
                    cellContent.setCellValue(cell);
                }
            }       
            cellContent.setCellStyle(cellStyle);
            nextDataIndex++;                                
        }           
        //Back to first column              
        nextDataIndex = 0;
        lastRowCreated++;               
    }       
    autosize(sheet);
}

提前谢谢。

0 个答案:

没有答案