导出
如果不選擇,則導出全部內容;如果選擇,獲取選擇的id,通過id導出所選擇的內容
dcRecord : function() {var me = this;var record = me.getSelectionModel().getSelection(); // 取得要導出行的內容var A00 = [];var A0101 = [];if (record.length != 0) {for (var i = 0; i < record.length; i++) {A00.push(record[i].get("HDID"));A0101.push(record[i].get("姓名"));}var same = 2;var SheetName = "";for (var i = 0; i < A0101.length; i++) {if (A0101[i].indexOf(SheetName) != -1 && SheetName != "") {A0101[i] = A0101[i] + "(" + same + ")";same++;} else {same = 2;SheetName = A0101[i];}}}Ext.DownLoad({url : "/zgzhzd/zzgzlxb/Zzgzlxb/exportExcelMC?stheme=none&ID="+ A00.toString() + "&title=" + A0101.toString()})},
java文件方法
/*** 導出Excel* @return* @throws Exception*/@Actionpublic void exportExcelMC() {HttpServletRequest request = ActionContext.getActionContext().getHttpServletRequest();HttpServletResponse response = ActionContext.getActionContext().getHttpServletResponse();String[] ID = request.getParameter("ID").split(",");String[] title = request.getParameter("title").split(",");String fileName = title+".xls";com.aspose.cells.License lic_excel = new com.aspose.cells.License();lic_excel.setLicense(QueryBase.class.getClassLoader().getResourceAsStream("com/bop/web/xtgl/query/Aspose.lic"));Workbook workbook = new Workbook();// 工作簿List<Map<String, Object>> jsonData = new ArrayList<Map<String,Object>>();try {Worksheet sheet = null;sheet = workbook.getWorksheets().get(0);sheet.setName("第一頁");jsonData = loadTabRecordJLCY(ID);Cells cells = sheet.getCells();// 單元格// 第一行Style style1 = workbook.createStyle();// 新增樣式(數據) style1.setHorizontalAlignment(TextAlignmentType.CENTER);style1.getFont().setSize(11);style1.getFont().setName("宋體"); style1.setBorder(2, 1, Color.getBlack());style1.setBorder(1, 1, Color.getBlack());style1.setBorder(4, 1, Color.getBlack());Style style6 = workbook.createStyle();style6.setHorizontalAlignment(TextAlignmentType.CENTER);style6.getFont().setBold(true);style6.getFont().setSize(22);style6.getFont().setName("宋體"); Style style7 = workbook.createStyle(); //footerstyle7.setBorder(4, 1, Color.getBlack());// 設置表頭cells.get(0, 0).putValue("序號");cells.get(0, 0).setStyle(style1);// 下面匹配數據用cells.get(0, 1).putValue("姓名");cells.get(0, 1).setStyle(style1);cells.get(0, 2).putValue("性別");cells.get(0, 2).setStyle(style1);cells.get(0, 3).putValue("單位");cells.get(0, 3).setStyle(style1);cells.get(0, 4).putValue("職務");cells.get(0, 4).setStyle(style1);cells.get(0, 5).putValue("從事主要業務");cells.get(0, 5).setStyle(style1);cells.get(0, 6).putValue("辦公室電話");cells.get(0, 6).setStyle(style1);cells.get(0, 7).putValue("手機");cells.get(0, 7).setStyle(style1);cells.get(0, 8).putValue("微信號");cells.get(0, 8).setStyle(style1);cells.get(0, 9).putValue("內網郵箱");cells.get(0, 9).setStyle(style1);cells.get(0, 10).putValue("外網郵箱");cells.get(0, 10).setStyle(style1);if (jsonData != null && jsonData.size() > 0) {// 數據格式Style style2 = workbook.createStyle();style2.setHorizontalAlignment(TextAlignmentType.CENTER);style2.getFont().setSize(11);style2.getFont().setName("宋體");for (int k = 0; k < jsonData.size(); k++) {Map<String, Object> datamap = new HashMap<String, Object>();datamap = jsonData.get(k);int index = k + 1;cells.get(index, 0).putValue(index);cells.get(index, 0).setStyle(style2);cells.get(index, 1).putValue(datamap.get("姓名"));cells.get(index, 1).setStyle(style2);cells.get(index, 1 + 1).putValue(datamap.get("性別"));cells.get(index, 1 + 1).setStyle(style2);cells.get(index, 1 + 2).putValue(datamap.get("單位"));cells.get(index, 1 + 2).setStyle(style2);cells.get(index, 1 + 3).putValue(datamap.get("職務"));cells.get(index, 1 + 3).setStyle(style2);cells.get(index, 1 + 4).putValue(datamap.get("從事主要業務"));cells.get(index, 1 + 4).setStyle(style2);cells.get(index, 1 + 5).putValue(datamap.get("辦公室電話"));cells.get(index, 1 + 5).setStyle(style2);cells.get(index, 1 + 6).putValue(datamap.get("手機"));cells.get(index, 1 + 6).setStyle(style2);cells.get(index, 1 + 7).putValue(datamap.get("微信號"));cells.get(index, 1 + 7).setStyle(style2);cells.get(index, 1 + 8).putValue(datamap.get("內網郵箱"));cells.get(index, 1 + 8).setStyle(style2);cells.get(index, 1 + 9).putValue(datamap.get("外網郵箱"));cells.get(index, 1 + 9).setStyle(style2);}sheet.autoFitColumns();}workbook.save(getOutputStream(fileName, response),FileFormatType.EXCEL_2003_XML);} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}private List<Map<String, Object>> loadTabRecordJLCY(String [] ID) {List<Map<String, Object>> JTCY = new ArrayList<Map<String, Object>>(); // 集體成員數據StringBuffer JTCY_sql =new StringBuffer();StringBuffer IDSQL =new StringBuffer("(");for (int i = 0; i < ID.length; i++) {if(ID.length-1!=i){IDSQL.append("'").append(ID[i]).append("',");}else{IDSQL.append("'").append(ID[i]).append("'");}}IDSQL.append(")");JTCY_sql.append( "SELECT ") ;JTCY_sql.append( "z.A0101 AS 姓名, ") ;JTCY_sql.append( "d.DMCPT AS 性別, ") ;JTCY_sql.append( "e.DMCPT AS 單位, ") ;JTCY_sql.append( "ff.ZDYXA0105F AS 職務, ") ;JTCY_sql.append( "'' AS 從事主要業務, ") ;JTCY_sql.append( "b.ZGZH0302 AS 辦公室電話, ") ;JTCY_sql.append( "b.ZGZH0303 AS 手機, ") ;JTCY_sql.append( "b.ZGZH0304 AS 微信號, ") ;JTCY_sql.append( "b.ZGZH0305 AS 內網郵箱, ") ;JTCY_sql.append( "b.ZGZH0306 AS 外網郵箱 ") ;JTCY_sql.append( "FROM A01 z ") ;JTCY_sql.append( "LEFT JOIN ZGZH03 b on z.A00=b.ZGZH0301 ") ;JTCY_sql.append( "LEFT JOIN A01_FUNCTION ff on z.a00=ff.a00 ") ;JTCY_sql.append( "LEFT JOIN GB22611 d on z.A0104 = d.DMCOD ") ;JTCY_sql.append( "LEFT JOIN G099 e on z.ZDYXA0121 = e.DMCOD ") ;JTCY_sql.append( "WHERE z.DELETEFLAG = '0' ") ;if(!(ID[0].isEmpty())){JTCY_sql.append( "AND z.A00 IN ").append(IDSQL.toString());}JTCY_sql.append( "ORDER BY z.CREATETIME desc ") ;JTCY = jdbcOperations.queryForList(JTCY_sql.toString());return JTCY;} /*** * @param fileName* @param response* @return* @throws IOException*/private OutputStream getOutputStream(String fileName,HttpServletResponse response) throws IOException {response.reset();response.setContentType("application/octet-stream");response.addHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("gbk"), "iso-8859-1"));OutputStream out = response.getOutputStream();return out;}
dcRecord : function() {var me = this;var record = me.getSelectionModel().getSelection(); // 取得要導出行的內容var A00 = [];var A0101 = [];if (record.length != 0) {for (var i = 0; i < record.length; i++) {A00.push(record[i].get("HDID"));A0101.push(record[i].get("姓名"));}var same = 2;var SheetName = "";for (var i = 0; i < A0101.length; i++) {if (A0101[i].indexOf(SheetName) != -1 && SheetName != "") {A0101[i] = A0101[i] + "(" + same + ")";same++;} else {same = 2;SheetName = A0101[i];}}}Ext.DownLoad({url : "/zgzhzd/zzgzlxb/Zzgzlxb/exportExcelMC?stheme=none&ID="+ A00.toString() + "&title=" + A0101.toString()})},
java文件方法
/*** 導出Excel* @return* @throws Exception*/@Actionpublic void exportExcelMC() {HttpServletRequest request = ActionContext.getActionContext().getHttpServletRequest();HttpServletResponse response = ActionContext.getActionContext().getHttpServletResponse();String[] ID = request.getParameter("ID").split(",");String[] title = request.getParameter("title").split(",");String fileName = title+".xls";com.aspose.cells.License lic_excel = new com.aspose.cells.License();lic_excel.setLicense(QueryBase.class.getClassLoader().getResourceAsStream("com/bop/web/xtgl/query/Aspose.lic"));Workbook workbook = new Workbook();// 工作簿List<Map<String, Object>> jsonData = new ArrayList<Map<String,Object>>();try {Worksheet sheet = null;sheet = workbook.getWorksheets().get(0);sheet.setName("第一頁");jsonData = loadTabRecordJLCY(ID);Cells cells = sheet.getCells();// 單元格// 第一行Style style1 = workbook.createStyle();// 新增樣式(數據) style1.setHorizontalAlignment(TextAlignmentType.CENTER);style1.getFont().setSize(11);style1.getFont().setName("宋體"); style1.setBorder(2, 1, Color.getBlack());style1.setBorder(1, 1, Color.getBlack());style1.setBorder(4, 1, Color.getBlack());Style style6 = workbook.createStyle();style6.setHorizontalAlignment(TextAlignmentType.CENTER);style6.getFont().setBold(true);style6.getFont().setSize(22);style6.getFont().setName("宋體"); Style style7 = workbook.createStyle(); //footerstyle7.setBorder(4, 1, Color.getBlack());// 設置表頭cells.get(0, 0).putValue("序號");cells.get(0, 0).setStyle(style1);// 下面匹配數據用cells.get(0, 1).putValue("姓名");cells.get(0, 1).setStyle(style1);cells.get(0, 2).putValue("性別");cells.get(0, 2).setStyle(style1);cells.get(0, 3).putValue("單位");cells.get(0, 3).setStyle(style1);cells.get(0, 4).putValue("職務");cells.get(0, 4).setStyle(style1);cells.get(0, 5).putValue("從事主要業務");cells.get(0, 5).setStyle(style1);cells.get(0, 6).putValue("辦公室電話");cells.get(0, 6).setStyle(style1);cells.get(0, 7).putValue("手機");cells.get(0, 7).setStyle(style1);cells.get(0, 8).putValue("微信號");cells.get(0, 8).setStyle(style1);cells.get(0, 9).putValue("內網郵箱");cells.get(0, 9).setStyle(style1);cells.get(0, 10).putValue("外網郵箱");cells.get(0, 10).setStyle(style1);if (jsonData != null && jsonData.size() > 0) {// 數據格式Style style2 = workbook.createStyle();style2.setHorizontalAlignment(TextAlignmentType.CENTER);style2.getFont().setSize(11);style2.getFont().setName("宋體");for (int k = 0; k < jsonData.size(); k++) {Map<String, Object> datamap = new HashMap<String, Object>();datamap = jsonData.get(k);int index = k + 1;cells.get(index, 0).putValue(index);cells.get(index, 0).setStyle(style2);cells.get(index, 1).putValue(datamap.get("姓名"));cells.get(index, 1).setStyle(style2);cells.get(index, 1 + 1).putValue(datamap.get("性別"));cells.get(index, 1 + 1).setStyle(style2);cells.get(index, 1 + 2).putValue(datamap.get("單位"));cells.get(index, 1 + 2).setStyle(style2);cells.get(index, 1 + 3).putValue(datamap.get("職務"));cells.get(index, 1 + 3).setStyle(style2);cells.get(index, 1 + 4).putValue(datamap.get("從事主要業務"));cells.get(index, 1 + 4).setStyle(style2);cells.get(index, 1 + 5).putValue(datamap.get("辦公室電話"));cells.get(index, 1 + 5).setStyle(style2);cells.get(index, 1 + 6).putValue(datamap.get("手機"));cells.get(index, 1 + 6).setStyle(style2);cells.get(index, 1 + 7).putValue(datamap.get("微信號"));cells.get(index, 1 + 7).setStyle(style2);cells.get(index, 1 + 8).putValue(datamap.get("內網郵箱"));cells.get(index, 1 + 8).setStyle(style2);cells.get(index, 1 + 9).putValue(datamap.get("外網郵箱"));cells.get(index, 1 + 9).setStyle(style2);}sheet.autoFitColumns();}workbook.save(getOutputStream(fileName, response),FileFormatType.EXCEL_2003_XML);} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}private List<Map<String, Object>> loadTabRecordJLCY(String [] ID) {List<Map<String, Object>> JTCY = new ArrayList<Map<String, Object>>(); // 集體成員數據StringBuffer JTCY_sql =new StringBuffer();StringBuffer IDSQL =new StringBuffer("(");for (int i = 0; i < ID.length; i++) {if(ID.length-1!=i){IDSQL.append("'").append(ID[i]).append("',");}else{IDSQL.append("'").append(ID[i]).append("'");}}IDSQL.append(")");JTCY_sql.append( "SELECT ") ;JTCY_sql.append( "z.A0101 AS 姓名, ") ;JTCY_sql.append( "d.DMCPT AS 性別, ") ;JTCY_sql.append( "e.DMCPT AS 單位, ") ;JTCY_sql.append( "ff.ZDYXA0105F AS 職務, ") ;JTCY_sql.append( "'' AS 從事主要業務, ") ;JTCY_sql.append( "b.ZGZH0302 AS 辦公室電話, ") ;JTCY_sql.append( "b.ZGZH0303 AS 手機, ") ;JTCY_sql.append( "b.ZGZH0304 AS 微信號, ") ;JTCY_sql.append( "b.ZGZH0305 AS 內網郵箱, ") ;JTCY_sql.append( "b.ZGZH0306 AS 外網郵箱 ") ;JTCY_sql.append( "FROM A01 z ") ;JTCY_sql.append( "LEFT JOIN ZGZH03 b on z.A00=b.ZGZH0301 ") ;JTCY_sql.append( "LEFT JOIN A01_FUNCTION ff on z.a00=ff.a00 ") ;JTCY_sql.append( "LEFT JOIN GB22611 d on z.A0104 = d.DMCOD ") ;JTCY_sql.append( "LEFT JOIN G099 e on z.ZDYXA0121 = e.DMCOD ") ;JTCY_sql.append( "WHERE z.DELETEFLAG = '0' ") ;if(!(ID[0].isEmpty())){JTCY_sql.append( "AND z.A00 IN ").append(IDSQL.toString());}JTCY_sql.append( "ORDER BY z.CREATETIME desc ") ;JTCY = jdbcOperations.queryForList(JTCY_sql.toString());return JTCY;} /*** * @param fileName* @param response* @return* @throws IOException*/private OutputStream getOutputStream(String fileName,HttpServletResponse response) throws IOException {response.reset();response.setContentType("application/octet-stream");response.addHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("gbk"), "iso-8859-1"));OutputStream out = response.getOutputStream();return out;}
?
?
轉載于:https://www.cnblogs.com/mandy3651/p/6781913.html
總結
- 上一篇: Qt核心知识归类及相关资料
- 下一篇: 20145202马超《网络对抗》Exp7