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