EclipseRCP打印表格
??? 做過RCP項目的朋友應該都遇到過打印的問題,在C/S構架中打印應該是最麻煩的事情。SWT提供的打印功能很簡單,特別是在做表格打印的時候,需要大家使用GC自己繪出來,才能打印,對于初級的開發人員和人力不足的公司來說是非常麻煩的事情。
?? 還好ceclipse.org的老大yipsilon zheng貢獻出了一個SWT表格打印的項目,可以做到不同表格的直接打印,而且還有跨行跨列的實現,我改造了一下(把項目做了個轉碼utf-8==》GBK),然后打成JAR包放上來給大家使用。
Jar下載:
http://www.aygfsteel.com/Files/leeguannan/org.ceclipse.printer_1.0.rar
客戶虐我千百遍,我待客戶如初戀!
?? 還好ceclipse.org的老大yipsilon zheng貢獻出了一個SWT表格打印的項目,可以做到不同表格的直接打印,而且還有跨行跨列的實現,我改造了一下(把項目做了個轉碼utf-8==》GBK),然后打成JAR包放上來給大家使用。
?1
package?com.glnpu.dmp.client.platform.core.internal.util;
?2
?3
import?org.ceclipse.reporting.IReport;
?4
import?org.ceclipse.reporting.IReportPage;
?5
import?org.ceclipse.reporting.Report;
?6
import?org.ceclipse.reporting.ReportData;
?7
import?org.ceclipse.reporting.ReportUtil;
?8
import?org.eclipse.nebula.widgets.grid.Grid;
?9
import?org.eclipse.swt.printing.PrintDialog;
10
import?org.eclipse.swt.printing.Printer;
11
import?org.eclipse.swt.widgets.Table;
12
import?org.eclipse.ui.PlatformUI;
13
14
/**?*//**
15
?*?通用表格打印組件,目前提供兩個方法分別用于打印表格(Gird,Table);
16
?*?工作任務名:printContent
17
?*?@author?lign
18
?*
19
?*/
20
public?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的打印,基本上滿足我的需要了。
?2

?3

?4

?5

?6

?7

?8

?9

10

11

12

13

14


15

16

17

18

19

20



21

22


23

24

25

26

27



28

29

30

31

32

33

34

35


36

37

38

39

40



41

42

43

44

45

46

47

48


49

50

51

52



53

54

55

56

57

58

59

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用戶群