实践-全程

预测未来的最好办法,就是把它创造出来 --- 阿伦.凯
数据加载中……
EclipseRCP打印表格
    做过RCP项目的朋友应该都遇到过打印的问题,在C/S构架中打印应该是最麻烦的事情。SWT提供的打印功能很简单,特别是在做表格打印的时候,需要大家使用GC自己绘出来,才能打印,对于初级的开发人员和人力不足的公司来说是非常麻烦的事情。
   还好ceclipse.org的老大yipsilon zheng贡献出了一个SWT表格打印的项目,可以做到不同表格的直接打印,而且还有跨行跨列的实现,我改造了一下(把项目做了个转码utf-8==》GBK),然后打成JAR包放上来给大家使用。
 1package com.glnpu.dmp.client.platform.core.internal.util;
 2
 3import org.ceclipse.reporting.IReport;
 4import org.ceclipse.reporting.IReportPage;
 5import org.ceclipse.reporting.Report;
 6import org.ceclipse.reporting.ReportData;
 7import org.ceclipse.reporting.ReportUtil;
 8import org.eclipse.nebula.widgets.grid.Grid;
 9import org.eclipse.swt.printing.PrintDialog;
10import org.eclipse.swt.printing.Printer;
11import org.eclipse.swt.widgets.Table;
12import org.eclipse.ui.PlatformUI;
13
14/**
15 * 通用表格打印组件,目前提供两个方法分别用于打印表格(Gird,Table);
16 * 工作任务名:printContent
17 * @author lign
18 *
19 */

20public class PrintContent {
21
22    /**
23     * 对Gird进行打印操作
24     * @param grid SWT 的nebula项目的Grid
25     * @param title 表头文字描述
26     */

27    public static void printGird(Grid grid, String title) {
28        IReportPage page = ReportUtil.convert(grid, title);
29        Report report = new Report();
30        report.addPage(page);
31        printToPrinter(report);
32        
33    }

34    
35    /**
36     * 对Table进行打印操作
37     * @param table SWT 的Table
38     * @param title 表头文字描述
39     */

40    public static void printTable(Table table, String title) {
41        IReportPage page = ReportUtil.convert(table, title);
42        Report report = new Report();
43        report.addPage(page);
44        printToPrinter(report);
45        
46    }

47    
48    /**
49     * 处理打印以及调用Printer
50     * @param report
51     */

52    private static void printToPrinter(IReport report) {
53         ReportData reportData = report.getReportData();
54         reportData.setJobName("printContent");
55         reportData.setPrinter(new Printer(new PrintDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).open()));
56         report.print();
57    }

58}

59
我封装了两个方法,一个方法处理SWT提供的Table的打印,另一个处理SWT-星云(Nebula)-Gird的打印,基本上满足我的需要了。
Jar下载:
http://www.blogjava.net/Files/leeguannan/org.ceclipse.printer_1.0.rar

声明:  
  本BLOG内的所有文章,未经特别说明,均采用“署名-非商业性使用-禁止演绎 2.5 中国大陆”授权。任何违反本协议的行为均属于非法行为。如需非商业性转载,请保留署名。如需商业性转载出版,请直接和我联系。

Creative Commons License

posted on 2007-07-20 16:21 阿南 阅读(1269) 评论(4)  编辑  收藏 所属分类: Eclipse-RCP西安java用户群

评论

# re: EclipseRCP打印表格 2007-07-24 10:04 阿源

请问有没有附带源码呢? 我想预览一下,调用report.preview();出错的。
  回复  更多评论    

# re: EclipseRCP打印表格 2007-10-01 12:09 李世虎

我的信息表格
  回复  更多评论    

# re: EclipseRCP打印表格 2008-01-23 21:34 winner

org.eclipse.nebula.widgets.grid.Grid;这个JAR哪儿下载呀,程序老报错。源码传上来看看呀
  回复  更多评论    

# re: EclipseRCP打印表格 2008-05-28 09:32 求助

我想用utf-8的老大能给我个吗

luiguangshui@163.com
  回复  更多评论    



标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交