各种导出下载
来源:互联网 发布:怎么优化古墓丽影崛起 编辑:程序博客网 时间:2024/04/29 23:32
Excel 导出、Word导出示例
/**
* <h1>月度主要财务指标快报_导出</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("月度主要财务指标快报".getBytes("GBK"), "ISO-8859-1") +".xls");
OutputStream os = response.getOutputStream();
this.weekService.exportYdzycwzbkb(this.weekService.getYdzycwzbkb(dateTime),dateTime,"月度主要财务指标快报").write(os);
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* <h1>月度主要财务指标快报_Word_导出</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("月度主要财务指标快报".getBytes("GBK"), "ISO-8859-1") +".doc");
OutputStream os = response.getOutputStream();
// this.weekService.exportYdzycwzbkb(this.weekService.getYdzycwzbkb(dateTime),dateTime,"月度主要财务指标快报").write(os);
this.weekService.testWord(os);
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* <h1>月度主要财务指标快报_导出</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[]{"项目","行号","本月数","同期本月","增幅","本年累计","本年累计","累计增幅"};
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是列号,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;
// 标题样式
HSSFCellStyle headStyle = ToolUtils.StyleUtil.getTitleStyle(book);
// 标题
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("编制单位:江苏中烟工业有限责任公司(本级)");
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());
// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
RtfWriter2.getInstance(document,out);
document.open();
// 设置中文字体
// 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);
// 标题字体风格
Font titleFont = new Font(bfChinese, 26, Font.BOLD);
//标签字体样式
Font labelFont = new Font(bfChinese,15,Font.BOLD);
// 正文字体风格
Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
Font contextBoldFont = new Font(bfChinese, 14, Font.BOLD);
// 设置标题格式对齐方式
Paragraph title = new Paragraph("江苏中烟工业系统月度快报说明",titleFont);
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
// 设置日期
Paragraph title2 = new Paragraph("(二Ο一四年五月)",new Font(bfChinese,16,Font.BOLD));
title2.setAlignment(Element.ALIGN_CENTER);
document.add(title2);
document.add(new Paragraph(""));
//标签1
Paragraph label = new Paragraph(" 一、全系统实现税利情况",labelFont);
label.setLeading(30);
label.setAlignment(Element.ALIGN_LEFT);
document.add(label);
Chunk _label = new Chunk(" 工业公司本级:",contextBoldFont);
Chunk _context = new Chunk("5月份实现税利35.75亿元,同比29.62亿元增长20.69%," +
"其中实现利润8.15亿元,同比7.52亿元上升8.39%。1-5月份累计实现税利215.77亿元, 同比197.84亿元增长9.06%," +
"其中累计实现利润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(" 全系统:",contextBoldFont);
_context = new Chunk("5月份实现税利35.98亿元,同比29.75亿元增长20.94%,其中实现利润8.29亿元,同比7.6亿元增长9.05%。1-5月份累计实现税利216.37亿元," +
"同比198.54亿元增长8.98%,其中实现利润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);
//标签1
label = new Paragraph(" 二、卷烟工业企业产量、销量及实现税利情况",labelFont);
label.setLeading(30);
label.setAlignment(Element.ALIGN_LEFT);
document.add(label);
_l_c = new Paragraph(" 1、5月份生产卷烟17.5万箱,同比15.56万箱增加1.9万箱,增长12.44%。1-5月份累计生产卷烟89.08万箱,同比85.56万箱增加3.5万箱,增长4.1%。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
_l_c = new Paragraph(" 2、5月份自产卷烟销售17.55万箱,同比15.83万箱增加1.72万箱,增长10.86%。1-5月份累计自产卷烟销售94.68万箱,同比90.87万箱增加3.81万箱,增长4.19%。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
_l_c = new Paragraph(" 3、5月份自产卷烟销售额38.52亿元,同比32.64亿元增长18.01%。1-5月份累计自产卷烟销售额233.21亿元,同比212.77亿元增长9.6%。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
_l_c = new Paragraph(" 4、5月份自产卷烟销售成本7.88亿元,同比6.49亿元增长21.52%。1-5月份累计自产卷烟销售成本43.29亿元,同比38.35亿元增长12.87%。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
_l_c = new Paragraph(" 4、5月份自产卷烟销售成本7.88亿元,同比6.49亿元增长21.52%。1-5月份累计自产卷烟销售成本43.29亿元,同比38.35亿元增长12.87%。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
_l_c = new Paragraph(" 6、1-5月份卷烟累计税利增加17.93亿元,其中销量增加3.81万箱,增加税利8.29亿元,单箱税利结构提升1017元,增加税利9.64亿元。",contextFont);
_l_c.setLeading(30);
document.add(_l_c);
label = new Paragraph(" 三、工业公司本级成本费用情况",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月份累计期间费用61628万元,同比62377万元下降1.2%。其中:",contextFont);
_label = new Chunk("营业费用",contextBoldFont);
_l_c.add(_context);
_l_c.add(_label);
_context = new Chunk("21357万元,同比18877万元上升13.14%,",contextFont);
_label = new Chunk("管理费用",contextBoldFont);
_l_c.add(_context);
_l_c.add(_label);
_context = new Chunk("56992万元,同比61123万元下降6.76%。综合两大费用来看总体减少1651万,下降2.06%。其中由于工资费用增长1600万,实则其他费用的下降影响在3200多万。重点费用的使用情况:其中宣传促销费下降70%,车辆运行费用下降30%,业务招待费下降82.29%,本月由于派驻阿根廷人员差费报销,涉外费用是上升的。",contextFont);
_l_c.add(_context);
document.add(_l_c);
document.close();
}
其他类型的导出
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>
- 各种导出下载
- 下载导出
- Access 导出各种格式文件
- Access 导出各种格式文件
- 各种开发工具下载
- UltraEdit各种wordfile下载
- 各种Windows版本下载
- 各种Linux版本下载
- 各种下载资源网址。
- 各种 UNIX 下载地址
- 各种源码下载地址
- 各种下载地址汇集
- 各种jar包下载
- 各种操作系统下载
- linux 各种相关下载
- 各种android下载资源
- 各种安装程序下载
- Xcode各种版本下载
- Oracle deferrable、immediate 约束
- POJ1135_Domino Effect(最短路)
- 常州做乳腺纤维瘤最好的医院
- v4l2_device.c浅析
- Android 模拟器从局域网访问外部网络
- 各种导出下载
- Windows 9预览版今秋发布 正式版明年推出
- lr11 监控windows server 2003方法
- 收藏高精度模板
- 苹果组建语音识别团队 或抛弃Siri技术提供商
- 广州传智播客PHP程序员大型专场招聘会圆满成功
- Java String和Int类型之间相互转换
- 两年降价超80% 4K电视机开始快速普及
- VS2010编译Lua程序(lua-5.2.3)