• jxl解析多个excel工作表-java代码


        @Override
        public ResultBean txImportDqKpi(String filePath)
        {
            ResultBean rb = new ResultBean();
            int success = 0, fail = 0;
            StringBuffer sb = new StringBuffer();
            try
            {
                File file = new File(fsConfig.getFsRoot() + filePath);
                Workbook wb = Workbook.getWorkbook(new FileInputStream(file));
                Sheet sheet = wb.getSheet(0);
                int rows = sheet.getRows();
                List<SchDqKpiHead> dqKpiHeadList = new ArrayList<SchDqKpiHead>();
                SchDqKpiHead dqKpiHead = null;
                for (int row = 2; row < rows; row++)
                {
                    if (!TopUtil.isValidValue(sheet.getCell(0, row).getContents()))
                    {
                        continue;
                    }
                    try
                    {
                        dqKpiHead = new SchDqKpiHead();
                        dqKpiHead.setHeadId(new Long(this.checkIfNullToZero(sheet.getCell(0, row).getContents())));
                        dqKpiHead.setDqKpiCode(sheet.getCell(1, row).getContents());
                        dqKpiHead.setDqKpiName(sheet.getCell(2, row).getContents());
                        dqKpiHead.setDqKpiDesc(sheet.getCell(3, row).getContents());
                        dqKpiHead.setCalculateSql(sheet.getCell(4, row).getContents());
                        dqKpiHead.setAlterCondition(sheet.getCell(5, row).getContents());
                        dqKpiHead.setAlterMsg(sheet.getCell(6, row).getContents());
                        dqKpiHead.setObjectType(sheet.getCell(7, row).getContents());
                        dqKpiHead.setDqKpiType(sheet.getCell(8, row).getContents());
                        dqKpiHead.setKpiStatus(sheet.getCell(9, row).getContents());
                        dqKpiHead.setObjectCode(sheet.getCell(10, row).getContents());
                        dqKpiHead.setRunPosition(sheet.getCell(11, row).getContents());
                        dqKpiHead.setRunOrder(sheet.getCell(12, row).getContents());
                        dqKpiHead.setPonderance(sheet.getCell(13, row).getContents());
                        dqKpiHead.setEnabledFlag(sheet.getCell(14, row).getContents());
    
                        dqKpiHead.setCreatedBy("import");
                        dqKpiHead.setCreatedDate(new Date());
                        dqKpiHead.setLastUpdatedBy("import");
                        dqKpiHead.setLastUpdatedDate(new Date());
    
                        dqKpiHeadList.add(dqKpiHead);
                        success++;
                    } catch (Exception e)
                    {
                        log.error(e);
                        e.printStackTrace();
                        fail++;
                        continue;
                    }
                }
                sb.append("表:SCH_DQ_KPI_HEAD 成功:" + success + "条,失败:" + fail + "条</br>");
                success = fail = 0;
                coreDao.saveOrUpdate(dqKpiHeadList);
                rb.setData(dqKpiHeadList);
    
                sheet = wb.getSheet(1);
                rows = sheet.getRows();
                List<SchDqKpiLine> dqKpiLineList = new ArrayList<SchDqKpiLine>();
                SchDqKpiLine dqKpiLine = null;
                for (int row = 2; row < rows; row++)
                {
                    if (!TopUtil.isValidValue(sheet.getCell(0, row).getContents()))
                    {
                        continue;
                    }
                    try
                    {
                        dqKpiLine = new SchDqKpiLine();
                        dqKpiLine.setLineId(new Long(this.checkIfNullToZero(sheet.getCell(0, row).getContents())));
                        dqKpiLine.setHeadId(new Long(this.checkIfNullToZero(sheet.getCell(1, row).getContents())));
                        dqKpiLine.setDtlCode(sheet.getCell(2, row).getContents());
                        dqKpiLine.setDtlName(sheet.getCell(3, row).getContents());
                        dqKpiLine.setExecSql(sheet.getCell(4, row).getContents());
                        dqKpiLine.setAttribute1(sheet.getCell(5, row).getContents());
                        dqKpiLine.setAttribute2(sheet.getCell(6, row).getContents());
                        dqKpiLine.setAttribute3(sheet.getCell(7, row).getContents());
                        dqKpiLine.setAttribute4(sheet.getCell(8, row).getContents());
                        dqKpiLine.setAttribute5(sheet.getCell(9, row).getContents());
                        dqKpiLine.setAttribute6(sheet.getCell(10, row).getContents());
                        dqKpiLine.setAttribute7(sheet.getCell(11, row).getContents());
                        dqKpiLine.setAttribute8(sheet.getCell(12, row).getContents());
                        dqKpiLine.setAttribute9(sheet.getCell(13, row).getContents());
                        dqKpiLine.setAttribute10(sheet.getCell(14, row).getContents());
                        dqKpiLine.setEnabledFlag(sheet.getCell(15, row).getContents());
    
                        dqKpiLine.setCreatedBy("import");
                        dqKpiLine.setCreatedDate(new Date());
                        dqKpiLine.setLastUpdatedBy("import");
                        dqKpiLine.setLastUpdatedDate(new Date());
    
                        dqKpiLineList.add(dqKpiLine);
                        success++;
                    } catch (Exception e)
                    {
                        log.error(e);
                        e.printStackTrace();
                        fail++;
                        continue;
                    }
                }
                sb.append("表:SCH_DQ_KPI_LINE 成功:" + success + "条,失败:" + fail + "条</br>");
                success = fail = 0;
                coreDao.saveOrUpdate(dqKpiLineList);
                rb.setMessage(sb.toString());
            } catch (Exception e)
            {
                log.error(e);
                e.printStackTrace();
                rb.setSuccess(false);
                rb.setMessage(e.getMessage());
            }
            return rb;
        }

    这是jxl解析excel(多个子表)的代码,权当记录,怕忘记。

     原创文章如转载,请注明出处

  • 相关阅读:
    vi常用操作
    Python练习题
    Jmeter也能IP欺骗!
    mysql主从配置
    性能测试之mysql监控、优化
    Git 命令
    Chrome——F12 谷歌开发者工具详解
    Appscan
    微信群发红包抢红包设计测试用例
    MySQL基础篇(1)SQL基础
  • 原文地址:https://www.cnblogs.com/pongyc/p/7514580.html
Copyright © 2020-2023  润新知