怎么把从数据库取出来的数据生成一个Excel文件,并显示数据

解决方案 »

  1.   

    jxl.jar自己百度 google 一堆代码  呵呵  
      

  2.   

    jxl  或者 poi 都是很好的处理方法 比较而已poi效率更高
      

  3.   

    用poi吧,百度,google是你最好的老师
      

  4.   

    有好多的组件都支持数据的导入导出 可以导出成excel的 pdf的等等 
    推荐extremecomponents 组件
      

  5.   

    jxl了,自己先研究一下,不行我这里有个写好的工具类供调用,可以给你参考一下
      

  6.   

    可以参考我博客的文章,应该还算比较详细,我曾用它处理过公司的数据
    http://blog.csdn.net/kings988/archive/2009/12/29/5099589.aspx
      

  7.   

    poi 有ComThread 进程问题,非法关闭进程一直存在
    jxl 数据量过大 会内存泄漏
      

  8.   

    jacob操作excel
    建议用jacob1.9的 具体怎么配置 网上找下吧private ActiveXComponent xl;
    private Dispatch workbooks = null;
    private Dispatch workbook = null;
    private Dispatch sheet = null;
    private String filename = null;
    private boolean readonly = false;
    private Dispatch sheets = null;// 获得sheets集合对象 public void clean() { xl = null;
    workbooks = null;
    workbook = null;
    sheet = null;
    filename = null;
    sheets = null;// 获得sheets集合对象
    } // 打开Excel文档
    public void OpenExcel(String file, boolean f) {
     ComThread.InitSTA();
    //ComThread.InitSTA(true);
    try {
    filename = file;
    xl = new ActiveXComponent("Excel.Application");
    xl.setProperty("Visible", new Variant(f));
    workbooks = xl.getProperty("Workbooks").toDispatch();
    workbook = Dispatch.invoke(
    workbooks,
    "Open",
    Dispatch.Method,
    new Object[] { filename, new Variant(false),
    new Variant(readonly) },// 是否以只读方式打开
    new int[1]).toDispatch();
    } catch (Exception e) {
    e.printStackTrace();
    }
    } // 关闭Excel文档
    public void CloseExcel(boolean f) {
    try {
    Dispatch.call(workbook, "Save");
    Dispatch.call(workbook, "Close", new Variant(f));
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    xl.invoke("Quit", new Variant[] {});
    ComThread.Release();
    // ComThread.InitMTA()
    }
    } // 写入值
    public void SetValue(String position, String type, String value) {
    sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
    Dispatch cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,
    new Object[] { position }, new int[1]).toDispatch();
    Dispatch.put(cell, type, value);
    cell = null;
    } // 读取值
    public String GetValue(String position) {
    Dispatch cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,
    new Object[] { position }, new int[1]).toDispatch();
    String value = Dispatch.get(cell, "Value").toString(); return value;
    } // 添加新的工作表(sheet),(添加后为默认为当前激活的工作表)
    public void addSheet() {
    Dispatch.get(Dispatch.get(workbook, "sheets").toDispatch(), "add");
    } // 修改当前工作表的名字
    public void modifySheetName(String newName) {
    Dispatch.put(getCurrentSheet(), "name", newName);
    } // 得到当前工作表的名字
    public String getSheetName() {
    return Dispatch.get(sheet, "name").toString();
    } // 得到工作薄的名字
    public String getWorkbookName() {
    return Dispatch.get(workbook, "name").toString();
    } // 得到sheets的集合对象
    public Dispatch getSheets() {
    sheets = Dispatch.get(workbook, "sheets").toDispatch();
    return sheets;
    } // 通过工作表名字得到工作表(未实现)
    public Dispatch getSheetByName(String name) {
    //
    return sheet;
    } // 通过工作表索引得到工作表(未实现)
    public Dispatch getSheetByIndex(String name) {
    //
    return sheet;
    } // 得到当前sheet
    public Dispatch getCurrentSheet() {
    sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
    return sheet;
    } // 得到sheet的总数
    public int getSheetCount() {
    int count = Dispatch.get(getSheets(), "count").toInt();
    return count;
    }
      

  9.   

    public static void main(String[] args) {
    try {
    File file = new File("\\test\\test_2\\WebRoot\\test\\test.xls");//给文件命名和设置路径
    WritableWorkbook book = Workbook.createWorkbook(file);
    WritableSheet ws = book.createSheet("第一页", 0);//设置页
    Label label = new Label(0,0,"我爱我家sssssss");//设置第一行里面的第一个单元格的内容
    ws.addCell(label); //添加行
    book.write();
    book.close();//完成xls生成
    } catch (IOException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }以上是生成xls文件的代码