您的位置:首页 > 其它

将一个字符串左旋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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: