標籤:ati url 需要 dml span 對象 post 功能 word
打造一個很簡單的文檔轉換器 - 使用組件 Spire.Office目錄
- Spire.Office 介紹
- 庫引用
- 介面預覽
- 程式碼片段
Spire.Office 介紹
關於 Spire.Office,它是一個專門為開發人員建立,讀取,寫入設計的庫,轉換和從列印 word 文檔檔案。作為一個獨立的 .NET組件,它不需要在機器上安裝微軟的 Word 等辦公軟體。然而,它可以將微軟的“文檔建立功能”整合到任何開發人員的網路應用程式中。它是一個可靠的 MS Word 的API,可以執行許多Word文檔處理任務。它支援 C #,VB.NET,ASP.NET 和 ASP.NET 的 MVC,以及支援Word 97-2003 / 2007 / 2010 / 2013 並能將它們轉換為常用的檔案格式,如 XML,RTF,TXT,XPS,EPUB 等高品質轉換,反之亦然。它是一款來自 E-iceblue 公司開發的組件。
以下是摘取“慧都控制項網”對該公司的簡單介紹。
E-iceblue 是一個 .NET、Silverlight 和 WPF 開發控制項供應商。e-iceblue 的目標是為客戶提供高品質的控制項去閱讀和寫作不同格式的檔案。E-iceblue 的控制項被大部分的世界 500 強企業廣泛使用。e-iceblue 的主要開發人員在開發高效能、高品質的 .NET、Silverlight 和 WPF 控制項技術方面有超過 10 年的經驗。每天,e-iceblue 產品協助大量的來自超過 60 個國家的大型/小型公司的開發人員從更容易、更好、更快和更富有成效的開發和向顧客交付可靠的應用程式。
庫引用
我只是想打造 word 和 excel 轉換器,所以只在 Nuget 中安裝中的 ~.Doc 和 ~.XLS。
介面預覽
我發現當 ~.Doc 和 ~.XLS 同時裝在一個類庫中的時候,在轉換部分類型時會出現異常,所以採取了分層的形式。
WordConverter 只引用 ~.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 = 24104 }
只是一些新手入門的代碼,看起來沒什麼好說的。
Demo :http://git.oschina.net/liqingwen/OfficeConverter
傳送門
《開頭不講"Hello Word",讀盡詩書也枉然 : Word 操作組件介紹 - Spire.Doc》
[.NET] 打造一個很簡單的文檔轉換器 - 使用組件 Spire.Office