如题

解决方案 »

  1.   

    可以用开源的报表工具实现,jf,ireport都可以。网址:wwww.open-open.com
      

  2.   

    package mypro;/**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2008</p>
     *
     * <p>Company: </p>
     *
     * @author 张栋芳
     * @version 1.0该类为写入到网页中的功能实现
     */
    import java.util.*;
    import java.io.*;
    import javax.swing.*;public class PrintHtml {
      private Vector veData;
      private File file;
      private FileOutputStream fos;
      private String allPane;
      private String path; //保存路径
      private String fileName; //文件名
      public PrintHtml() {};
      private String type;
      public PrintHtml(Vector veDate, String path, String fileName, String type) {
        this.veData = veDate; //要写入网页中的Vector对象
        this.path = path;
        this.type = type;
        this.fileName = fileName;
      }  /*返回值表示是否写入成功or写入完毕
       *
       *colum写入以表格形式中的字段名
       *text表格标题
       *Vector veColum列名
       *allPane拼截之后的内容
       */
      public boolean writeHtml(Vector veColum) {
        /*
         *选择写入的地
         */
        try {
          fileName = fileName + "/" + path;
          String pane = getPanel(veColum);
          byte[] all = new byte[pane.length()];
          if (!fileName.endsWith(type)) { //判断用户是否设置扩展名
            fileName = fileName.concat(type);
          }
          //System.out.println(fileName);
          JOptionPane.showMessageDialog(null, "请查看" + fileName);
          all = pane.getBytes();
          fos = new FileOutputStream(fileName);
          fos.write(all);
          fos.close();
        }
        catch (Exception ex) {
        }
        return true;
      }  private String getPanel(Vector veColum) {
        String str = "<html><head><title>2008Vista人事管理系统报表打印</title></head><body><marquee><font size='12px' color='#3399FF'>欢迎使用2008Vista人事管理系统报表功能</font></marquee><br><table border='2' align='center' bordercolor='#6699FF'  width='800'><br><caption ><font size='10px' color='#00FF00'>" +
            path + "</font></caption><tr>";
        for (int i = 0; i < veColum.size(); i++) {
          str = str + "<td>" + (veColum.get(i)) + "</td>";
        }
        str = str + "</tr><tr>";
        for (int n = 0; n < veData.size(); n++) {
          Vector voData = (Vector) veData.get(n);
          for (int j = 0; j < voData.size(); j++) {
            str = str + "<td>" + voData.get(j) + "</td>";
          }
          str = str + "</tr>";
        }
        String end = "</table></body></html>";
        return str + end;
      }
    }
    你看下这个呀,生成html的文件