大夢想家

          5年開發工程師,2年實施經理,X年售前顧問,......
          數據加載中……
          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.aygfsteel.com/Files/leeguannan/org.ceclipse.printer_1.0.rar

          客戶虐我千百遍,我待客戶如初戀!

          posted on 2007-07-20 16:21 阿南 閱讀(3098) 評論(7)  編輯  收藏 所屬分類: 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
            回復  更多評論    

          # re: EclipseRCP打印表格 2008-07-07 17:50 huangdan

          IReportPage page = ReportUtil.convert(grid, title);
          convert(grid, title)這個方法出錯了,怎么改?
          怎么樣使用這個類來進行打印呀?
          謝謝!!!
            回復  更多評論    

          # re: EclipseRCP打印表格 2008-07-21 23:49 何敏··

          謝謝大家把你們的資源共享。
          hemin108@126.com
            回復  更多評論    

          # re: EclipseRCP打印表格 2010-10-11 16:36 zmh

          博主你好,我在調用打印表格的方法時出現如下錯誤:Exception in thread "main" java.lang.IllegalStateException: Workbench has not been created yet.
          at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
          at com.ytkj.kq.print.PrintContent.printToPrinter(PrintContent.java:55)
          at com.ytkj.kq.print.PrintContent.printTable(PrintContent.java:44)
          at com.ytkj.kq.PersonnelData.PersonnelChange$6.widgetSelected(PersonnelChange.java:404)
          at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
          at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
          at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
          at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
          at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
          at com.ytkj.kq.PersonnelData.PersonnelChange.open(PersonnelChange.java:139)
          at com.ytkj.kq.Main$14.widgetSelected(Main.java:852)
          at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
          at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
          at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
          at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
          at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
          at com.ytkj.kq.Main.<init>(Main.java:278)
          at com.ytkj.kq.Main.main(Main.java:243)

          能幫忙解決一下嗎,希望能將解決方法發到小弟的郵箱:lqmh18@163.com
          在此先謝過了
            回復  更多評論    
          主站蜘蛛池模板: 屯留县| 永康市| 西丰县| 尚义县| 翁牛特旗| 镇康县| 崇仁县| 布尔津县| 工布江达县| 长阳| 梨树县| 合山市| 乐平市| 雷波县| 东乡县| 晴隆县| 天祝| 辉县市| 红原县| 澄迈县| 西和县| 桃园县| 诸暨市| 扎赉特旗| 云和县| 长葛市| 巫山县| 乐山市| 恩平市| 吉水县| 平山县| 文化| 康定县| 鄱阳县| 卓尼县| 拜城县| 义乌市| 巫山县| 澎湖县| 图们市| 兴仁县|