在从excel文件中读取数据时,我们可以使用
no_of_rows = sheet.getPhysicalNumberOfRows();
来获取包含数据的行数。有没有一种方法可以得到在工作表的第一列中有数据的行数?
发布于 2015-03-13 16:07:54
让每一列都有不同的行号?
int rows;//行数= sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns
int tmp = 0;
for (int i = 0; i < rows; i++) {
row = sheet.getRow(i);
if (row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if (tmp > cols) {
cols = tmp;
}
}
}
if (cols == 23) {
row = sheet.getRow(0);
if ("I.D.Number".equals(row.getCell(0).toString())) {
if ("Name".equals(row.getCell(1).toString())) {
if ("Surname".equals(row.getCell(2).toString())) {
applicaple = true;
}
}
}
}
Iterator rowsExcel = sheet.rowIterator();
XSSFRow row2 = null;
if (uygunluk == true) {
while (rowsExcel.hasNext()) {
row2 = (XSSFRow) rowsExcel.next();
if (row2.getRowNum() != 0) {
if (fmt.formatCellValue(row2.getCell(0)) == null || (fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
System.out.print.ln("warn!!");
return;
} else if (fmt.formatCellValue(row2.getCell(0)) != null || !(fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
idInfo = fmt.formatCellValue(row2.getCell(0);
}https://stackoverflow.com/questions/29026852
复制相似问题