java应用程序中如何做报表打印界面

爱吃芋头 2008-04-12 02:51:06
如题
...全文
173 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
East271536394 2008-04-15
  • 打赏
  • 举报
回复
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的文件
davide 2008-04-12
  • 打赏
  • 举报
回复
可以用开源的报表工具实现,jf,ireport都可以。网址:wwww.open-open.com

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧