java - Apache POI-无法读取单元格的内容

标签 java apache-poi

我正在尝试读取包含大字符串的单元格的内容。但读取的单元格将其显示为空白。包含大字符串的单元格未被提取,而其他单元格数据被提取。

try{
        FileInputStream inputStream = new FileInputStream(new File(strFileName));
        Workbook workbook = new XSSFWorkbook(inputStream);
        Sheet sheetName=null;
        sheetName = workbook.getSheet(strSheetName);
        Iterator<Row> iterator = sheetName.iterator();

        while (iterator.hasNext()) {
            if(blnHasHeader){
                //  Data starts from next row
                iterator.next();
                blnHasHeader=false;
                continue;
            }
            ArrayList<String> arrRow = new ArrayList<String>();
            Row nextRow = iterator.next();
            Iterator<Cell> cellIterator = nextRow.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_STRING:
                    arrRow.add(String.valueOf(cell.getStringCellValue()));
                    System.out.println(String.valueOf(cell.getStringCellValue()));
                    break;
                case Cell.CELL_TYPE_BOOLEAN:
                    arrRow.add(String.valueOf(cell.getBooleanCellValue()));
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    arrRow.add(String.valueOf(cell.getNumericCellValue()));
                    System.out.println(String.valueOf(cell.getNumericCellValue()));
                    break;
                case Cell.CELL_TYPE_BLANK:
                    arrRow.add("");
                    System.out.println("Blank");
                    break;
                }

            }
            arrReturnArrayList.add(arrRow); 
        }
        workbook.close();
        inputStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

读取的字符串长度有限制吗?

最佳答案

public static final SpreadsheetVersion EXCEL2007 Excel2007

The total number of available rows is 1M (2^20)

The total number of available columns is 16K (2^14)

The maximum number of arguments to a function is 255

Number of conditional format conditions on a cell is unlimited (actually limited by available memory in Excel)

Number of cell styles is 64000

Length of text cell contents is 32767

取自这里:https://poi.apache.org/apidocs/org/apache/poi/ss/SpreadsheetVersion.html

我希望这能回答您的问题。您应该查看单元格包含多少个字符

关于java - Apache POI-无法读取单元格的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42385135/

相关文章:

java - 使用Servlet登录后重定向到index.jsp

java - 如何在 Java Web 应用程序中显示 jFrame 表单 (NetBeans)

java - 文件之间的克隆表

java - 读取多个csv文件并将其放入Excel中的不同工作表中不起作用

excel - Apache POI 和颜色

java - Spring 启动: ReentrantLock

java - 如何使用 Intent 而不是 putExtra 将类文件变量获取到另一个 Activity 并通过按钮进行访问?

java - 如何使用 POI 在 Word 中读取标题编号

java - java中如何读取超过100000行的excel文件?

java - 如何使用java在hibernate中一次将数据插入多个表