java操作excel的方法
本文實(shí)例講述了java操作excel的方法。分享給大家供大家參考。具體如下:
WritableWorkbook workbook = Workbook.createWorkbook(new File("d:\\output.xls")); WritableSheet sheet = workbook.createSheet("項(xiàng)目簡(jiǎn)報(bào)", 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("宋體"), 12,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 //項(xiàng)目簡(jiǎn)介信息 sheet.addCell(new Label(0, 0, projReportParam.getProj_name() + "項(xiàng)目簡(jiǎn)報(bào)",font18Subject)); sheet.mergeCells(0, 0, 5, 0); sheet.addCell(new Label(0,1,"項(xiàng)目編號(hào)",font12Subject)); sheet.addCell(new Label(1,1,projReportParam.getProj_code(),font12SubjectNoBold)); sheet.addCell(new Label(2,1,"項(xiàng)目經(jīng)理",font12Subject)); sheet.addCell(new Label(3,1,projReportParam.getEmp_name(),font12SubjectNoBold)); sheet.addCell(new Label(4,1,"立項(xiàng)部門",font12Subject)); sheet.addCell(new Label(5,1,projReportParam.getDept_name(),font12SubjectNoBold)); sheet.addCell(new Label(0,2,"計(jì)劃發(fā)生成本",font12Subject)); sheet.addCell(new Label(1,2,projReportParam.getPlan_cost(),font12SubjectNoBold)); sheet.addCell(new Label(2,2,"實(shí)際發(fā)生成本",font12Subject)); sheet.addCell(new Label(3,2,projReportParam.getActual_cost(),font12SubjectNoBold)); sheet.addCell(new Label(0,3,"項(xiàng)目簡(jiǎn)介",font12Subject)); sheet.addCell(new Label(1,3,projReportParam.getProj_desc(),font12SubjectNoBold)); sheet.mergeCells(1, 3, 5, 3); //項(xiàng)目簡(jiǎn)介信息 end //里程碑 sheet.addCell(new Label(0,5,"里程碑",font18Subject)); sheet.mergeCells(0, 5, 5, 5); sheet.addCell(new Label(0,6,"階段名稱",font12Subject)); sheet.addCell(new Label(1,6,"任務(wù)名稱",font12Subject)); sheet.addCell(new Label(2,6,"實(shí)施人",font12Subject)); sheet.addCell(new Label(3,6,"計(jì)劃起止時(shí)間",font12Subject)); sheet.addCell(new Label(4,6,"實(shí)際起止時(shí)間",font12Subject)); sheet.addCell(new Label(5,6,"狀態(tài)",font12Subject)); int i = 7;//行 for(ProjReportParamMInfo projReportParamMInfo : projReportParam.getProjReportParamMInfoList()){ sheet.addCell(new Label(0,i,projReportParamMInfo.getPharse_name(),font12SubjectNoBold)); sheet.addCell(new Label(1,i,projReportParamMInfo.getTask_item(),font12SubjectNoBold)); sheet.addCell(new Label(2,i,projReportParamMInfo.getEmp_name(),font12SubjectNoBold)); sheet.addCell(new Label(3,i,Utils.formatDate(projReportParamMInfo.getTask_plan_sd()) + " / " + Utils.formatDate(projReportParamMInfo.getTask_plan_fd()),font12SubjectNoBold)); sheet.addCell(new Label(4,i,Utils.formatDate(projReportParamMInfo.getTask_actual_sd()) + " / " + Utils.formatDate(projReportParamMInfo.getTask_actual_fd()),font12SubjectNoBold)); sheet.addCell(new Label(5,i,projReportParamMInfo.getTask_state(),font12SubjectNoBold)); i++; } //里程碑 end //項(xiàng)目組成員及干系人 int j = 1+i;//行 sheet.addCell(new Label(0,j,"項(xiàng)目組成員及干系人",font18Subject)); sheet.mergeCells(0, j, 5, j); sheet.addCell(new Label(0,j+1,"序號(hào)",font12Subject)); sheet.addCell(new Label(1,j+1,"姓名",font12Subject)); sheet.addCell(new Label(2,j+1,"角色",font12Subject)); sheet.addCell(new Label(3,j+1,"進(jìn)入項(xiàng)目組時(shí)間",font12Subject)); sheet.addCell(new Label(4,j+1,"離開項(xiàng)目組時(shí)間",font12Subject)); sheet.addCell(new Label(5,j+1,"累計(jì)工時(shí)",font12Subject)); int m = 1;//序號(hào) int n = j+2;//行 for(ProjReportParamHRInfo projReportParamHRInfo : projReportParam.getProjReportParamHRInfoList()){ sheet.addCell(new Label(0,n,m+"",font12SubjectNoBold)); sheet.addCell(new Label(1,n,projReportParamHRInfo.getEmp_name(),font12SubjectNoBold)); sheet.addCell(new Label(2,n,projReportParamHRInfo.getRole_name(),font12SubjectNoBold)); sheet.addCell(new Label(3,n,Utils.formatDate(projReportParamHRInfo.getHr_start_date()),font12SubjectNoBold)); sheet.addCell(new Label(4,n,Utils.formatDate(projReportParamHRInfo.getHr_release_date()),font12SubjectNoBold)); sheet.addCell(new Label(5,n,projReportParamHRInfo.getTotal_manhour(),font12SubjectNoBold)); m++; n++; } //項(xiàng)目組成員及干系人 end //本期工作內(nèi)容 int k = n + 1;//行 sheet.addCell(new Label(0,k,"本期工作內(nèi)容("+startDate+"至"+endDate+")",font18Subject)); sheet.mergeCells(0, k, 6, k); sheet.addCell(new Label(0,k+1,"任務(wù)編號(hào)",font12Subject)); sheet.addCell(new Label(1,k+1,"任務(wù)名稱",font12Subject)); sheet.addCell(new Label(2,k+1,"計(jì)劃起止時(shí)間",font12Subject)); sheet.addCell(new Label(3,k+1,"實(shí)際起止時(shí)間",font12Subject)); sheet.addCell(new Label(4,k+1,"計(jì)劃工時(shí)",font12Subject)); sheet.addCell(new Label(5,k+1,"實(shí)際工時(shí)",font12Subject)); sheet.addCell(new Label(6,k+1,"實(shí)施人員",font12Subject)); int p = k + 2;//行 for(ProjReportParamTaskInfo projReportParamTaskInfo : projReportParam.getThisProjReportParamTaskInfoList()){ sheet.addCell(new Label(0,p,projReportParamTaskInfo.getTask_code(),font12SubjectNoBold)); sheet.addCell(new Label(1,p,projReportParamTaskInfo.getTask_item(),font12SubjectNoBold)); sheet.addCell(new Label(2,p,Utils.formatDate(projReportParamTaskInfo.getTask_plan_sd()) + " / " + Utils.formatDate(projReportParamTaskInfo.getTask_plan_fd()),font12SubjectNoBold)); sheet.addCell(new Label(3,p,Utils.formatDate(projReportParamTaskInfo.getTask_actual_sd()) + " / " + Utils.formatDate(projReportParamTaskInfo.getTask_actual_fd()),font12SubjectNoBold)); sheet.addCell(new Label(4,p,projReportParamTaskInfo.getTask_plan_manhour(),font12SubjectNoBold)); sheet.addCell(new Label(5,p,projReportParamTaskInfo.getTask_actual_manhour(),font12SubjectNoBold)); sheet.addCell(new Label(6,p,projReportParamTaskInfo.getPlan_emp_name(),font12SubjectNoBold)); p++; } //本期工作內(nèi)容 end //下周工作內(nèi)容 int q = p + 1;//行 sheet.addCell(new Label(0,q,"下周工作內(nèi)容",font18Subject)); sheet.mergeCells(0, q, 5, q); sheet.addCell(new Label(0,q+1,"任務(wù)編號(hào)",font12Subject)); sheet.addCell(new Label(1,q+1,"任務(wù)名稱",font12Subject)); sheet.addCell(new Label(2,q+1,"計(jì)劃開始時(shí)間",font12Subject)); sheet.addCell(new Label(3,q+1,"計(jì)劃結(jié)束時(shí)間",font12Subject)); sheet.addCell(new Label(4,q+1,"計(jì)劃工時(shí)",font12Subject)); sheet.addCell(new Label(5,q+1,"實(shí)施人員",font12Subject)); int r = q + 2; for(ProjReportParamTaskInfo projReportParamTaskInfo : projReportParam.getNextProjReportParamTaskInfoList()){ sheet.addCell(new Label(0,r,projReportParamTaskInfo.getTask_code(),font12SubjectNoBold)); sheet.addCell(new Label(1,r,projReportParamTaskInfo.getTask_item(),font12SubjectNoBold)); sheet.addCell(new Label(2,r,Utils.formatDate(projReportParamTaskInfo.getTask_plan_sd()),font12SubjectNoBold)); sheet.addCell(new Label(3,r,Utils.formatDate(projReportParamTaskInfo.getTask_plan_fd()),font12SubjectNoBold)); sheet.addCell(new Label(4,r,projReportParamTaskInfo.getTask_plan_manhour(),font12SubjectNoBold)); sheet.addCell(new Label(5,r,projReportParamTaskInfo.getPlan_emp_name(),font12SubjectNoBold)); r++; } //下周工作內(nèi)容 end //項(xiàng)目存在的問(wèn)題及解決 int s = r + 1;//行 sheet.addCell(new Label(0,s,"項(xiàng)目存在的問(wèn)題及解決",font18Subject)); sheet.mergeCells(0, s, 8, s); sheet.addCell(new Label(0,s+1,"識(shí)別日期",font12Subject)); sheet.addCell(new Label(1,s+1,"問(wèn)題描述",font12Subject)); sheet.addCell(new Label(2,s+1,"所屬風(fēng)險(xiǎn)",font12Subject)); sheet.addCell(new Label(3,s+1,"解決方法",font12Subject)); sheet.addCell(new Label(4,s+1,"解決人",font12Subject)); sheet.addCell(new Label(5,s+1,"計(jì)劃開始時(shí)間",font12Subject)); sheet.addCell(new Label(6,s+1,"計(jì)劃完成時(shí)間",font12Subject)); sheet.addCell(new Label(7,s+1,"問(wèn)題狀態(tài)",font12Subject)); sheet.addCell(new Label(8,s+1,"總結(jié)",font12Subject)); int t = s + 2;//行 for(ProjReportParamRiskInfo projReportParamRiskInfo : projReportParam.getProjReportParamRiskInfoList()){ sheet.addCell(new Label(0,t,Utils.formatDate(projReportParamRiskInfo.getSts_date()),font12SubjectNoBold)); sheet.addCell(new Label(1,t,projReportParamRiskInfo.getProj_issue_item(),font12SubjectNoBold)); sheet.addCell(new Label(2,t,projReportParamRiskInfo.getProj_risk_item(),font12SubjectNoBold)); sheet.addCell(new Label(3,t,projReportParamRiskInfo.getIssue_resolve_method(),font12SubjectNoBold)); sheet.addCell(new Label(4,t,projReportParamRiskInfo.getIssue_resolve_emp(),font12SubjectNoBold)); sheet.addCell(new Label(5,t,Utils.formatDate(projReportParamRiskInfo.getIssue_plan_date()),font12SubjectNoBold)); sheet.addCell(new Label(6,t,Utils.formatDate(projReportParamRiskInfo.getIssue_actual_date()),font12SubjectNoBold)); sheet.addCell(new Label(7,t,projReportParamRiskInfo.getIssue_state(),font12SubjectNoBold)); sheet.addCell(new Label(8,t,projReportParamRiskInfo.getIssue_summarize(),font12SubjectNoBold)); t++; } //項(xiàng)目存在的問(wèn)題及解決 end workbook.write(); workbook.close(); //生成項(xiàng)目簡(jiǎn)報(bào)的程序
希望本文所述對(duì)大家的java程序設(shè)計(jì)有所幫助。
相關(guān)文章
Java設(shè)置httponly?cookie的實(shí)現(xiàn)示例
本文主要介紹了Java設(shè)置httponly?cookie的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08用Java實(shí)現(xiàn)小球碰壁反彈的簡(jiǎn)單實(shí)例(算法十分簡(jiǎn)單)
下面小編就為大家?guī)?lái)一篇用Java實(shí)現(xiàn)小球碰壁反彈的簡(jiǎn)單實(shí)例(算法十分簡(jiǎn)單)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)學(xué)生管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01JDK都出到14了,你有什么理由不會(huì)函數(shù)式編程(推薦)
這篇文章主要介紹了JDK都出到14了,你有什么理由不會(huì)函數(shù)式編程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05IntelliJ IDEA 刷題利器 LeetCode 插件詳解
這篇文章主要介紹了IntelliJ IDEA 刷題利器 LeetCode 插件,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08SpringBoot Security前后端分離登錄驗(yàn)證的實(shí)現(xiàn)
這篇文章主要介紹了SpringBoot Security前后端分離登錄驗(yàn)證的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Spring的Bean注入解析結(jié)果BeanDefinition詳解
這篇文章主要介紹了Spring的Bean注入解析結(jié)果BeanDefinition詳解,BeanDefinition描述了一個(gè)bean實(shí)例,擁有屬性值、構(gòu)造參數(shù)值和具體實(shí)現(xiàn)的其他信息,其是一個(gè)bean的元數(shù)據(jù),xml中配置的bean元素會(huì)被解析成BeanDefinition對(duì)象,需要的朋友可以參考下2023-12-12