java jxl导出excle但是弹不出对话框,指定路径可以生成excel
OutputStreamfile=response.getOutputStream();Stringfilename="管理员操作日志信息.xls";response.r...
OutputStream file = response.getOutputStream();
String filename = "管理员操作日志信息.xls";
response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment; filename="+filename);
response.setContentType("application/msexcel");
// FileOutputStream file = new FileOutputStream("D:/管理员操作日志信息.xls");
//创建一个excel文件
WritableWorkbook wbook = Workbook.createWorkbook(file);
WritableSheet ws = wbook.createSheet("ofbiz admin log", 10);
WritableFont wf = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,
UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat wcf = new WritableCellFormat(wf);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf.setAlignment(Alignment.CENTRE);
ws.setRowView(0, 500);
ws.addCell(new Label(0,0,"操作人",wcf));
ws.addCell(new Label(1,0,"行为",wcf));
ws.addCell(new Label(2,0,"时间",wcf));
ws.addCell(new Label(3,0,"IP",wcf));
ws.addCell(new Label(0,1,"管理员",wcf));
ws.addCell(new Label(1,1,"AAAA",wcf));
ws.addCell(new Label(2,1,"2014-07-13",wcf));
ws.addCell(new Label(3,1,"192.169.1.102",wcf));
ws.addCell(new Label(0,2,"管理员",wcf));
ws.addCell(new Label(1,2,"BBBB",wcf));
ws.addCell(new Label(2,2,"2014-07-13",wcf));
ws.addCell(new Label(3,2,"192.169.1.102",wcf));
wbook.write();
wbook.close(); 展开
String filename = "管理员操作日志信息.xls";
response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment; filename="+filename);
response.setContentType("application/msexcel");
// FileOutputStream file = new FileOutputStream("D:/管理员操作日志信息.xls");
//创建一个excel文件
WritableWorkbook wbook = Workbook.createWorkbook(file);
WritableSheet ws = wbook.createSheet("ofbiz admin log", 10);
WritableFont wf = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,
UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat wcf = new WritableCellFormat(wf);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf.setAlignment(Alignment.CENTRE);
ws.setRowView(0, 500);
ws.addCell(new Label(0,0,"操作人",wcf));
ws.addCell(new Label(1,0,"行为",wcf));
ws.addCell(new Label(2,0,"时间",wcf));
ws.addCell(new Label(3,0,"IP",wcf));
ws.addCell(new Label(0,1,"管理员",wcf));
ws.addCell(new Label(1,1,"AAAA",wcf));
ws.addCell(new Label(2,1,"2014-07-13",wcf));
ws.addCell(new Label(3,1,"192.169.1.102",wcf));
ws.addCell(new Label(0,2,"管理员",wcf));
ws.addCell(new Label(1,2,"BBBB",wcf));
ws.addCell(new Label(2,2,"2014-07-13",wcf));
ws.addCell(new Label(3,2,"192.169.1.102",wcf));
wbook.write();
wbook.close(); 展开
1个回答
展开全部
jxl没有提供界面控件,你需要用JFileChooser自己做文件选择对话框,然后用jxl将文件写到选择的文件中。
更多追问追答
追问
我刚刚没有描述清楚 我是在web项目中遇到这个问题的
追答
那就把文件写到web项目的response的OutputStream中去,这样就相当于下载了。
另外别王杰设置response的header,一般这样设置:
filename = URLEncoder.encode(filename,"UTF-8");// 转码,根据自己的页面字符集来改
//设置文件名,attachment和filename之间是分号,注意!
response.addHeader("Content-Disposition", "attachment;filename=" + filename);
//设置大小
response.addHeader("Content-Length", (new Long(file.length())).toString());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |