将一个字符串左旋n个字符(两种方法)
2015-11-20 13:55
337 查看
以下代码中使用outputStream 对生成的报表进行接收,通过下载方式进行响应
OutputStream os = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(os);
将生成的excel文件在workbook关闭后直接写入到输出流中。
以下代码包含了jxl技术中的以下几个技术点
合并单元格,设置单元格格式,设置列宽,设置单元格背景色,设置边框,设置对齐方式。
//设置响应头信息,为下载文件方式
response.setContentType("APPLICATION/DOWNLOAD");
response.setHeader("Content-Disposition", "attachment;filename=\"" + new String(newExcelpath.getBytes("gbk"),"ISO-8859-1"));
//将生成都excel文件写入到response输出流中
OutputStream os = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet(table, 0);
// 大标题字体格式
WritableFont headTitleFont = new WritableFont(WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false,UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.WHITE);
WritableCellFormat headTitleFormat = new WritableCellFormat(headTitleFont);
headTitleFormat.setBackground(jxl.format.Colour.BLUE_GREY); // 设置单元格的背景颜色
headTitleFormat.setAlignment(jxl.format.Alignment.LEFT); // 设置对齐方式
headTitleFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//设置边框
//小标题字体格式
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
titleFormat.setBackground(jxl.format.Colour.PALE_BLUE); // 设置单元格的背景颜色
titleFormat.setAlignment(jxl.format.Alignment.LEFT);// 设置对齐方式
titleFormat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);//设置边框
// 设置列的宽度
sheet.setColumnView(0, 20); (列号,宽度)
sheet.setColumnView(1, 20);
sheet.setColumnView(2, 20);
sheet.setColumnView(3, 20);
sheet.addCell(new Label(0, 0, "OMDF外线侧信息", headTitleFormat));
sheet.mergeCells(0, 0, 3, 0);
sheet.addCell(new Label(0, 1, "ss",titleFormat));
sheet.addCell(new Label(1, 1, form.getOMDF_QU_JU_NAME()));
sheet.addCell(new Label(2, 1, "ss",titleFormat));
sheet.addCell(new Label(3, 1, form.getOMDF_JU_SUO_NAME()));
sheet.addCell(new Label(0, 2, "ss",titleFormat));
sheet.addCell(new Label(1, 2, form.getOMDF_JIFANG_MINGCHENG()));
sheet.addCell(new Label(2, 2, "ss",titleFormat));
sheet.addCell(new Label(3, 2, form.getOMDF_SHEBEI_BIANMA()));
workbook.write();
workbook.close();
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
}
}
OutputStream os = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(os);
将生成的excel文件在workbook关闭后直接写入到输出流中。
以下代码包含了jxl技术中的以下几个技术点
合并单元格,设置单元格格式,设置列宽,设置单元格背景色,设置边框,设置对齐方式。
//设置响应头信息,为下载文件方式
response.setContentType("APPLICATION/DOWNLOAD");
response.setHeader("Content-Disposition", "attachment;filename=\"" + new String(newExcelpath.getBytes("gbk"),"ISO-8859-1"));
//将生成都excel文件写入到response输出流中
OutputStream os = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet(table, 0);
// 大标题字体格式
WritableFont headTitleFont = new WritableFont(WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false,UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.WHITE);
WritableCellFormat headTitleFormat = new WritableCellFormat(headTitleFont);
headTitleFormat.setBackground(jxl.format.Colour.BLUE_GREY); // 设置单元格的背景颜色
headTitleFormat.setAlignment(jxl.format.Alignment.LEFT); // 设置对齐方式
headTitleFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//设置边框
//小标题字体格式
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
titleFormat.setBackground(jxl.format.Colour.PALE_BLUE); // 设置单元格的背景颜色
titleFormat.setAlignment(jxl.format.Alignment.LEFT);// 设置对齐方式
titleFormat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);//设置边框
// 设置列的宽度
sheet.setColumnView(0, 20); (列号,宽度)
sheet.setColumnView(1, 20);
sheet.setColumnView(2, 20);
sheet.setColumnView(3, 20);
sheet.addCell(new Label(0, 0, "OMDF外线侧信息", headTitleFormat));
sheet.mergeCells(0, 0, 3, 0);
sheet.addCell(new Label(0, 1, "ss",titleFormat));
sheet.addCell(new Label(1, 1, form.getOMDF_QU_JU_NAME()));
sheet.addCell(new Label(2, 1, "ss",titleFormat));
sheet.addCell(new Label(3, 1, form.getOMDF_JU_SUO_NAME()));
sheet.addCell(new Label(0, 2, "ss",titleFormat));
sheet.addCell(new Label(1, 2, form.getOMDF_JIFANG_MINGCHENG()));
sheet.addCell(new Label(2, 2, "ss",titleFormat));
sheet.addCell(new Label(3, 2, form.getOMDF_SHEBEI_BIANMA()));
workbook.write();
workbook.close();
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
}
}
相关文章推荐
- UIImange的简单使用(一)
- Win7如何显示/隐藏Administrator账号
- JavaScript性能优化之小知识总结
- 为Gradle添加tomcat插件,调试WEB应用
- UITableView 的用法
- Android服务之Service(其一)
- 我是如何招聘程序员的
- HttpClient4.3 使用经验(一) 简单使用
- cocoa框架 for iOS
- JUNIT -- springMVC的action进行单元测试
- linux学习教程(一)(安装篇)centos7没有安装ifconfig命令的解决方法
- [代码]JAVA触发器,Spring的quartz配置
- JS中使用正则表达式
- 网站安全狗V3.2版 增加URL地址全检测功能 保护网站安全
- Qt Quick 布局介绍
- PHP获取客户端IP函数
- android沉浸式状态栏实现
- 1048. Find Coins (25)
- LeetCode(201) Bitwise AND of Numbers Range
- Python 实现单向链表