加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java操作excel的方法

发布时间:2020-12-14 17:42:11 所属栏目:Java 来源:网络整理
导读:本篇章节讲解java操作excel的方法。供大家参考研究。具体如下: WritableWorkbook workbook = Workbook.createWorkbook(new File("d:output.xls")); WritableSheet sheet = workbook.createSheet("项目简报",0); //样式 WritableFont sonti18font

本篇章节讲解java操作excel的方法。分享给大家供大家参考。具体如下:

WritableWorkbook workbook = Workbook.createWorkbook(new File("d:output.xls")); 
 WritableSheet sheet = workbook.createSheet("项目简报",0); 
 //样式 
 WritableFont sonti18font = new WritableFont(WritableFont.createFont("宋体"),18,WritableFont.BOLD); 
 WritableFont sonti12font = new WritableFont(WritableFont.createFont("宋体"),12,WritableFont.BOLD); 
 WritableFont sonti12fontNoBold = new WritableFont(WritableFont.createFont("宋体"),WritableFont.NO_BOLD); 
 WritableCellFormat font18Subject = new WritableCellFormat (sonti18font); 
 WritableCellFormat font12Subject = new WritableCellFormat (sonti12font); 
 WritableCellFormat font12SubjectNoBold = new WritableCellFormat (sonti12fontNoBold); 
 font18Subject.setAlignment(jxl.format.Alignment.CENTRE); 
 font18Subject.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);  
 font18Subject.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);  
 font12Subject.setAlignment(jxl.format.Alignment.LEFT); 
 font12Subject.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);  
 font12Subject.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN); 
 font12SubjectNoBold.setAlignment(jxl.format.Alignment.LEFT); 
 font12SubjectNoBold.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);  
 font12SubjectNoBold.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN); 
 //样式 end 
 //项目简介信息 
 sheet.addCell(new Label(0,projReportParam.getProj_name() + "项目简报",font18Subject)); 
 sheet.mergeCells(0,5,0); 
 sheet.addCell(new Label(0,1,"项目编号",font12Subject)); 
 sheet.addCell(new Label(1,projReportParam.getProj_code(),font12SubjectNoBold)); 
 sheet.addCell(new Label(2,"项目经理",font12Subject)); 
 sheet.addCell(new Label(3,projReportParam.getEmp_name(),font12SubjectNoBold)); 
 sheet.addCell(new Label(4,"立项部门",font12Subject)); 
 sheet.addCell(new Label(5,projReportParam.getDept_name(),font12SubjectNoBold)); 
 sheet.addCell(new Label(0,2,"计划发生成本",projReportParam.getPlan_cost(),"实际发生成本",projReportParam.getActual_cost(),3,"项目简介",projReportParam.getProj_desc(),font12SubjectNoBold)); 
 sheet.mergeCells(1,3); 
 //项目简介信息 end 
 //里程碑 
 sheet.addCell(new Label(0,"里程碑",5); 
 sheet.addCell(new Label(0,6,"阶段名称","任务名称",font12Subject)); 
 sheet.addCell(new Label(2,"实施人","计划起止时间",font12Subject)); 
 sheet.addCell(new Label(4,"实际起止时间","状态",font12Subject)); 
 int i = 7;//行 
 for(ProjReportParamMInfo projReportParamMInfo : projReportParam.getProjReportParamMInfoList()){ 
  sheet.addCell(new Label(0,i,projReportParamMInfo.getPharse_name(),font12SubjectNoBold)); 
  sheet.addCell(new Label(1,projReportParamMInfo.getTask_item(),font12SubjectNoBold)); 
  sheet.addCell(new Label(2,projReportParamMInfo.getEmp_name(),font12SubjectNoBold)); 
  sheet.addCell(new Label(3,Utils.formatDate(projReportParamMInfo.getTask_plan_sd()) + " / " + Utils.formatDate(projReportParamMInfo.getTask_plan_fd()),font12SubjectNoBold)); 
  sheet.addCell(new Label(4,Utils.formatDate(projReportParamMInfo.getTask_actual_sd()) + " / " + Utils.formatDate(projReportParamMInfo.getTask_actual_fd()),font12SubjectNoBold)); 
  sheet.addCell(new Label(5,projReportParamMInfo.getTask_state(),font12SubjectNoBold)); 
  i++; 
 } 
 //里程碑 end 
 //项目组成员及干系人 
 int j = 1+i;//行 
 sheet.addCell(new Label(0,j,"项目组成员及干系人",j); 
 sheet.addCell(new Label(0,j+1,"序号","姓名","角色","进入项目组时间","离开项目组时间","累计工时",font12Subject)); 
 int m = 1;//序号 
 int n = j+2;//行 
 for(ProjReportParamHRInfo projReportParamHRInfo : projReportParam.getProjReportParamHRInfoList()){ 
  sheet.addCell(new Label(0,n,m+"",projReportParamHRInfo.getEmp_name(),projReportParamHRInfo.getRole_name(),Utils.formatDate(projReportParamHRInfo.getHr_start_date()),Utils.formatDate(projReportParamHRInfo.getHr_release_date()),projReportParamHRInfo.getTotal_manhour(),font12SubjectNoBold)); 
  m++; 
  n++; 
 } 
 //项目组成员及干系人 end 
 //本期工作内容 
 int k = n + 1;//行 
 sheet.addCell(new Label(0,k,"本期工作内容("+startDate+"至"+endDate+")",k); 
 sheet.addCell(new Label(0,k+1,"任务编号","计划工时","实际工时",font12Subject)); 
 sheet.addCell(new Label(6,"实施人员",font12Subject)); 
 int p = k + 2;//行 
 for(ProjReportParamTaskInfo projReportParamTaskInfo : projReportParam.getThisProjReportParamTaskInfoList()){ 
  sheet.addCell(new Label(0,p,projReportParamTaskInfo.getTask_code(),projReportParamTaskInfo.getTask_item(),Utils.formatDate(projReportParamTaskInfo.getTask_plan_sd()) + " / " + Utils.formatDate(projReportParamTaskInfo.getTask_plan_fd()),Utils.formatDate(projReportParamTaskInfo.getTask_actual_sd()) + " / " + Utils.formatDate(projReportParamTaskInfo.getTask_actual_fd()),projReportParamTaskInfo.getTask_plan_manhour(),projReportParamTaskInfo.getTask_actual_manhour(),font12SubjectNoBold)); 
  sheet.addCell(new Label(6,projReportParamTaskInfo.getPlan_emp_name(),font12SubjectNoBold)); 
  p++; 
 } 
 //本期工作内容 end 
 //下周工作内容 
 int q = p + 1;//行 
 sheet.addCell(new Label(0,q,"下周工作内容",q); 
 sheet.addCell(new Label(0,q+1,"计划开始时间","计划结束时间",font12Subject)); 
 int r = q + 2; 
 for(ProjReportParamTaskInfo projReportParamTaskInfo : projReportParam.getNextProjReportParamTaskInfoList()){ 
  sheet.addCell(new Label(0,r,Utils.formatDate(projReportParamTaskInfo.getTask_plan_sd()),Utils.formatDate(projReportParamTaskInfo.getTask_plan_fd()),font12SubjectNoBold)); 
  r++; 
 } 
 //下周工作内容 end 
 //项目存在的问题及解决 
 int s = r + 1;//行 
 sheet.addCell(new Label(0,s,"项目存在的问题及解决",8,s); 
 sheet.addCell(new Label(0,s+1,"识别日期","问题描述","所属风险","解决方法","解决人","计划完成时间",font12Subject)); 
 sheet.addCell(new Label(7,"问题状态",font12Subject)); 
 sheet.addCell(new Label(8,"总结",font12Subject)); 
 int t = s + 2;//行 
 for(ProjReportParamRiskInfo projReportParamRiskInfo : projReportParam.getProjReportParamRiskInfoList()){ 
  sheet.addCell(new Label(0,t,Utils.formatDate(projReportParamRiskInfo.getSts_date()),projReportParamRiskInfo.getProj_issue_item(),projReportParamRiskInfo.getProj_risk_item(),projReportParamRiskInfo.getIssue_resolve_method(),projReportParamRiskInfo.getIssue_resolve_emp(),Utils.formatDate(projReportParamRiskInfo.getIssue_plan_date()),Utils.formatDate(projReportParamRiskInfo.getIssue_actual_date()),font12SubjectNoBold)); 
  sheet.addCell(new Label(7,projReportParamRiskInfo.getIssue_state(),font12SubjectNoBold)); 
  sheet.addCell(new Label(8,projReportParamRiskInfo.getIssue_summarize(),font12SubjectNoBold)); 
  t++; 
 } 
 //项目存在的问题及解决 end 
 workbook.write(); 
 workbook.close(); 
//生成项目简报的程序

希望本文所述对大家的java程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读