我想把jsp页面的数据(从数据库中得到的数据)导出到excel中,我在网上找了两天了,有的js代码但是抛出js error,说什么服务期不能创建automation对象,我也考虑用第三方插件,poi,jxl,但是我的数据已经有了,不需再从数据库中获取,所以就没必要用它们了,高手们怎么解决啊,帮忙啊,搞了好长时间了,还是没头绪,郁闷死了,
解决方案 »
- struts2布置配置问题
- 在html下拉框中的option选项,如何动态添加,我是初学者,请大侠多多指点,谢谢阿,在线急等。
- 求系统界面模板~~~~~~~~~~~~~~~~
- 这段js什么意思?请大侠解释下!
- 请推荐一个java开发工具包,
- 急!初学struts,问题请教
- 请问,Web页面中实现图形绘制功能的手段都有哪些?
- 求助hibernate mapping中设置的character长度无效
- *****数据库连接问题*****《JSP设计》例子的数据库连接问题
- 有关struts的<html:text>标签的问题!!!!!!!!!!!!!!!!!!!!!!!
- jsp数据库连接错误,大家帮我看下~(我是新手)
- struts上传文件的问题,着急,请帮帮忙看看啊
package com.jagie.test;
import java.io.*;
import jxl.*;
import jxl.write.*;
import jxl.format.*;
import java.util.*;
import java.awt.Color;public class Test{
public static void writeExcel(OutputStream os) throws Exception {
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);
jxl.write.Label labelC = new jxl.write.Label(0, 0, "我爱中国");
ws.addCell(labelC);
jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL,20, WritableFont.BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);
wcfFC.setBackground(jxl.format.Colour.RED);
labelC = new jxl.write.Label(6, 0, "中国爱我",wcfFC);
ws.addCell(labelC);
//写入Exel工作表
wwb.write();
//关闭Excel工作薄对象
wwb.close();
} //最好写一个这样的main方法来测试一下你的这个class是否写好了。
public static void main(String[] args)throws Exception{
File f=new File("kk.xls");
f.createNewFile();
writeExcel(new FileOutputStream(f));
}
} 写一个jsp,来利用Test这个javabean输出excel文档。///////////////////////////test_excel.jsp//////////////////////////<%@page import="com.jagie.test.Test" %>
<%
response.reset();
response.setContentType("application/vnd.ms-excel");
Test.writeExcel(response.getOutputStream());
%> 这样就大功告成了,你用ie访问test_excel.jsp就能在ie里面打开动态生成的excel文档了。一点乱码也没有。
<%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%>
<%
//Get criteria
String xlsName =request.getParameter("xlsName");
if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";
else xlsName =xlsName + ".xls";
//Set respond type for excel
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);
OutputStream os=response.getOutputStream();
//Create excel workbook
HSSFRow row;
HSSFCell cell;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Records");row = sheet.createRow( (short) 0);
cell = row.createCell((short) 0);
cell.setCellValue("ACCOUNT");
cell = row.createCell((short) 1);
cell.setCellValue("Fund");
cell = row.createCell((short) 2);
cell.setCellValue("Old Balance");
cell = row.createCell((short) 3);
cell.setCellValue("New Balance");
cell = row.createCell((short) 4);
cell.setCellValue("Charge Time");
cell = row.createCell((short) 5);
cell.setCellValue("Charge Type");
cell = row.createCell((short) 6);
cell.setCellValue("Operator");for (int i=1; i<100;i++)
{
//pay=(PaymentVO)allRecord.get(i-1);
row = sheet.createRow( (short) i); cell = row.createCell((short) 0);
cell.setCellValue("12345"); //cell.setCellValue(cdrVO.getCallNumber());
cell = row.createCell((short) 1);
cell.setCellValue("100"); //cell.setCellValue
cell = row.createCell((short) 2);
cell.setCellValue("0.0");
cell = row.createCell((short) 3);
cell.setCellValue("100.0");
cell = row.createCell((short) 4);
cell.setCellValue("2006-08-25");
cell = row.createCell((short) 5);
cell.setCellValue("web");
cell = row.createCell((short) 6);
cell.setCellValue("123456");
}
//Write to client side
wb.write(os);
os.flush();
os.close();
%>给个简单的 中间的数据自己加吧 我就是拿这个改的 希望对你有所帮助
这个帖子里有你想要的程序
org.apache.jasper.JasperException: Unable to compile class for JSPGenerated servlet error:
Syntax error on token "import", Identifier expected after this tokenAn error occurred at line: 3 in the jsp file: /xd/xdout.jsp
Generated servlet error:
HSSFRow cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /xd/xdout.jsp
Generated servlet error:
HSSFCell cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /xd/xdout.jsp
Generated servlet error:
HSSFWorkbook cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /xd/xdout.jsp
Generated servlet error:
HSSFWorkbook cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /xd/xdout.jsp
Generated servlet error:
HSSFSheet cannot be resolved to a type
这是怎么回事啊?