柒拾~ 2018-09-29 07:34
浏览 1150

Excel导出问题,数据错位,求解决。。。。。。。

Excel导出有问题,但是我是第一次弄这个所以不晓得怎么解决。
Excel模板如果不加所以边框导出来的数据正常如下图:
图片说明
但是如果在Excel 里加了边框如图:图片说明导出来的数据第一个数据位置就错位了,如图:
Java后台,Service层代码如下:
public static void excelImportDatasss(String filurl, Map list, HttpServletResponse response,
String begindate,String enddate,String organizeid,String key) throws IOException {
File excel2 = new File(filurl);
FileInputStream is = new FileInputStream(excel2);
HSSFWorkbook excel = new HSSFWorkbook(is);
Sheet sheet = excel.getSheetAt(0);
Object obj = null;
Row rowa = sheet.getRow(1);
if (rowa == null) {
rowa = sheet.createRow(1);
}
Cell tempcells = rowa.getCell(5);
if (tempcells == null) {
tempcells = rowa.createCell(5);
}
tempcells.setCellValue(begindate+"-"+enddate);
rowa = sheet.getRow(1);
if (rowa == null) {
rowa = sheet.createRow(1);
}
tempcells = rowa.getCell(1);
if (tempcells == null) {
tempcells = rowa.createCell(1);
}
tempcells.setCellValue(key);

    if (list != null && list.size() > 0) {
    Row row = sheet.getRow(3);
    if (row == null) {
        row = sheet.createRow(2);
    }
    Cell tempcell = row.getCell(3);
    if (tempcell == null) {
        tempcell = row.createCell(2);
    }
        obj = list.get("ZWHZZ");    //这个地方就是第一个数据

         System.out.println(list.toString());
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(3);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(3);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("ZWHZZNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(4);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(4);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("GLXSHY");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(4);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(4);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("GLXSHYNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(5);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(5);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("QTHY");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(5);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(5);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("QTHYNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(6);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(6);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("JOINSTUDYSTATENUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(6);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(6);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("STUDYNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(7);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(7);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("INVESTIGATION");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(7);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(7);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("RDYNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(8);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(8);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("INSPECTION");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(8);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(8);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("RSCNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(9);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(9);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("INVESTIGATE");
        tempcell.setCellValue(obj.toString());

/*
if (row == null) {
row = sheet.createRow(9);
}
if (tempcell == null) {
tempcell = row.createCell(5);
}
row = sheet.getRow(9);
tempcell = row.getCell(5);
obj = list.get("RKCNUM");
tempcell.setCellValue(obj.toString());*/

        row = sheet.getRow(10);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(10);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("DENUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(10);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(10);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("DERNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(11);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(11);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("TANUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(11);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(11);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("TARNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(12);
        tempcell = row.getCell(2);
        if (row == null) {
            row = sheet.createRow(12);
        }
        if (tempcell == null) {
            tempcell = row.createCell(2);
        }
        obj = list.get("QTNUM");
        tempcell.setCellValue(obj.toString());
        row = sheet.getRow(12);
        tempcell = row.getCell(5);
        if (row == null) {
            row = sheet.createRow(12);
        }
        if (tempcell == null) {
            tempcell = row.createCell(5);
        }
        obj = list.get("QTRNUM");
        tempcell.setCellValue(obj.toString());
    }
    sheet.setForceFormulaRecalculation(true);
    try {
        OutputStream os = response.getOutputStream();
        response.reset();
        response.setHeader("Content-disposition", "attachment; filename="
                + new String(URLEncoder.encode("省政协专委会组织委员开展活动情况季度统计表", "utf-8").getBytes("UTF-8"), "ISO-8859-1")
                + ".xls");
        response.setContentType("application/msexcel");
        excel.write(os);
        os.close();
        excel.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据