首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

【叨、校长】JAVA WEB 导出Excel表格

2012-12-28 
【叨、校长】JAVA WEB 导出Excel报表?package com.daodao.servletimport java.io.IOExceptionimport java.i

【叨、校长】JAVA WEB 导出Excel报表

?

package com.daodao.servlet;import java.io.IOException;import java.io.OutputStream;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFCellStyle;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;public class TestServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String[] header={"第一","第二","第三"};String[][] data={{"A1","A2","A3"},{"B1","B2","B3"},{"C1","C2","C3"}};HSSFWorkbook wb = new HSSFWorkbook();        HSSFSheet sheet = wb.createSheet("测试");        HSSFRow row = sheet.createRow((int) 0);        HSSFCellStyle style = wb.createCellStyle();        for (int i = 0; i < header.length; i++) {            HSSFCell cell = row.createCell((short) i);            cell.setCellValue(header[i]);            sheet.autoSizeColumn((short) i);        }        for (int i = 0; i < data.length; i++) {            row = sheet.createRow(i + 1);            row.createCell((short) 0).setCellValue(data[i][0]);            row.createCell((short) 1).setCellValue(data[i][1]);            row.createCell((short) 2).setCellValue(data[i][2]);        } response.setContentType("application/vnd.ms-excel");   response.setHeader("Content-disposition", "attachment;filename=test.xls");   OutputStream ouputStream = response.getOutputStream();   wb.write(ouputStream);  }}
1 楼 公子芒 昨天   可以请教下:
  我 也在使用jxl 导出Excel表,可能是测试数据过大 ,出现这样的错误。不知道是什么原因。前提是MyEclipse 没有报错。
    jxl.write.biff.JxlWriteException:Cell has already been added to worksheet. 2 楼 wb1991wb 昨天   公子芒 写道可以请教下:
  我 也在使用jxl 导出Excel表,可能是测试数据过大 ,出现这样的错误。不知道是什么原因。前提是MyEclipse 没有报错。
    jxl.write.biff.JxlWriteException:Cell has already been added to worksheet.
你看看是不是创建了同一个cell,就是cell的位置重复了

热点排行