用poi将Excel数据表(含有合并单元格)导入系统的表格中,遇到合并列的数据和后面的列的一样。求解

img

问题相关代码,
        JSONObject item = new JSONObject();
        for(int c = 0; c < codes.length; c++) {
            String code = codes[c];
                cell = ExcelUtils.getCell(sheet, k, c);
            cell.setCellType(CellType.STRING);
            item.put(code, cell.getStringCellValue());

public static Cell getCellA(Sheet sheet, int row, int column) {
Cell cell = null;
int temp;
int sheetMergeCount = sheet.getNumMergedRegions(); //得到所有合并单元格
for(int i = 0 ; i < sheetMergeCount ; i++){
CellRangeAddress ca = sheet.getMergedRegion(i);//得到第i个合并单元格
int firstColumn = ca.getFirstColumn();
int lastColumn = ca.getLastColumn();
temp=column-firstColumn;
if(row >= ca.getFirstRow() && row <= ca.getLastRow()){
if(temp>=firstColumn){
//if(row==ca.getFirstRow()&&column==firstColumn) {
cell = sheet.getRow(row).getCell(lastColumn+temp);
break;
//}
}
}
}
if(cell == null) {
cell = sheet.getRow(row).getCell(column);
}
return cell;
}

在去含有合并单元格的那一行时,取到的只有三列数据。所以传c最大只能为2。导致财务和非财务那一列取值为2.就输出了合并单元格的数据。不知道怎么改。

debug断点调试一下吧,你这是表头和表体数据错位了。