java引用poi导出excel(包含单元格合并,单元格背景色,单元格字体,循环加载,自动换行,边框)

废话不多说

调用导出代码:


function ExpPDF(){
    document.location.href = AppUrl + 'excel/WORKDY_ExpExcel?V_V_ORDERGUID='
        + V_ORDERGUID ,'dialogHeight:500px;dialogWidth:800px';
}

如图代码:

// 工单打印pdf
    @RequestMapping(value = "/WORKDY_ExpExcel", method = RequestMethod.GET, produces = "application/html;charset=UTF-8")
    @ResponseBody
    public void WORKDY_ExpExcel(@RequestParam(value = "V_V_ORDERGUID") String V_V_ORDERGUID,
                           HttpServletRequest request,
                           HttpServletResponse response)
             throws DocumentException, IOException, Exception, SQLException {
        String V_V_ORGCODE = "";
        String V_WORK_TYPE = "";
        String V_DEPT_CODE = "";

        /*工单基本信息-data*/
        List<Map<String, Object>> workresult = (List) cjyService.PRO_PM_WORKORDER_GET(V_V_ORDERGUID).get("list");
        if (workresult.size() > 0) {
            V_V_ORGCODE = workresult.get(0).get("V_ORGCODE").toString().equals("")?"":workresult.get(0).get("V_ORGCODE").toString(); //厂矿
            V_WORK_TYPE = workresult.get(0).get("V_ORDER_TYP_TXT").toString().equals("")?"":workresult.get(0).get("V_ORDER_TYP_TXT").toString(); //工单类型
            V_DEPT_CODE = workresult.get(0).get("V_DEPTCODE").toString().equals("")?"":workresult.get(0).get("V_DEPTCODE").toString(); //作业区
        }

        /*工序data*/
        List<Map<String, Object>> workgxresult = (List) zdhService.PRO_PM_WORKORDER_ET_OPERATIONS(V_V_ORDERGUID).get("list");

        /*物料data*/
        List<Map<String, Object>> mmresult = (List) zdhService.PRO_PM_WORKORDER_SPARE_VIEW(V_V_ORDERGUID).get("list");

        int rowWF=10+workgxresult.size();
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();
        for (int i = 0; i <= 1; i++) {
            sheet.setColumnWidth(i, 3000);
        }
//        标头字体
        HSSFFont fontHead = wb.createFont();
        fontHead.setColor(HSSFColor.BLACK.index);
        fontHead.setFontHeightInPoints((short) 12);
        fontHead.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗
        //标题字体
        HSSFFont fontT = wb.createFont();
        fontT.setColor(HSSFColor.BLACK.index);
        fontT.setFontHeightInPoints((short) 10);
        fontT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗

        //正文一个字体
        HSSFFont font = wb.createFont();
        font.setColor(HSSFColor.BLACK.index);
        font.setFontHeightInPoints((short) 10);
//        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗

        HSSFCellStyle styleHead = wb.createCellStyle();
        styleHead.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleHead.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleHead.setFont(fontHead);

        HSSFCellStyle styleTitle = wb.createCellStyle();
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleTitle.setFont(fontT);

        HSSFCellStyle styleOne = wb.createCellStyle();
        styleOne.setWrapText(true);
        styleOne.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleOne.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        /*styleOne.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderRight(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setTopBorderColor(HSSFColor.BLACK.index);
        styleOne.setLeftBorderColor(HSSFColor.BLACK.index);
        styleOne.setBottomBorderColor(HSSFColor.BLACK.index);
        styleOne.setRightBorderColor(HSSFColor.BLACK.index);*/
        styleOne.setFont(font);

        HSSFCellStyle styleTwo = wb.createCellStyle();
        styleTwo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleTwo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleTwo.setFillForegroundColor(HSSFColor.CORNFLOWER_BLUE.index);  /* 背景色*/
        styleTwo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        styleTwo.setFillBackgroundColor(HSSFColor.CORNFLOWER_BLUE.index);
         /*styleOne.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setBorderRight(HSSFCellStyle.BORDER_DOUBLE);
        styleOne.setTopBorderColor(HSSFColor.BLACK.index);
        styleOne.setLeftBorderColor(HSSFColor.BLACK.index);
        styleOne.setBottomBorderColor(HSSFColor.BLACK.index);
        styleOne.setRightBorderColor(HSSFColor.BLACK.index);*/
        styleTwo.setFont(fontT);


        sheet.addMergedRegion(new CellRangeAddress(0,0,0,10)); //row 1
        sheet.addMergedRegion(new CellRangeAddress(1,1,0,4));//row 2
        sheet.addMergedRegion(new CellRangeAddress(1,1,5,10)); //row 2
        sheet.addMergedRegion(new CellRangeAddress(2,2,3,4)); //row 3
        sheet.addMergedRegion(new CellRangeAddress(2,2,6,10)); //row 3
        sheet.addMergedRegion(new CellRangeAddress(3,3,3,4)); //row 4
        sheet.addMergedRegion(new CellRangeAddress(3,3,6,10)); //row 4
        sheet.addMergedRegion(new CellRangeAddress(4,4,3,4)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(4,4,6,7)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(4,4,9,10)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(5,5,1,4)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(5,5,6,7)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(5,5,9,10)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(6,6,6,7)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(6,6,9,10)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(6,6,1,4)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(7,7,1,10)); //row 8

        sheet.addMergedRegion(new CellRangeAddress(8,8,0,10)); //row 9

        sheet.addMergedRegion(new CellRangeAddress(rowWF,rowWF,0,10));//row物料标题行

        //第一行
        HSSFRow rowOne = sheet.createRow((int) 0);
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 12 * 256);
        sheet.setColumnWidth(2, 12 * 256);
        sheet.setColumnWidth(3, 10 * 256);
        sheet.setColumnWidth(4, 10 * 256);
        sheet.setColumnWidth(5, 15 * 256);
        sheet.setColumnWidth(6, 10 * 256);
        sheet.setColumnWidth(7, 10 * 256);
        sheet.setColumnWidth(8, 15 * 256);
        sheet.setColumnWidth(9, 10 * 256);
        sheet.setColumnWidth(10, 10 * 256);

        //第一列
        HSSFCell cella = rowOne.createCell((short) 0);
        cella.setCellValue("工单打印");
        cella.setCellStyle(styleHead);

        //第2行
        HSSFRow rowTwo = sheet.createRow((int) 1);
        //1列
        HSSFCell cellb = rowTwo.createCell((short) 0);
        cellb.setCellValue("1、基本信息栏");
        cellb.setCellStyle(styleTitle);
        //2列
        cellb = rowTwo.createCell((short) 5);
        cellb.setCellValue("2、任务信息栏");
        cellb.setCellStyle(styleTitle);

        //第3行
        HSSFRow rowThree = sheet.createRow((int) 2);
        //1列
        HSSFCell cellc = rowThree.createCell((short) 0);
        cellc.setCellValue("厂矿单位:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 1);
        cellc.setCellValue(V_V_ORGCODE);
        cellc.setCellStyle(styleOne);

        cellc = rowThree.createCell((short) 2);
        cellc.setCellValue("工单类型:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 3);
        cellc.setCellValue(V_WORK_TYPE);
        cellc.setCellStyle(styleOne);

        cellc = rowThree.createCell((short) 5);
        cellc.setCellValue("WBS编码:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 6);
        cellc.setCellValue(workresult.get(0).get("V_WBS").toString().equals("")?"":workresult.get(0).get("V_WBS").toString());
        cellc.setCellStyle(styleOne);

        //4行
        HSSFRow rowFour = sheet.createRow((int) 3);
        HSSFCell celld = rowFour.createCell((short) 0);
        celld.setCellValue("作业区:");
        celld.setCellStyle(styleTwo);

        cellc = rowFour.createCell((short) 1);
        cellc.setCellValue(V_DEPT_CODE);
        cellc.setCellStyle(styleOne);

        cellc = rowFour.createCell((short) 2);
        cellc.setCellValue("工单号:");
        cellc.setCellStyle(styleTwo);

        cellc = rowFour.createCell((short) 3);
        cellc.setCellValue(workresult.get(0).get("V_ORDERID").toString().equals("")?"":workresult.get(0).get("V_ORDERID").toString());
        cellc.setCellStyle(styleOne);

        cellc = rowFour.createCell((short) 5);
        cellc.setCellValue("项目名称:");
        cellc.setCellStyle(styleTwo);

        cellc = rowFour.createCell((short) 6);
        cellc.setCellValue(workresult.get(0).get("V_WBS_TXT").toString().equals("")?"":workresult.get(0).get("V_WBS_TXT").toString());
        cellc.setCellStyle(styleOne);

        //5行
        HSSFRow rowFive = sheet.createRow((int) 4);
        HSSFCell celle = rowFive.createCell((short) 0);
        celle.setCellValue("设备名称:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 1);
        celle.setCellValue(workresult.get(0).get("V_EQUIP_NAME").toString().equals("")?"":workresult.get(0).get("V_EQUIP_NAME").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 2);
        celle.setCellValue("检修单位:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 3);
        celle.setCellValue(workresult.get(0).get("V_DEPTNAMEREPARIR").toString().equals("")?"":workresult.get(0).get("V_DEPTNAMEREPARIR").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 5);
        celle.setCellValue("创建人:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 6);
        celle.setCellValue(workresult.get(0).get("V_ENTERED_BY").toString().equals("")?"":workresult.get(0).get("V_ENTERED_BY").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 8);
        celle.setCellValue("创建时间:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 9);
        celle.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        celle.setCellStyle(styleOne);

        //6行
        HSSFRow rowSix = sheet.createRow((int) 5);
        HSSFCell cellf = rowSix.createCell((short) 0);
        cellf.setCellValue("设备编码:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 1);
        cellf.setCellValue(workresult.get(0).get("V_EQUIP_NO").toString().equals("")?"":workresult.get(0).get("V_EQUIP_NO").toString());
        cellf.setCellStyle(styleOne);

        cellf = rowSix.createCell((short) 5);
        cellf.setCellValue("计划开始时间:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 6);
        cellf.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        cellf.setCellStyle(styleOne);

        cellf = rowSix.createCell((short) 8);
        cellf.setCellValue("实际开始时间:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 9);
        cellf.setCellValue(workresult.get(0).get("D_FACT_START_DATE").toString().equals("")?"":workresult.get(0).get("D_FACT_START_DATE").toString());
        cellf.setCellStyle(styleOne);

        //7行
        HSSFRow rowSeven = sheet.createRow((int) 6);
        HSSFCell cellg = rowSeven.createCell((short) 0);
        cellg.setCellValue("功能位置:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 1);
        cellg.setCellValue(workresult.get(0).get("V_EQUSITENAME").toString().equals("")?"":workresult.get(0).get("V_EQUSITENAME").toString());
        cellg.setCellStyle(styleOne);

        cellg = rowFive.createCell((short) 5);
        cellg.setCellValue("计划完成时间:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 6);
        cellg.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        cellg.setCellStyle(styleOne);

        cellg = rowFive.createCell((short) 8);
        cellg.setCellValue("实际完成时间:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 9);
        cellg.setCellValue(workresult.get(0).get("D_FACT_FINISH_DATE").toString().equals("")?"":workresult.get(0).get("D_FACT_FINISH_DATE").toString());
        cellg.setCellStyle(styleOne);

        //8行
        HSSFRow rowEight = sheet.createRow((int) 7);
        HSSFCell cellh = rowEight.createCell((short) 0);
        cellh.setCellValue("工单描述:");
        cellh.setCellStyle(styleTwo);

        cellh = rowFive.createCell((short) 1);
        cellh.setCellValue(workresult.get(0).get("V_SHORT_TXT").toString().equals("")?"":workresult.get(0).get("V_SHORT_TXT").toString());
        cellh.setCellStyle(styleOne);

        //9行
        HSSFRow rownight = sheet.createRow((int) 8);
        HSSFCell celli = rownight.createCell((short) 0);
        celli.setCellValue("3、任务细节:");
        celli.setCellStyle(styleTitle);

        //9行
        HSSFRow rowten = sheet.createRow((int) 9);
        HSSFCell cellj = rowten.createCell((short) 0);
        cellj.setCellValue("工作编号");cellj.setCellStyle(styleTwo);

        cellj = rowten.createCell((short) 1);cellj.setCellValue("工作中心");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 2);cellj.setCellValue("工序内容");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 3);cellj.setCellValue("定额时间");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 4);cellj.setCellValue("定额人数");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 5);cellj.setCellValue("实际时间");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 6);cellj.setCellValue("实际人数");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 7);cellj.setCellValue("机具");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 8);cellj.setCellValue("工具");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 9);cellj.setCellValue("技术要求");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 10);cellj.setCellValue("安全措施");cellj.setCellStyle(styleTwo);

        if(workgxresult.size()>0){
            int sizegx=workgxresult.size()+10;
            for(int i=10;i<sizegx;i++){
                HSSFRow rowgx = sheet.createRow((int) i);
                int a=i-10;
                rowgx.createCell((short) 0).setCellValue(workgxresult.get(a).get("V_ACTIVITY").toString().equals("") ? "" :workgxresult.get(a).get("V_ACTIVITY").toString());
                rowgx.createCell((short) 1).setCellValue(workgxresult.get(a).get("V_WORK_CENTER").toString().equals("") ? "" :workgxresult.get(a).get("V_WORK_CENTER").toString());// map.get("FX_GUID").toString());
                rowgx.createCell((short) 2).setCellValue(workgxresult.get(a).get("V_DESCRIPTION").toString().equals("") ? "" :workgxresult.get(a).get("V_DESCRIPTION").toString());
                rowgx.createCell((short) 3).setCellValue(workgxresult.get(a).get("I_WORK_ACTIVITY").toString().equals("") ? "" :workgxresult.get(a).get("I_WORK_ACTIVITY").toString());
                rowgx.createCell((short) 4).setCellValue(workgxresult.get(a).get("I_DURATION_NORMAL").toString().equals("") ? "" :workgxresult.get(a).get("I_DURATION_NORMAL").toString());
                rowgx.createCell((short) 5).setCellValue(workgxresult.get(a).get("I_ACTUAL_TIME").toString().equals("") ? "" :workgxresult.get(a).get("I_ACTUAL_TIME").toString());
                rowgx.createCell((short) 6).setCellValue(workgxresult.get(a).get("I_NUMBER_OF_PEOPLE").toString().equals("") ? "" :workgxresult.get(a).get("I_NUMBER_OF_PEOPLE").toString());
                rowgx.createCell((short) 7).setCellValue(workgxresult.get(a).get("V_JJ_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_JJ_NAME").toString());
                rowgx.createCell((short) 8).setCellValue(workgxresult.get(a).get("V_GJ_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_GJ_NAME").toString());
                rowgx.createCell((short) 9).setCellValue(workgxresult.get(a).get("V_JSQY_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_JSQY_NAME").toString());
                rowgx.createCell((short) 10).setCellValue(workgxresult.get(a).get("V_AQSC_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_AQSC_NAME").toString());
                rowgx.createCell((short) a).setCellStyle(styleOne);
            }

        }

        //物料标题
        HSSFRow rowMH= sheet.createRow((int) rowWF);
        HSSFCell cellk = rowMH.createCell((short) 0);
        cellk.setCellValue("4、物料信息:");
        cellk.setCellStyle(styleTitle);

        HSSFRow rowMtit= sheet.createRow((int) rowWF+1);
        sheet.addMergedRegion(new CellRangeAddress(rowWF+1,rowWF+1,3,4));//row物料标题行
        HSSFCell celll = rowMtit.createCell((short) 0);
        celll.setCellValue("序号");
        celll.setCellStyle(styleTwo);

        celll = rowMtit.createCell((short) 1);celll.setCellValue("工序");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 2);celll.setCellValue("物料编码");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 3);celll.setCellValue("物料描述");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 5);celll.setCellValue("单位");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 6);celll.setCellValue("计划数量");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 7);celll.setCellValue("总金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 8);celll.setCellValue("实际金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 9);celll.setCellValue("实际总金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 10);celll.setCellValue("备注");celll.setCellStyle(styleTwo);

        if(mmresult.size()>0){

            int sizemat=mmresult.size()+rowWF;
            int insize=rowWF+2;
            for(int j=insize;j<sizemat;j++){
                sheet.addMergedRegion(new CellRangeAddress(j,j,3,4));//row物料标题行
                HSSFRow rowmat = sheet.createRow((int) j);
                int b=j-rowWF-2;
                rowmat.createCell((short) 0).setCellValue(workgxresult.get(b).get("sid").toString().equals("") ? "" :workgxresult.get(b).get("sid").toString());
                rowmat.createCell((short) 1).setCellValue(workgxresult.get(b).get("V_ACTIVITY").toString().equals("") ? "" :workgxresult.get(b).get("V_ACTIVITY").toString());// map.get("FX_GUID").toString());
                rowmat.createCell((short) 2).setCellValue(workgxresult.get(b).get("V_MATERIALCODE").toString().equals("") ? "" :workgxresult.get(b).get("V_MATERIALCODE").toString());
                rowmat.createCell((short) 3).setCellValue(workgxresult.get(b).get("V_MATERIALNAME").toString().equals("") ? "" :workgxresult.get(b).get("V_MATERIALNAME").toString());
                rowmat.createCell((short) 5).setCellValue(workgxresult.get(b).get("V_UNIT").toString().equals("") ? "" :workgxresult.get(b).get("V_UNIT").toString());
                rowmat.createCell((short) 6).setCellValue(workgxresult.get(b).get("I_PLANAMOUNT").toString().equals("") ? "" :workgxresult.get(b).get("I_PLANAMOUNT").toString());
                rowmat.createCell((short) 7).setCellValue(workgxresult.get(b).get("F_PLANMONEY").toString().equals("") ? "" :workgxresult.get(b).get("F_PLANMONEY").toString());
                rowmat.createCell((short) 8).setCellValue(workgxresult.get(b).get("I_ACTUALAMOUNT").toString().equals("") ? "" :workgxresult.get(b).get("I_ACTUALAMOUNT").toString());
                rowmat.createCell((short) 9).setCellValue(workgxresult.get(b).get("F_ACTUALMONEY").toString().equals("") ? "" :workgxresult.get(b).get("F_ACTUALMONEY").toString());
                rowmat.createCell((short) 10).setCellValue(workgxresult.get(b).get("").toString().equals("") ? "" :workgxresult.get(b).get("").toString());
                rowmat.createCell((short) b).setCellStyle(styleOne);
            }

        }
        try {
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment; filename="
                    + URLEncoder.encode("工单打印Excel.xls", "UTF-8"));
            OutputStream out = response.getOutputStream();

            wb.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

结果样式:

//update: 2019/07/23  加边框版

今天查找边框的时候,发现一个可以借鉴的很好的详解文档:https://blog.csdn.net/sxdtwym/article/details/54379592 

 // 工单打印pdf
    @RequestMapping(value = "/WORKDY_ExpExcel", method = RequestMethod.GET, produces = "application/html;charset=UTF-8")
    @ResponseBody
    public void WORKDY_ExpExcel(@RequestParam(value = "V_V_ORDERGUID") String V_V_ORDERGUID,
                           HttpServletRequest request,
                           HttpServletResponse response)
             throws DocumentException, IOException, Exception, SQLException {
        String V_V_ORGCODE = "";
        String V_WORK_TYPE = "";
        String V_DEPT_CODE = "";

        /*工单基本信息-data*/
        List<Map<String, Object>> workresult = (List) cjyService.PRO_PM_WORKORDER_GET(V_V_ORDERGUID).get("list");
        if (workresult.size() > 0) {
            V_V_ORGCODE = workresult.get(0).get("V_ORGCODE").toString().equals("")?"":workresult.get(0).get("V_ORGCODE").toString(); //厂矿
            V_WORK_TYPE = workresult.get(0).get("V_ORDER_TYP_TXT").toString().equals("")?"":workresult.get(0).get("V_ORDER_TYP_TXT").toString(); //工单类型
            V_DEPT_CODE = workresult.get(0).get("V_DEPTCODE").toString().equals("")?"":workresult.get(0).get("V_DEPTCODE").toString(); //作业区
        }

        /*工序data*/
        List<Map<String, Object>> workgxresult = (List) zdhService.PRO_PM_WORKORDER_ET_OPERATIONS(V_V_ORDERGUID).get("list");

        /*物料data*/
        List<Map<String, Object>> mmresult = (List) zdhService.PRO_PM_WORKORDER_SPARE_VIEW(V_V_ORDERGUID).get("list");

        int rowWF=10+workgxresult.size();
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();
        for (int i = 0; i <= 1; i++) {
            sheet.setColumnWidth(i, 3000);
        }
//        标头字体
        HSSFFont fontHead = wb.createFont();
        fontHead.setColor(HSSFColor.BLACK.index);
        fontHead.setFontHeightInPoints((short) 12);
        fontHead.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗
        //标题字体
        HSSFFont fontT = wb.createFont();
        fontT.setColor(HSSFColor.BLACK.index);
        fontT.setFontHeightInPoints((short) 10);
        fontT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗

        //正文一个字体
        HSSFFont font = wb.createFont();
        font.setColor(HSSFColor.BLACK.index);
        font.setFontHeightInPoints((short) 10);
//        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗

        HSSFCellStyle styleHead = wb.createCellStyle();
        styleHead.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleHead.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleHead.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleHead.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleHead.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleHead.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleHead.setTopBorderColor(HSSFColor.BLACK.index);
        styleHead.setLeftBorderColor(HSSFColor.BLACK.index);
        styleHead.setBottomBorderColor(HSSFColor.BLACK.index);
        styleHead.setRightBorderColor(HSSFColor.BLACK.index);
        styleHead.setFont(fontHead);

        HSSFCellStyle styleTitle = wb.createCellStyle();
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleTitle.setTopBorderColor(HSSFColor.BLACK.index);
        styleTitle.setLeftBorderColor(HSSFColor.BLACK.index);
        styleTitle.setBottomBorderColor(HSSFColor.BLACK.index);
        styleTitle.setRightBorderColor(HSSFColor.BLACK.index);
        styleTitle.setFont(fontT);

        HSSFCellStyle styleOne = wb.createCellStyle();
        styleOne.setWrapText(true);
        styleOne.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleOne.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleOne.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleOne.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleOne.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleOne.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleOne.setTopBorderColor(HSSFColor.BLACK.index);
        styleOne.setLeftBorderColor(HSSFColor.BLACK.index);
        styleOne.setBottomBorderColor(HSSFColor.BLACK.index);
        styleOne.setRightBorderColor(HSSFColor.BLACK.index);
        styleOne.setFont(font);

        HSSFCellStyle styleTwo = wb.createCellStyle();
        styleTwo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleTwo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
        styleTwo.setFillForegroundColor(HSSFColor.CORNFLOWER_BLUE.index);  /* 背景色*/
        styleTwo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        styleTwo.setFillBackgroundColor(HSSFColor.CORNFLOWER_BLUE.index);
        styleTwo.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleTwo.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleTwo.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleTwo.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleTwo.setTopBorderColor(HSSFColor.BLACK.index);
        styleTwo.setLeftBorderColor(HSSFColor.BLACK.index);
        styleTwo.setBottomBorderColor(HSSFColor.BLACK.index);
        styleTwo.setRightBorderColor(HSSFColor.BLACK.index);
        styleTwo.setFont(fontT);


        sheet.addMergedRegion(new CellRangeAddress(0,0,0,10)); //row 1
        sheet.addMergedRegion(new CellRangeAddress(1,1,0,4));//row 2
        sheet.addMergedRegion(new CellRangeAddress(1,1,5,10)); //row 2
        sheet.addMergedRegion(new CellRangeAddress(2,2,3,4)); //row 3
        sheet.addMergedRegion(new CellRangeAddress(2,2,6,10)); //row 3
        sheet.addMergedRegion(new CellRangeAddress(3,3,3,4)); //row 4
        sheet.addMergedRegion(new CellRangeAddress(3,3,6,10)); //row 4
        sheet.addMergedRegion(new CellRangeAddress(4,4,3,4)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(4,4,6,7)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(4,4,9,10)); //row 5
        sheet.addMergedRegion(new CellRangeAddress(5,5,1,4)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(5,5,6,7)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(5,5,9,10)); //row 6
        sheet.addMergedRegion(new CellRangeAddress(6,6,6,7)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(6,6,9,10)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(6,6,1,4)); //row 7
        sheet.addMergedRegion(new CellRangeAddress(7,7,1,10)); //row 8

        sheet.addMergedRegion(new CellRangeAddress(8,8,0,10)); //row 9

        sheet.addMergedRegion(new CellRangeAddress(rowWF,rowWF,0,10));//row物料标题行


        //第一行
        HSSFRow rowOne = sheet.createRow((int) 0);
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 12 * 256);
        sheet.setColumnWidth(2, 12 * 256);
        sheet.setColumnWidth(3, 10 * 256);
        sheet.setColumnWidth(4, 10 * 256);
        sheet.setColumnWidth(5, 15 * 256);
        sheet.setColumnWidth(6, 10 * 256);
        sheet.setColumnWidth(7, 10 * 256);
        sheet.setColumnWidth(8, 15 * 256);
        sheet.setColumnWidth(9, 10 * 256);
        sheet.setColumnWidth(10, 10 * 256);

        //第一列
        HSSFCell cella = rowOne.createCell((short) 0);
        cella.setCellValue("工单打印");cella.setCellStyle(styleHead);
        CellRangeAddress cra1 =new CellRangeAddress(0,0,0,10);
        sheet.addMergedRegion(cra1);
        RegionUtil.setBorderBottom(1, cra1, sheet,wb);
//        RegionUtil.setBorderLeft(1, cra, sheet); // 左边框
        RegionUtil.setBorderRight(1, cra1, sheet,wb); // 有边框
        RegionUtil.setBorderTop(1, cra1, sheet,wb); // 上边框

        //第2行
        HSSFRow rowTwo = sheet.createRow((int) 1);
        //1列
        HSSFCell cellb = rowTwo.createCell((short) 0);
        cellb.setCellValue("1、基本信息栏");
        cellb.setCellStyle(styleTitle);

        //2列
        cellb = rowTwo.createCell((short) 5);
        cellb.setCellValue("2、任务信息栏");
        cellb.setCellStyle(styleTitle);

        CellRangeAddress cra2=new CellRangeAddress(1,1,0,4);
        sheet.addMergedRegion(cra2);
        RegionUtil.setBorderBottom(1, cra2, sheet,wb);
        RegionUtil.setBorderRight(1, cra2, sheet,wb);
        RegionUtil.setBorderTop(1, cra2, sheet,wb);
        CellRangeAddress cra3 =new CellRangeAddress(1,1,5,10);
        sheet.addMergedRegion(cra3);
        RegionUtil.setBorderBottom(1, cra3, sheet,wb);
        RegionUtil.setBorderRight(1, cra3, sheet,wb);
        RegionUtil.setBorderTop(1, cra3, sheet,wb);

        //第3行
        HSSFRow rowThree = sheet.createRow(2);
        //1列
        HSSFCell cellc = rowThree.createCell((short) 0);
        cellc.setCellValue("厂矿单位:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 1);
        cellc.setCellValue(V_V_ORGCODE);
        cellc.setCellStyle(styleOne);

        cellc = rowThree.createCell((short) 2);
        cellc.setCellValue("工单类型:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 3);
        cellc.setCellValue(V_WORK_TYPE);
        cellc.setCellStyle(styleOne);
        cellc = rowThree.createCell((short) 4);
        cellc.setCellStyle(styleOne);
        cellc = rowThree.createCell((short) 5);
        cellc.setCellValue("WBS编码:");
        cellc.setCellStyle(styleTwo);

        cellc = rowThree.createCell((short) 6);
        cellc.setCellValue(workresult.get(0).get("V_WBS").toString().equals("")?"":workresult.get(0).get("V_WBS").toString());
        cellc.setCellStyle(styleOne);

        CellRangeAddress cra4 =new CellRangeAddress(2,2,3,4);
        sheet.addMergedRegion(cra4);
        RegionUtil.setBorderBottom(1, cra4, sheet,wb);
        RegionUtil.setBorderRight(1, cra4, sheet,wb);
        RegionUtil.setBorderTop(1, cra4, sheet,wb);
        CellRangeAddress cra5 =new CellRangeAddress(2,2,6,10);
        sheet.addMergedRegion(cra5);
        RegionUtil.setBorderBottom(1, cra5, sheet,wb);
        RegionUtil.setBorderRight(1, cra5, sheet,wb);
        RegionUtil.setBorderTop(1, cra5, sheet,wb);

        //4行
        HSSFRow rowFour = sheet.createRow((int) 3);
        HSSFCell celld = rowFour.createCell((short) 0);
        celld.setCellValue("作业区:");
        celld.setCellStyle(styleTwo);

        celld = rowFour.createCell((short) 1);
        celld.setCellValue(V_DEPT_CODE);
        celld.setCellStyle(styleOne);

        celld = rowFour.createCell((short) 2);
        celld.setCellValue("工单号:");
        celld.setCellStyle(styleTwo);

        celld = rowFour.createCell((short) 3);
        celld.setCellValue(workresult.get(0).get("V_ORDERID").toString().equals("")?"":workresult.get(0).get("V_ORDERID").toString());
        celld.setCellStyle(styleOne);

        celld = rowFour.createCell((short) 4);
        celld.setCellValue("");
        celld.setCellStyle(styleOne);

        celld = rowFour.createCell((short) 5);
        celld.setCellValue("项目名称:");
        celld.setCellStyle(styleTwo);

        celld = rowFour.createCell((short) 6);
        celld.setCellValue(workresult.get(0).get("V_WBS_TXT").toString().equals("")?"":workresult.get(0).get("V_WBS_TXT").toString());
        celld.setCellStyle(styleOne);

        CellRangeAddress cra6 =new CellRangeAddress(3,3,3,4);
        sheet.addMergedRegion(cra6);
        RegionUtil.setBorderBottom(1, cra6, sheet,wb);
        RegionUtil.setBorderRight(1, cra6, sheet,wb);
        RegionUtil.setBorderTop(1, cra6, sheet,wb);
        CellRangeAddress cra7 =new CellRangeAddress(3,3,6,10);
        sheet.addMergedRegion(cra7);
        RegionUtil.setBorderBottom(1, cra7, sheet,wb);
        RegionUtil.setBorderRight(1, cra7, sheet,wb);
        RegionUtil.setBorderTop(1, cra7, sheet,wb);

        //5行
        HSSFRow rowFive = sheet.createRow((int) 4);
        HSSFCell celle = rowFive.createCell((short) 0);
        celle.setCellValue("设备名称:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 1);
        celle.setCellValue(workresult.get(0).get("V_EQUIP_NAME").toString().equals("")?"":workresult.get(0).get("V_EQUIP_NAME").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 2);
        celle.setCellValue("检修单位:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 3);
        celle.setCellValue(workresult.get(0).get("V_DEPTNAMEREPARIR").toString().equals("")?"":workresult.get(0).get("V_DEPTNAMEREPARIR").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 5);
        celle.setCellValue("创建人:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 6);
        celle.setCellValue(workresult.get(0).get("V_ENTERED_BY").toString().equals("")?"":workresult.get(0).get("V_ENTERED_BY").toString());
        celle.setCellStyle(styleOne);

        celle = rowFive.createCell((short) 8);
        celle.setCellValue("创建时间:");
        celle.setCellStyle(styleTwo);

        celle = rowFive.createCell((short) 9);
        celle.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        celle.setCellStyle(styleOne);

        CellRangeAddress cra8 =new CellRangeAddress(4,4,3,4);
        sheet.addMergedRegion(cra8);
        RegionUtil.setBorderBottom(1, cra8, sheet,wb);
        RegionUtil.setBorderRight(1, cra8, sheet,wb);
        RegionUtil.setBorderTop(1, cra8, sheet,wb);
        CellRangeAddress cra9 =new CellRangeAddress(4,4,6,7);
        sheet.addMergedRegion(cra9);
        RegionUtil.setBorderBottom(1, cra9, sheet,wb);
        RegionUtil.setBorderRight(1, cra9, sheet,wb);
        RegionUtil.setBorderTop(1, cra9, sheet,wb);
        CellRangeAddress cra10 =new CellRangeAddress(4,4,9,10);
        sheet.addMergedRegion(cra10);
        RegionUtil.setBorderBottom(1, cra10, sheet,wb);
        RegionUtil.setBorderRight(1, cra10, sheet,wb);
        RegionUtil.setBorderTop(1, cra10, sheet,wb);

        //6行
        HSSFRow rowSix = sheet.createRow((int) 5);
        HSSFCell cellf = rowSix.createCell((short) 0);
        cellf.setCellValue("设备编码:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 1);
        cellf.setCellValue(workresult.get(0).get("V_EQUIP_NO").toString().equals("")?"":workresult.get(0).get("V_EQUIP_NO").toString());
        cellf.setCellStyle(styleOne);

        cellf = rowSix.createCell((short) 5);
        cellf.setCellValue("计划开始时间:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 6);
        cellf.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        cellf.setCellStyle(styleOne);

        cellf = rowSix.createCell((short) 8);
        cellf.setCellValue("实际开始时间:");
        cellf.setCellStyle(styleTwo);

        cellf = rowSix.createCell((short) 9);
        cellf.setCellValue(workresult.get(0).get("D_FACT_START_DATE").toString().equals("")?"":workresult.get(0).get("D_FACT_START_DATE").toString());
        cellf.setCellStyle(styleOne);

        CellRangeAddress cra11 =new CellRangeAddress(5,5,1,4);
        sheet.addMergedRegion(cra11);
        RegionUtil.setBorderBottom(1, cra11, sheet,wb);
        RegionUtil.setBorderRight(1, cra11, sheet,wb);
        RegionUtil.setBorderTop(1, cra11, sheet,wb);
        CellRangeAddress cra12 =new CellRangeAddress(5,5,6,7);
        sheet.addMergedRegion(cra12);
        RegionUtil.setBorderBottom(1, cra12, sheet,wb);
        RegionUtil.setBorderRight(1, cra12, sheet,wb);
        RegionUtil.setBorderTop(1, cra12, sheet,wb);
        CellRangeAddress cra13 =new CellRangeAddress(5,5,9,10);
        sheet.addMergedRegion(cra13);
        RegionUtil.setBorderBottom(1, cra13, sheet,wb);
        RegionUtil.setBorderRight(1, cra13, sheet,wb);
        RegionUtil.setBorderTop(1, cra13, sheet,wb);


        //7行
        HSSFRow rowSeven = sheet.createRow((int) 6);
        HSSFCell cellg = rowSeven.createCell((short) 0);
        cellg.setCellValue("功能位置:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 1);
        cellg.setCellValue(workresult.get(0).get("V_EQUSITENAME").toString().equals("")?"":workresult.get(0).get("V_EQUSITENAME").toString());
        cellg.setCellStyle(styleOne);

        cellg = rowFive.createCell((short) 5);
        cellg.setCellValue("计划完成时间:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 6);
        cellg.setCellValue(workresult.get(0).get("D_ENTER_DATE").toString().equals("")?"":workresult.get(0).get("D_ENTER_DATE").toString());
        cellg.setCellStyle(styleOne);

        cellg = rowFive.createCell((short) 8);
        cellg.setCellValue("实际完成时间:");
        cellg.setCellStyle(styleTwo);

        cellg = rowFive.createCell((short) 9);
        cellg.setCellValue(workresult.get(0).get("D_FACT_FINISH_DATE").toString().equals("")?"":workresult.get(0).get("D_FACT_FINISH_DATE").toString());
        cellg.setCellStyle(styleOne);

        CellRangeAddress cra14 =new CellRangeAddress(6,6,6,7);
        sheet.addMergedRegion(cra14);
        RegionUtil.setBorderBottom(1, cra14, sheet,wb);
        RegionUtil.setBorderRight(1, cra14, sheet,wb);
        RegionUtil.setBorderTop(1, cra14, sheet,wb);
        CellRangeAddress cra15 =new CellRangeAddress(6,6,9,10);
        sheet.addMergedRegion(cra15);
        RegionUtil.setBorderBottom(1, cra15, sheet,wb);
        RegionUtil.setBorderRight(1, cra15, sheet,wb);
        RegionUtil.setBorderTop(1, cra15, sheet,wb);
        CellRangeAddress cra16 =new CellRangeAddress(6,6,1,4);
        sheet.addMergedRegion(cra16);
        RegionUtil.setBorderBottom(1, cra16, sheet,wb);
        RegionUtil.setBorderRight(1, cra16, sheet,wb);
        RegionUtil.setBorderTop(1, cra16, sheet,wb);

        //8行
        HSSFRow rowEight = sheet.createRow((int) 7);
        HSSFCell cellh = rowEight.createCell((short) 0);
        cellh.setCellValue("工单描述:");
        cellh.setCellStyle(styleTwo);

        cellh = rowFive.createCell((short) 1);
        cellh.setCellValue(workresult.get(0).get("V_SHORT_TXT").toString().equals("")?"":workresult.get(0).get("V_SHORT_TXT").toString());
        cellh.setCellStyle(styleOne);

        CellRangeAddress cra17 =new CellRangeAddress(7,7,1,10);
        sheet.addMergedRegion(cra17);
        RegionUtil.setBorderBottom(1, cra17, sheet,wb);
        RegionUtil.setBorderRight(1, cra17, sheet,wb);
        RegionUtil.setBorderTop(1, cra17, sheet,wb);

        //9行
        HSSFRow rownight = sheet.createRow((int) 8);
        HSSFCell celli = rownight.createCell((short) 0);
        celli.setCellValue("3、任务细节:");
        celli.setCellStyle(styleTitle);
        CellRangeAddress cra18 =new CellRangeAddress(8,8,0,10);
        sheet.addMergedRegion(cra18);
        RegionUtil.setBorderBottom(1, cra18, sheet,wb);
        RegionUtil.setBorderRight(1, cra18, sheet,wb);
        RegionUtil.setBorderTop(1, cra18, sheet,wb);

        //9行
        HSSFRow rowten = sheet.createRow((int) 9);
        HSSFCell cellj = rowten.createCell((short) 0);
        cellj.setCellValue("工作编号");cellj.setCellStyle(styleTwo);

        cellj = rowten.createCell((short) 1);cellj.setCellValue("工作中心");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 2);cellj.setCellValue("工序内容");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 3);cellj.setCellValue("定额时间");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 4);cellj.setCellValue("定额人数");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 5);cellj.setCellValue("实际时间");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 6);cellj.setCellValue("实际人数");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 7);cellj.setCellValue("机具");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 8);cellj.setCellValue("工具");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 9);cellj.setCellValue("技术要求");cellj.setCellStyle(styleTwo);
        cellj = rowten.createCell((short) 10);cellj.setCellValue("安全措施");cellj.setCellStyle(styleTwo);

        if(workgxresult.size()>0){
            int sizegx=workgxresult.size()+10;
            for(int i=10;i<sizegx;i++){
                HSSFRow rowgx = sheet.createRow((int) i);
                int a=i-10;
                rowgx.createCell((short) 0).setCellValue(workgxresult.get(a).get("V_ACTIVITY").toString().equals("") ? "" :workgxresult.get(a).get("V_ACTIVITY").toString());
                rowgx.createCell((short) 1).setCellValue(workgxresult.get(a).get("V_WORK_CENTER").toString().equals("") ? "" :workgxresult.get(a).get("V_WORK_CENTER").toString());// map.get("FX_GUID").toString());
                rowgx.createCell((short) 2).setCellValue(workgxresult.get(a).get("V_DESCRIPTION").toString().equals("") ? "" :workgxresult.get(a).get("V_DESCRIPTION").toString());
                rowgx.createCell((short) 3).setCellValue(workgxresult.get(a).get("I_WORK_ACTIVITY").toString().equals("") ? "" :workgxresult.get(a).get("I_WORK_ACTIVITY").toString());
                rowgx.createCell((short) 4).setCellValue(workgxresult.get(a).get("I_DURATION_NORMAL").toString().equals("") ? "" :workgxresult.get(a).get("I_DURATION_NORMAL").toString());
                rowgx.createCell((short) 5).setCellValue(workgxresult.get(a).get("I_ACTUAL_TIME").toString().equals("") ? "" :workgxresult.get(a).get("I_ACTUAL_TIME").toString());
                rowgx.createCell((short) 6).setCellValue(workgxresult.get(a).get("I_NUMBER_OF_PEOPLE").toString().equals("") ? "" :workgxresult.get(a).get("I_NUMBER_OF_PEOPLE").toString());
                rowgx.createCell((short) 7).setCellValue(workgxresult.get(a).get("V_JJ_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_JJ_NAME").toString());
                rowgx.createCell((short) 8).setCellValue(workgxresult.get(a).get("V_GJ_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_GJ_NAME").toString());
                rowgx.createCell((short) 9).setCellValue(workgxresult.get(a).get("V_JSQY_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_JSQY_NAME").toString());
                rowgx.createCell((short) 10).setCellValue(workgxresult.get(a).get("V_AQSC_NAME").toString().equals("") ? "" :workgxresult.get(a).get("V_AQSC_NAME").toString());
                for(int m=0;m<=10;m++){
                    sheet.addMergedRegion(new CellRangeAddress(i,i,m,m));
                    RegionUtil.setBorderBottom(1, new CellRangeAddress(i,i,m,m), sheet,wb);
                    RegionUtil.setBorderRight(1, new CellRangeAddress(i,i,m,m), sheet,wb);
                    RegionUtil.setBorderTop(1, new CellRangeAddress(i,i,m,m), sheet,wb);
                }
            }
        }

        //物料标题
        HSSFRow rowMH= sheet.createRow((int) rowWF);
        HSSFCell cellk = rowMH.createCell((short) 0);
        cellk.setCellValue("4、物料信息:");
        cellk.setCellStyle(styleTitle);

        CellRangeAddress cra19 =new CellRangeAddress(rowWF,rowWF,0,10);
        sheet.addMergedRegion(cra19);
        RegionUtil.setBorderBottom(1, cra19, sheet,wb);
        RegionUtil.setBorderRight(1, cra19, sheet,wb);
        RegionUtil.setBorderTop(1, cra19, sheet,wb);

        HSSFRow rowMtit= sheet.createRow((int) rowWF+1);
        sheet.addMergedRegion(new CellRangeAddress(rowWF+1,rowWF+1,3,4));//row物料标题行
        HSSFCell celll = rowMtit.createCell((short) 0);
        celll.setCellValue("序号");
        celll.setCellStyle(styleTwo);

        celll = rowMtit.createCell((short) 1);celll.setCellValue("工序");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 2);celll.setCellValue("物料编码");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 3);celll.setCellValue("物料描述");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 5);celll.setCellValue("单位");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 6);celll.setCellValue("计划数量");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 7);celll.setCellValue("总金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 8);celll.setCellValue("实际金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 9);celll.setCellValue("实际总金额");celll.setCellStyle(styleTwo);
        celll = rowMtit.createCell((short) 10);celll.setCellValue("备注");celll.setCellStyle(styleTwo);

        if(mmresult.size()>0){
            int sizemat=mmresult.size()+rowWF+2;
            int insize=rowWF+2;
            for(int j=insize;j<sizemat;j++){
                sheet.addMergedRegion(new CellRangeAddress(j,j,3,4));//row物料标题行
                HSSFRow rowmat = sheet.createRow((int) j);

                int b=j-rowWF-2;
                rowmat.createCell((short) 0).setCellValue(b+1);
                rowmat.createCell((short) 1).setCellValue(mmresult.get(b).get("V_ACTIVITY").toString().equals("") ? "" :mmresult.get(b).get("V_ACTIVITY").toString());
                rowmat.createCell((short) 2).setCellValue(mmresult.get(b).get("V_MATERIALCODE").toString().equals("") ? "" :mmresult.get(b).get("V_MATERIALCODE").toString());
                rowmat.createCell((short) 3).setCellValue(mmresult.get(b).get("V_MATERIALNAME").toString().equals("") ? "" :mmresult.get(b).get("V_MATERIALNAME").toString());
                rowmat.createCell((short) 5).setCellValue(mmresult.get(b).get("V_UNIT").toString().equals("") ? "" :mmresult.get(b).get("V_UNIT").toString());
                rowmat.createCell((short) 6).setCellValue(mmresult.get(b).get("I_PLANAMOUNT").toString().equals("") ? "" :mmresult.get(b).get("I_PLANAMOUNT").toString());
                rowmat.createCell((short) 7).setCellValue(mmresult.get(b).get("F_PLANMONEY").toString().equals("") ? "" :mmresult.get(b).get("F_PLANMONEY").toString());
                rowmat.createCell((short) 8).setCellValue(mmresult.get(b).get("I_ACTUALAMOUNT").toString().equals("") ? "" :mmresult.get(b).get("I_ACTUALAMOUNT").toString());
                rowmat.createCell((short) 9).setCellValue(mmresult.get(b).get("F_ACTUALMONEY").toString().equals("") ? "" :mmresult.get(b).get("F_ACTUALMONEY").toString());
                rowmat.createCell((short) 10).setCellValue("");
                for(int n=0;n<=10;n++){
                    sheet.addMergedRegion(new CellRangeAddress(j,j,n,n));
                    RegionUtil.setBorderBottom(1, new CellRangeAddress(j,j,n,n), sheet,wb);
                    RegionUtil.setBorderRight(1, new CellRangeAddress(j,j,n,n), sheet,wb);
                    RegionUtil.setBorderTop(1, new CellRangeAddress(j,j,n,n), sheet,wb);
                }
                sheet.addMergedRegion(new CellRangeAddress(j,j,3,4));
                RegionUtil.setBorderBottom(1, new CellRangeAddress(j,j,3,4), sheet,wb);
                RegionUtil.setBorderRight(1, new CellRangeAddress(j,j,3,4), sheet,wb);
                RegionUtil.setBorderTop(1, new CellRangeAddress(j,j,3,4), sheet,wb);
            }
        }
        try {
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment; filename="
                    + URLEncoder.encode("工单打印Excel.xls", "UTF-8"));
            OutputStream out = response.getOutputStream();

            wb.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

样式:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用以下代码来设置 DataGridView 的列标题单元格宽度: ``` dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; //设置不自动换行 dataGridView1.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; //设置水平居中对齐 dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold); //设置字体样式、大小和加粗 dataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Yellow; //设置背景颜色 dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Red; //设置前景颜色 dataGridView1.Columns[0].HeaderCell.Style.SelectionBackColor = Color.Blue; //设置选中时的背景颜色 dataGridView1.Columns[0].HeaderCell.Style.SelectionForeColor = Color.White; //设置选中时的前景颜色 dataGridView1.Columns[0].HeaderCell.Style.WrapMode = DataGridViewTriState.False; //设置不自动换行 dataGridView1.Columns[0].HeaderCell.Style.Padding = new Padding(5); //设置内边距 dataGridView1.Columns[0].HeaderCell.Style.BorderWidth = 1; //设置边框宽度 dataGridView1.Columns[0].HeaderCell.Style.BorderColor = Color.Black; //设置边框颜色 dataGridView1.Columns[0].HeaderCell.Style.BorderStyle = DataGridViewCellBorderStyle.Single; //设置边框样式 dataGridView1.Columns[0].Width = 100; //设置列宽度 ``` 以上代码中的 `dataGridView1` 表示你的 DataGridView 对象,`Columns[0]` 表示第一列,你可以根据需要修改列的索引号和相应的属性值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值