以下 jsp 代码未生成任何 excel 文件。请帮忙。或者有人可以告诉我将表格数据从 jsp/javascript 导出到 excel 表的其他方法吗?
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.*"%>
<%@page language="java" import="java.sql.*"%>
<%@page language="java" import="pack.DbBean"%>
<%@ page import="java.io.*" %>
<%@ page import="jxl.*" %>
<%@ page import="jxl.write.*" %>
<%@ page import="jxl.Workbook" %>
<%@ page import="jxl.write.Label" %>
<%@ page import="jxl.write.WritableSheet" %>
<%@ page import="jxl.write.WritableWorkbook" %>
<jsp:useBean id="db" class="pack.DbBean" scope="session"/>
<%
try{
WritableWorkbook workbook = Workbook.createWorkbook(new File("output.xls"));
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "A label record");
sheet.addCell(label);
jxl.write.Number number = new jxl.write.Number(3, 4, 3.1459);
sheet.addCell(number);
workbook.write();
workbook.close();
}
catch(Exception e)
{
throw new ServletException("Exception in Excel Sample Servlet", e);
} finally
{
if (out != null)
out.close();
}
%>