我的Excel中有14行X 96列数据。我现在遇到的问题是,当我输出结果时,只有第一行包含所有列的完整数据,而下一行则仅包含96个总列的一半。我不知道为什么会发生。请帮助我。
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("C:xx"));
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row = null;
XSSFCell cell = null;
DataFormatter formatter = new DataFormatter();
for (Iterator<Row> iterator = sheet.rowIterator(); iterator.hasNext();) {
row = (XSSFRow) iterator.next();
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
cell = row.getCell(i);
String stringcell = formatter.formatCellValue(cell);
al.add(stringcell);`
}
System.out.println(al);
}
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
loop
}
正如Axel Richer建议的那样,现在所有数据都可见 来自
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("C:xx"));
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row = null;
XSSFCell cell = null;
DataFormatter formatter = new DataFormatter();
for (Iterator<Row> iterator = sheet.rowIterator(); iterator.hasNext();) {
row = (XSSFRow) iterator.next();
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
cell = row.getCell(i);
String stringcell = formatter.formatCellValue(cell);
al.add(stringcell);`
}
System.out.println(al);
}
} catch (Exception e) {
e.printStackTrace();
}
到
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++)