在jsp中写一个表格,然后我想把这个表格下载到本地.就是单击按钮提示是否保存..求详解..

解决方案 »

  1.   

    这个应该去JAVA 版。JXL 可以帮你。设计文件的导出。需要编程实现
      

  2.   

    /*

    // 设置单元格表头
    response.reset();
    response.setContentType("application/msxls");
    response.setHeader("Content-Disposition", "attachment; filename="
    + new String("出纳付款.xls".getBytes("GBK"), "ISO8859-1"));
    response.setHeader("Cache-Control", "no-cache");
    // 设置列文字格式
    WritableFont fontTitle = new WritableFont(
    WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false,
    UnderlineStyle.NO_UNDERLINE);
    WritableCellFormat formatTitle = new WritableCellFormat(fontTitle);
    formatTitle.setAlignment(jxl.format.Alignment.CENTRE);
    formatTitle.setBorder(Border.ALL, BorderLineStyle.THIN);
    formatTitle.setBackground(Colour.LIGHT_GREEN); // 设置单元格文字格式
    WritableFont fontBody = new WritableFont(WritableFont.createFont("宋体"),
    10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE);
    WritableCellFormat formatBody = new WritableCellFormat(fontBody);
    formatBody.setBorder(Border.ALL, BorderLineStyle.THIN);
    formatBody.setAlignment(jxl.format.Alignment.CENTRE);
    NumberFormat nf = new NumberFormat("0.00");
    WritableCellFormat wcfN = new WritableCellFormat(fontBody, nf);
    wcfN.setBorder(Border.ALL, BorderLineStyle.THIN);
    wcfN.setAlignment(jxl.format.Alignment.CENTRE); List<Object[]> list = new ArrayList<Object[]>();
    list = brPlanBalanceReconcService.getPayList(companyId); WritableWorkbook book = null;
    try {
    book = Workbook.createWorkbook(response.getOutputStream());
    // 设置excel第一列
    WritableSheet sheet = book.createSheet("出纳付款", 0);
    Label label = new Label(0, 0, "序号", formatTitle);
    sheet.addCell(label);
    label = new Label(1, 0, "公司/部门", formatTitle);
    sheet.addCell(label);
    label = new Label(2, 0, "凭证编号", formatTitle);
    sheet.addCell(label);
    label = new Label(3, 0, "出/收款行", formatTitle);
    sheet.addCell(label);
    label = new Label(4, 0, "出/收款账户", formatTitle);
    sheet.addCell(label);
    label = new Label(5, 0, "对方开户行", formatTitle);
    sheet.addCell(label);
    label = new Label(6, 0, "对方账户", formatTitle);
    sheet.addCell(label);
    label = new Label(7, 0, "金额", formatTitle);
    sheet.addCell(label);
    label = new Label(8, 0, "年月", formatTitle);
    sheet.addCell(label); // 设置单元格宽度
    sheet.setColumnView(0, 10);
    sheet.setColumnView(1, 15);
    sheet.setColumnView(2, 20);
    sheet.setColumnView(3, 20);
    sheet.setColumnView(4, 20);
    sheet.setColumnView(5, 20);
    sheet.setColumnView(6, 20);
    sheet.setColumnView(7, 15);
    sheet.setColumnView(8, 15);
    if (list != null && list.size() > 0) {
    for (int i = 0; i < list.size(); i++) {
    Object[] temp = (Object[]) list.get(i);
    label = new Label(0, i + 1, i + 1 + "", formatBody);// 文件序号
    sheet.addCell(label);
    if (temp[0] == null) {
    temp[0] = "";
    }
    label = new Label(1, i + 1, temp[0] + "", formatBody);// 公司/部门
    sheet.addCell(label);
    if (temp[1] == null) {
    temp[1] = "";
    }
    label = new Label(2, i + 1, temp[1] + "", formatBody);// 凭证编号
    sheet.addCell(label);
    if (temp[2] == null) {
    temp[2] = "";
    }
    label = new Label(3, i + 1, temp[2] + "", formatBody);// 出/收款行
    sheet.addCell(label);
    if (temp[3] == null) {
    temp[3] = "";
    }
    label = new Label(4, i + 1, temp[3] + "", formatBody);// 出/收款账户
    sheet.addCell(label);
    if (temp[4] == null) {
    temp[4] = "";
    }
    label = new Label(5, i + 1, temp[4] + "", formatBody);// 对方开户行
    sheet.addCell(label);
    if (temp[5] == null) {
    temp[5] = "";
    }
    label = new Label(6, i + 1, temp[5] + "", formatBody);// 对方账户
    sheet.addCell(label);
    if (temp[6] == null) {
    temp[6] = "";
    }
    label = new Label(7, i + 1, temp[6] + "", formatBody);// 金额
    sheet.addCell(label);
    if (temp[7] == null) {
    temp[7] = "";
    }
    label = new Label(8, i + 1, temp[7] + "", formatBody);// 月份
    sheet.addCell(label); }
    }

    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    // 写出并关闭流
    if (book != null) {
    try {
    book.write();
    book.close(); } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (WriteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }*/贴个例子给你,研究研究