导出Excel
来源:互联网 发布:淘宝二手房翻新 编辑:程序博客网 时间:2024/06/08 18:28
在控制器里面 写入进入jsp页面
public String writeExcel (HttpServletRequest request) throws Exception{
List<Object[]> list = whmsManager.findMaterial(selectTypeOne, day);
request.setAttribute("list", list);
return "whms/whms.jsp";
}
这里的whms.jsp 是指进入的页面
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="jxl.*,jxl.write.*,java.util.*,java.io.*" %>
<%@page import="com.iit.whms.webapp.controller.AAA"%>
<%@page import="java.text.*;"%>
<%
response.reset();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String date="whmsLazyInfo_"+df.format(new Date());
byte[] bdate=date.getBytes();
String d=new String(bdate,"GBK");
response.setCharacterEncoding("utf8");
response.setHeader("Connection", "close");
response.setHeader("Context-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="+d+".xls");
List list=(List) request.getAttribute("list");
OutputStream resOut=response.getOutputStream();
WritableWorkbook writableWorkbook =AAA.getWritableWorkbookLazyWhms(resOut,listWhmsMaterialDetail);
try{
writableWorkbook.write();
writableWorkbook.close();
resOut.flush();
resOut.close();
resOut=null;
response.flushBuffer();
}catch(Exception e){
e.toString();
} out.clear();
out=pageContext.pushBody();
%>
下面返回到getWritableWorkbookLazyWhms这个控制器里面
public static WritableWorkbook getWritableWorkbookLazyWhms(OutputStream out, List<Object[]> listWhmsMaterialDetail) {
WritableWorkbook book;
try {
book = Workbook.createWorkbook(out);
WritableSheet sheet = book.createSheet("呆滞料号信息", 0);
try {
WritableFont fon = new WritableFont(WritableFont.COURIER);
// fon.setColour(Colour.DEFAULT_BACKGROUND);
WritableCellFormat wcf = new WritableCellFormat(fon);
// wcf.setBackground(Colour.SKY_BLUE);
CellView view = new CellView();
view.setSize(5000);
sheet.setColumnView(0, view);
sheet.addCell(new Label(0, 1 , "编号",wcf));
sheet.addCell(new Label(1, 1 , "中文名称", wcf));
for (int i = 0; i < list.size(); i++) {
Object[] obj = list.get(i);
sheet.addCell(new Label(0, 1 + i+1, String.valueOf(i + 1), wcf));
String temp = "";
if(obj[0]!=null){
temp = obj[0].toString();
}
sheet.addCell(new Label(1, 1 + i+1, temp, wcf));
}
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
} catch (IOException e) {
book = null;
e.printStackTrace();
}
return book;
}
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- 我的Linux书架
- SAP常用事务码T-CODE
- unix中的PV原语
- Linux中加载新的硬盘
- 关于在2010中调用GDI+ 提示“Font”: 不明确的符号的问题
- 导出Excel
- 转贴:Android Camera 架构简析
- ubuntu 将最大化,最小化,关闭按钮置于窗口右侧
- android 数字证书
- mysql 将远程数据保存到本地
- 高效使用JavaEE ORM框架
- Bash csh 命令提示符
- openssl 客户端程序移植到arm平台 OK6410上运行
- 导出固定的excel