各种导出下载
Excel 導(dǎo)出、Word導(dǎo)出示例
/**
 * <h1>月度主要財(cái)務(wù)指標(biāo)快報(bào)_導(dǎo)出</h1>
 * @author ruanhao
 * @return
 */
 private String initYdzycwzbkbExcel() {
 String dateTime = request.getParameter("dateTime");
 response.reset();
 response.setContentType("application/vnd.ms-excel");
 response.setCharacterEncoding("GBK");
 try {
 response.setHeader("Content-Disposition", "attachment; filename=" + dateTime + new String("月度主要財(cái)務(wù)指標(biāo)快報(bào)".getBytes("GBK"), "ISO-8859-1") +".xls");
 OutputStream os = response.getOutputStream();
 this.weekService.exportYdzycwzbkb(this.weekService.getYdzycwzbkb(dateTime),dateTime,"月度主要財(cái)務(wù)指標(biāo)快報(bào)").write(os);
 os.flush();
 os.close();
 } catch (Exception e) {
 e.printStackTrace();
 }
 
 return null;
 }
 
 
 /**
 * <h1>月度主要財(cái)務(wù)指標(biāo)快報(bào)_Word_導(dǎo)出</h1>
 * @author ruanhao
 * @return
 */
 private String initYdzycwzbkbWord() {
 String dateTime = request.getParameter("dateTime");
 response.reset();
 response.setContentType("application/msword");
 response.setCharacterEncoding("GBK");
 try {
 response.setHeader("Content-Disposition", "attachment; filename=" + dateTime + new String("月度主要財(cái)務(wù)指標(biāo)快報(bào)".getBytes("GBK"), "ISO-8859-1") +".doc");
 OutputStream os = response.getOutputStream();
 // this.weekService.exportYdzycwzbkb(this.weekService.getYdzycwzbkb(dateTime),dateTime,"月度主要財(cái)務(wù)指標(biāo)快報(bào)").write(os);
 this.weekService.testWord(os);
 os.flush();
 os.close();
 } catch (Exception e) {
 e.printStackTrace();
 }
 
 return null;
 }
 
 
/**
 * <h1>月度主要財(cái)務(wù)指標(biāo)快報(bào)_導(dǎo)出</h1>
 * @author ruanhao
 * @return
 */
 public HSSFWorkbook exportYdzycwzbkb(List<Map<String, Object>> list,String dateTime, String sheetName) {
 HSSFWorkbook book = new HSSFWorkbook();
 ? ? ? ? HSSFSheet sheet = book.createSheet(sheetName);
 ? ? ? ??
 
 
 String[] headers = new String[]{"項(xiàng)目","行號(hào)","本月數(shù)","同期本月","增幅","本年累計(jì)","本年累計(jì)","累計(jì)增幅"};
 String[] cells = new String[]{"","","DBSL","DBSL_BYLJ","DBSL_BYTQ","DBSL_BYTB","DBSL_BNLJ","DBSL_BNTQ","DBSL_BNTB","YMKC","XSE_BNLJ","XSE_BNTQ","XSE_BNTB","XSJG_LJ","XSJG_TQ","XSJG_TB"};
 
 // sheet.setDefaultColumnWidth(15);
 sheet.setDefaultRowHeight((short)(20*15));
 sheet.setColumnWidth(0, 10000);//0是列號(hào),8000是列寬值
 sheet.setColumnWidth(1, 1500);
 sheet.setColumnWidth(2, 3000);
 sheet.setColumnWidth(3, 3000);
 sheet.setColumnWidth(4, 3000);
 sheet.setColumnWidth(5, 3000);
 sheet.setColumnWidth(6, 3000);
 sheet.setColumnWidth(7, 3000);
 
 HSSFRow hsrow = null;
 HSSFCellStyle cellStyleLeft = ToolUtils.StyleUtil.getHasBorderStyle(book);
 cellStyleLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
 HSSFCellStyle cellStyleCenter = ToolUtils.StyleUtil.getHasBorderStyle(book);
 cellStyleCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER);
 HSSFCellStyle cellStyleRight = ToolUtils.StyleUtil.getHasBorderStyle(book);
 cellStyleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
 HSSFCellStyle redFontStyle = ToolUtils.StyleUtil.getRedFontStyle(book);
 HSSFCellStyle noBorderStyle = ToolUtils.StyleUtil.getNoBorderStyle(book);
 
 HSSFCell cell = null;
 // 標(biāo)題樣式
 HSSFCellStyle headStyle = ToolUtils.StyleUtil.getTitleStyle(book);
 // 標(biāo)題
 hsrow = sheet.createRow(0);
 hsrow.setHeight((short)(20*47.25));
 
 cell = hsrow.createCell(0);
 cell.setCellValue(sheetName);
 cell.setCellStyle(headStyle);
 for(int i = 1; i < headers.length; i++){
 cell = hsrow.createCell(i);
 cell.setCellValue("");
 }
 sheet.addMergedRegion(new CellRangeAddress(
 ? ? ? ? ? ? ? ?0, //first row (0-based)
 ? ? ? ? ? ? ? ?0, //last row ?(0-based)
 ? ? ? ? ? ? ? ?0, //first column (0-based)
 ? ? ? ? ? ? ? ?headers.length-1 ?//last column ?(0-based)
 ? ?));
 
 // 第二行
 hsrow = sheet.createRow(1);
 ? ? ? ? for(int i=0;i<headers.length-1;i++){
 ? ? ? ? cell = hsrow.createCell(i);
 ? ? ? ? cell.setCellValue("");
 ? ? ? ? }
 ? ? ? ? cell = hsrow.createCell(0);
 ? ? ? ? cell.setCellValue("編制單位:江蘇中煙工業(yè)有限責(zé)任公司(本級(jí))");
 ? ? ? ? cell.setCellStyle(noBorderStyle);
 ? ? ? ? cell = hsrow.createCell(3);
 ? ? ? ? cell.setCellValue(dateTime.substring(0, 4)+"年"+dateTime.substring(5,7)+"月");
 ? ? ? ? cell.setCellStyle(noBorderStyle);
 ? ? ? ? cell = hsrow.createCell(6);
 ? ? ? ? cell.setCellValue("單位:萬元");
 ? ? ? ? cell.setCellStyle(noBorderStyle);
 ? ? ? ? sheet.addMergedRegion(new CellRangeAddress(
 ? ? ? ? ? ? ? ? 1, //first row (0-based)
 ? ? ? ? ? ? ? ? 1, //last row ?(0-based)
 ? ? ? ? ? ? ? ? 0, //first column (0-based)
 ? ? ? ? ? ? ? ? 1 ?//last column ?(0-based)
 ? ? ? ? ));
 
 hsrow = sheet.createRow(2);//表頭
 for(int i = 0; i < headers.length; i++){
 cell = hsrow.createCell(i);
 cell.setCellValue(headers[i]);
 cell.setCellStyle(cellStyleCenter);
 
 
 }
 int i =3;
 String byzf = null;
 String bnzf = null;
 for(Map<String, Object> m : list ){
 hsrow = sheet.createRow(i);
 
 cell = hsrow.createCell(0);
 cell.setCellValue(MapUtils.getString(m, "XM"));
 cell.setCellStyle(cellStyleLeft);
 
 cell = hsrow.createCell(1);
 cell.setCellValue(MapUtils.getString(m, "HH"));
 cell.setCellStyle(cellStyleRight);
 
 cell = hsrow.createCell(2);
 cell.setCellValue(fmtDouble(MapUtils.getString(m, "BY")));
 cell.setCellStyle(cellStyleRight);
 
 cell = hsrow.createCell(3);
 cell.setCellValue(fmtDouble(MapUtils.getString(m, "BY_TQ")));
 cell.setCellStyle(cellStyleRight);
 
 byzf = MapUtils.getString(m, "BYZF");
 cell = hsrow.createCell(4);
 cell.setCellValue(fmtPercent(byzf));
 if(fmtPercent(byzf)!=null && Double.parseDouble(byzf)<0){
 cell.setCellStyle(redFontStyle);
 }else{
 cell.setCellStyle(cellStyleRight);
 }
 
 cell = hsrow.createCell(5);
 cell.setCellValue(fmtDouble(MapUtils.getString(m, "BN")));
 cell.setCellStyle(cellStyleRight);
 
 cell = hsrow.createCell(6);
 cell.setCellValue(fmtDouble(MapUtils.getString(m, "BN_TQ")));
 cell.setCellStyle(cellStyleRight);
 
 bnzf = MapUtils.getString(m, "BNZF");
 cell = hsrow.createCell(7);
 cell.setCellValue(fmtPercent(bnzf));
 if(fmtPercent(bnzf)!=null && Double.parseDouble(bnzf)<0){
 cell.setCellStyle(redFontStyle);
 }else{
 cell.setCellStyle(cellStyleRight);
 }
 
 i++;
 }
 
 
 return book;
 }
 
 
 
 public void testWord(OutputStream out) throws DocumentException, IOException{
 Document document = new Document(PageSize.A4.rotate());
 // 建立一個(gè)書寫器(Writer)與document對(duì)象關(guān)聯(lián),通過書寫器(Writer)可以將文檔寫入到磁盤中?
 RtfWriter2.getInstance(document,out);?
 document.open();?
 // 設(shè)置中文字體?
 // BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",?
 // "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);?
 BaseFont bfChinese = BaseFont.createFont("C:\\WINDOWS\\Fonts\\SIMSUN.TTC,1",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 // 標(biāo)題字體風(fēng)格?
 Font titleFont = new Font(bfChinese, 26, Font.BOLD);?
 
 
 //標(biāo)簽字體樣式
 Font labelFont = new Font(bfChinese,15,Font.BOLD);
 
 // 正文字體風(fēng)格?
 Font contextFont = new Font(bfChinese, 14, Font.NORMAL);?
 Font contextBoldFont = new Font(bfChinese, 14, Font.BOLD);?
 
 // 設(shè)置標(biāo)題格式對(duì)齊方式?
 Paragraph title = new Paragraph("江蘇中煙工業(yè)系統(tǒng)月度快報(bào)說明",titleFont);?
 title.setAlignment(Element.ALIGN_CENTER);?
 document.add(title);?
 // 設(shè)置日期
 
 
 Paragraph title2 = new Paragraph("(二Ο一四年五月)",new Font(bfChinese,16,Font.BOLD));
 title2.setAlignment(Element.ALIGN_CENTER);
 document.add(title2);
 document.add(new Paragraph(""));
 
 
 //標(biāo)簽1
 Paragraph label = new Paragraph(" ? ?一、全系統(tǒng)實(shí)現(xiàn)稅利情況",labelFont);
 label.setLeading(30);
 label.setAlignment(Element.ALIGN_LEFT);
 document.add(label);
 ?
 Chunk _label = new Chunk(" ? ?工業(yè)公司本級(jí):",contextBoldFont);
 Chunk _context = new Chunk("5月份實(shí)現(xiàn)稅利35.75億元,同比29.62億元增長20.69%," +
 "其中實(shí)現(xiàn)利潤8.15億元,同比7.52億元上升8.39%。1-5月份累計(jì)實(shí)現(xiàn)稅利215.77億元, 同比197.84億元增長9.06%," +
 "其中累計(jì)實(shí)現(xiàn)利潤44.77億元,同比43.13億元增長3.78%。",contextFont);
 // Phrase _l_c = new Phrase();
 Paragraph _l_c = new Paragraph();
 _l_c.setLeading(30);
 _l_c.add(_label);
 _l_c.add(_context);
 document.add(_l_c);
 
 
 _label = new Chunk(" ? ?全系統(tǒng):",contextBoldFont);
 _context = new Chunk("5月份實(shí)現(xiàn)稅利35.98億元,同比29.75億元增長20.94%,其中實(shí)現(xiàn)利潤8.29億元,同比7.6億元增長9.05%。1-5月份累計(jì)實(shí)現(xiàn)稅利216.37億元," +
 "同比198.54億元增長8.98%,其中實(shí)現(xiàn)利潤45.27億元,同比43.69億元增長3.63%。",contextFont);
 _l_c = new Paragraph();
 _l_c.setLeading(30);
 _l_c.add(_label);
 _l_c.add(_context);
 document.add(_l_c);
 
 
 //標(biāo)簽1
 label = new Paragraph(" ? ?二、卷煙工業(yè)企業(yè)產(chǎn)量、銷量及實(shí)現(xiàn)稅利情況",labelFont);
 label.setLeading(30);
 label.setAlignment(Element.ALIGN_LEFT);
 document.add(label);
 ?
 _l_c = new Paragraph(" ? ?1、5月份生產(chǎn)卷煙17.5萬箱,同比15.56萬箱增加1.9萬箱,增長12.44%。1-5月份累計(jì)生產(chǎn)卷煙89.08萬箱,同比85.56萬箱增加3.5萬箱,增長4.1%。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 _l_c = new Paragraph(" ? ?2、5月份自產(chǎn)卷煙銷售17.55萬箱,同比15.83萬箱增加1.72萬箱,增長10.86%。1-5月份累計(jì)自產(chǎn)卷煙銷售94.68萬箱,同比90.87萬箱增加3.81萬箱,增長4.19%。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 _l_c = new Paragraph(" ? ?3、5月份自產(chǎn)卷煙銷售額38.52億元,同比32.64億元增長18.01%。1-5月份累計(jì)自產(chǎn)卷煙銷售額233.21億元,同比212.77億元增長9.6%。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 _l_c = new Paragraph(" ? ?4、5月份自產(chǎn)卷煙銷售成本7.88億元,同比6.49億元增長21.52%。1-5月份累計(jì)自產(chǎn)卷煙銷售成本43.29億元,同比38.35億元增長12.87%。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 _l_c = new Paragraph(" ? ?4、5月份自產(chǎn)卷煙銷售成本7.88億元,同比6.49億元增長21.52%。1-5月份累計(jì)自產(chǎn)卷煙銷售成本43.29億元,同比38.35億元增長12.87%。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 _l_c = new Paragraph(" ? ?6、1-5月份卷煙累計(jì)稅利增加17.93億元,其中銷量增加3.81萬箱,增加稅利8.29億元,單箱稅利結(jié)構(gòu)提升1017元,增加稅利9.64億元。",contextFont);
 _l_c.setLeading(30);
 document.add(_l_c);
 
 
 label = new Paragraph(" ? ?三、工業(yè)公司本級(jí)成本費(fèi)用情況",labelFont);
 label.setLeading(30);
 label.setAlignment(Element.ALIGN_LEFT);
 document.add(label);
 _l_c = new Paragraph();
 _l_c.setLeading(30);
 _context = new Chunk(" ? ?1-5月份累計(jì)期間費(fèi)用61628萬元,同比62377萬元下降1.2%。其中:",contextFont);
 _label = new Chunk("營業(yè)費(fèi)用",contextBoldFont);
 _l_c.add(_context);
 _l_c.add(_label);
 _context = new Chunk("21357萬元,同比18877萬元上升13.14%,",contextFont);
 _label = new Chunk("管理費(fèi)用",contextBoldFont);
 _l_c.add(_context);
 _l_c.add(_label);
 _context = new Chunk("56992萬元,同比61123萬元下降6.76%。綜合兩大費(fèi)用來看總體減少1651萬,下降2.06%。其中由于工資費(fèi)用增長1600萬,實(shí)則其他費(fèi)用的下降影響在3200多萬。重點(diǎn)費(fèi)用的使用情況:其中宣傳促銷費(fèi)下降70%,車輛運(yùn)行費(fèi)用下降30%,業(yè)務(wù)招待費(fèi)下降82.29%,本月由于派駐阿根廷人員差費(fèi)報(bào)銷,涉外費(fèi)用是上升的。",contextFont);
 _l_c.add(_context);
 document.add(_l_c);
 
 document.close();?
 }
 
 
其他類型的導(dǎo)出
response.setContentType("text/plain");<option value="image/bmp">BMP</option> <option value="image/gif">GIF</option> <option value="image/jpeg">JPEG</option> <option value="image/tiff">TIFF</option> <option value="image/x-dcx">DCX</option> <option value="image/x-pcx">PCX</option> <option value="text/html">HTML</option> <option value="text/plain">TXT</option> <option value="text/xml">XML</option> <option value="application/afp">AFP</option> <option value="application/pdf">PDF</option> <option value="application/rtf">RTF</option> <option value="application/msword">MSWORD</option> <option value="application/vnd.ms-excel">MSEXCEL</option> <option value="application/vnd.ms-powerpoint">MSPOWERPOINT</option> <option value="application/wordperfect5.1">WORDPERFECT</option> <option value="application/vnd.lotus-wordpro">WORDPRO</option> <option value="application/vnd.visio">VISIO</option> <option value="application/vnd.framemaker">FRAMEMAKER</option> <option value="application/vnd.lotus-1-2-3">LOTUS123</option>
總結(jié)
                            
                        - 上一篇: 黑客为“炫技”随机攻击,结果被“顺着网线
 - 下一篇: gNB-CU架构图