【博主】反骨仔 【原文】http://www.cnblogs.com/liqingwen/p/6024827.html
之前,《開頭不講"Hello Word",讀盡詩書也枉然 : Word 操作組件介紹 - Spire.Doc》一文簡單介紹了 Spire.Doc 如何使用。這次我們來介紹如何打造一個簡單的文檔轉換器。
1 //創建文檔對象
2 var document = new Document();
3
4 //加載文檔
5 document.LoadFromFile("包含路徑的文件名"); //例:document.SaveToFile("Sample.pdf", FileFormat.PDF);
6 //保存文件
7 document.SaveToFile("包含文件名的路徑", "想轉換的文檔格式類型");
8
9 //打開文件,預覽操作
10 Process.Start("包含路徑的文件名");
這裡的文檔格式類型的支持也是比較多的,FileFormat 枚舉。
1 public enum FileFormat
2 {
3 //
4 // 摘要:
5 // Microsoft Word 97 - 2003 Binary Document.
6 Doc = 0,
7 //
8 // 摘要:
9 // Microsoft Word 97 - 2003 Binary Document or Template.
10 Dot = 1,
11 //
12 // 摘要:
13 // Microsoft Word 2007 Document.
14 Docx = 2,
15 //
16 // 摘要:
17 // Microsoft Word 2010 Document
18 Docx2010 = 3,
19 //
20 // 摘要:
21 // Microsoft Word 2013 Document
22 Docx2013 = 4,
23 //
24 // 摘要:
25 // Microsoft Word 2007 Template format.
26 Dotx = 5,
27 //
28 // 摘要:
29 // Microsoft Word 2010 Template format.
30 Dotx2010 = 6,
31 //
32 // 摘要:
33 // Microsoft Word 2013 Template format.
34 Dotx2013 = 7,
35 //
36 // 摘要:
37 // Microsoft Word 2007 macro enabled file format.
38 Docm = 8,
39 //
40 // 摘要:
41 // Microsoft Word 2010 macro enabled file format.
42 Docm2010 = 9,
43 //
44 // 摘要:
45 // Microsoft Word 2013 macro enabled file format.
46 Docm2013 = 10,
47 //
48 // 摘要:
49 // Microsoft Word 2007 macro enabled template format.
50 Dotm = 11,
51 //
52 // 摘要:
53 // Microsoft Word 2010 macro enabled template format.
54 Dotm2010 = 12,
55 //
56 // 摘要:
57 // Microsoft Word 2013 macro enabled template format.
58 Dotm2013 = 13,
59 //
60 // 摘要:
61 // PDF format
62 PDF = 14,
63 //
64 // 摘要:
65 // Rtf format
66 Rtf = 15,
67 //
68 // 摘要:
69 // Xml file format.
70 Xml = 16,
71 //
72 // 摘要:
73 // Text file format.
74 Txt = 17,
75 //
76 // 摘要:
77 // Html format.
78 Html = 18,
79 //
80 // 摘要:
81 // XPS format
82 XPS = 19,
83 //
84 // 摘要:
85 // EPub format
86 EPub = 20,
87 //
88 // 摘要:
89 // WordprocessingML format
90 WordML = 21,
91 //
92 // 摘要:
93 // Word xml format.
94 WordXml = 22,
95 //
96 // 摘要:
97 // The document is in the Word 6 or Word 95 format. Spire.Doc does not currently
98 // support loading such documents.
99 DocPre97 = 23,
100 //
101 // 摘要:
102 // Instructs Spire.Doc to recognize the format automatically.
103 Auto = 24
104 }


只是一些新手入門的代碼,看起來沒什麼好說的。
Demo 下載地址:http://git.oschina.net/liqingwen/OfficeConverter
《開頭不講"Hello Word",讀盡詩書也枉然 : Word 操作組件介紹 - Spire.Doc》