一共380行只能遍历到375

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class TestExcel {
    private static final DataFormatter FORMATTER = new DataFormatter();

    /**
     * 获取单元格内容
     *
     * @param cell
     *            单元格对象
     * @return 转化为字符串的单元格内容
     */
    private static String getCellContent(Cell cell) {
        return FORMATTER.formatCellValue(cell);
    }

    private static String getExcelValue(String filePath, int sheetIndex) {
        String value = "";
        try {
            // 创建对Excel工作簿文件
            Workbook book = null;
            try {
                book = new XSSFWorkbook(new FileInputStream(filePath));
            } catch (Exception ex) {
                book = new HSSFWorkbook(new FileInputStream(filePath));
            }

            Sheet sheet = book.getSheetAt(sheetIndex);
            // 获取到Excel文件中的所有行数
            int rows = sheet.getPhysicalNumberOfRows();
            // System.out.println("rows:" + rows);
            // 遍历行
            for (int i = 0; i < rows; i++) {
                // 读取左上端单元格
                Row row = sheet.getRow(i);
                // 行不为空

                if (row != null) {
                    // 获取到Excel文件中的所有的列
                    int cells = row.getPhysicalNumberOfCells();
                    // System.out.println("cells:" + cells);

                    // 遍历列
                    for (int j = 0; j < cells; j++) {

                        // 获取到列的值
                        Cell cell = row.getCell(j);
                        if (cell != null) {
                            if(0==book.getFontAt(cell.getCellStyle().getFontIndex()).getColor())
                            value += "第" + (i + 1) + "行 第" + (j + 1) + "列 的内容是: " + getCellContent(cell) + ",";
                           //System.out.println(i+"行"+j+"列:"+cell.toString());
                        }

                    }
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return value;

    }

    public static void main(String[] args) {

        String filePath = "D://病人数据//1标准病人(非真实,蓝色为需收集的检验项目,红色为其结果).xlsx";
        int sheetIndex = 0;

        String[] val = getExcelValue(filePath, sheetIndex).split(",");
        for (int i = 0; i < val.length; i++) {
            System.out.println(val[i]);
        }
    }
}


有空行?

img

这里看不出问题,建议贴一下excel内容