標籤:查詢 時間 defaults 包含 sip [] work 表格 資料
/** * 匯出清單 eb中 firstRow(EntityBean) 列表第一行資料,索引值對(不包含序號)例:("name","姓名") * data(EntityBean[]) 列表資料 * * @author zhaojq */public PR exportData(EntityBean eb){if (eb == null){return new PR(0, "參數為空白", null);}try{// 建立表格檔案String rootpath = NameedPathUtil.getDefaultSavePath();String filepath = "/LSIP/excel/";File f = new File(rootpath + filepath);// 建立檔案夾路徑// 如果檔案夾不存在則建立if (!f.exists() && !f.isDirectory()){f.mkdirs();}String filename = System.currentTimeMillis() + ".xls";File file = new File(f, filename);if (!file.exists()){file.createNewFile();}EntityBean firstRow = eb.getBean("firstRow");EntityBean[] data = eb.getBeans("data");// 建立工作薄WritableWorkbook workbook = Workbook.createWorkbook(file);// 建立新的一頁WritableSheet sheet = workbook.createSheet("第1頁", 0);// Label(列,行,資料)// 第一行String[] keys = firstRow.getBeanFieldNames();// 擷取表頭keyfor (int i = 0; i < keys.length; i++){Label firstrow = new Label(i, 0, firstRow.getString(keys[i]));sheet.addCell(firstrow);}// 建立資料行for (int i = 0; i < data.length; i++){for (int j = 0; j < keys.length; j++){Label datarow = new Label(j, 1 + i, data[i].getString(keys[j]));sheet.addCell(datarow);}}workbook.write();workbook.close();String contex = LSIPConfigUtil.getDownloadConfig();return new PR(1, "", String.format("%sLEAP/Download/default%s%s", contex, filepath, filename));}catch (Exception e){Global.getInstance().LogError(e);return new PR(0, e.toString(), null);}}
/** * 考試清單匯出 */public PR exportExamQD(SearchParameters spar){try{EntityBean par = new EntityBean();spar.setOrder("seatno");spar.setPageSize(10000);EntityBean[] list = examsearch4eb(spar);if(StringUtil.IsNullOrEmpty(list))return new PR(1,"查詢結果為空白",null);//第一行資料EntityBean firstBean = new EntityBean();firstBean.set("areaname", "地區");firstBean.set("examroomid", "考試中心");firstBean.set("examsubject", "考試科目");firstBean.set("examtime", "考試時間");firstBean.set("cardno", "證件號碼");firstBean.set("personname", "姓名");firstBean.set("mobile", "手機號");firstBean.set("examstate", "考試報名狀態");firstBean.set("examscore", "成績");firstBean.set("seatno", "座位號");firstBean.set("address", "郵寄地址");for(int i = 0;i < list.length;i++){EntityBean _data = list[i];String areaname = zonepro.getInstance().getAreaName(_data.getString("areaid"));_data.set("areaname", areaname);if(_data.getString("examroomid") != null){leapcodevalue _examroomid= CodeTypeCache.getInstance().getCodeValue("LSIP_examroom",_data.getString("examroomid"));if(_examroomid != null)_data.set("examroomid", _examroomid.getcodevalue());}if(_data.getString("examsubject") != null){leapcodevalue _examsubject= CodeTypeCache.getInstance().getCodeValue("LSIP_examsubject",_data.getString("examsubject"));if(_examsubject != null)_data.set("examsubject", _examsubject.getcodevalue());}if(_data.getString("examtype") != null){leapcodevalue _examtype= CodeTypeCache.getInstance().getCodeValue("LSIP_examtype",_data.getString("examtype"));if(_examtype != null)_data.set("examtype", _examtype.getcodevalue());}if(_data.getString("examstate") != null){leapcodevalue _examstate= CodeTypeCache.getInstance().getCodeValue("LSIP_examstate",_data.getString("examstate"));if(_examstate != null)_data.set("examstate", _examstate.getcodevalue());}if(_data.getString("examtime") != null){_data.set("examtime", _data.getString("examtime").substring(0, 16));}}par.set("firstRow", firstBean);par.set("data", list);return new BaseDataService().exportData(par);}catch (Exception e){Global.getInstance().LogError(e);return new PR(0,e.getMessage(),null);}}
java實現excel表格匯出資料