原創|使用教程|編輯:李顯亮|2020-11-24 10:44:09.870|閱讀 620 次
概述:Spire系列文檔處理API是國產開發工具中功能可媲美Aspose的強大控件,幫助開發者輕松將文檔功能集成到應用程序中。臨近年終,小編為您傾情獻上Spire.Doc在各類開發語言中格式轉換的示例教程,記得收藏哦!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
將文檔從一種格式轉換為另一種格式是Spire.Doc的主要功能之一。這種轉換只不過是加載和保存操作的組合。因此,使用Spire.Doc可以將文檔從任何受支持的加載格式轉換為任何受支持的保存格式。
本文整理了包括在C#中以下文件格式的轉換指南,希望對您有所幫助:
>>你可以點擊這里下載Spire.Doc for .NET測試體驗。
(篇幅較長,建議收藏閱讀)
using System; using System.Windows.Forms; using Spire.Doc; using Spire.Doc.Documents; namespace to XML { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc"); //Save doc file. document.SaveToFile("Sample.xml", FileFormat.Xml); //Launching the MS Word file. WordDocViewer("Sample.xml"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Spire.Doc; namespace Xml2Word { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("sample.xml", FileFormat.Xml); doc.SaveToFile("test.doc", FileFormat.Doc); } } }
using Spire.Doc; namespace XML2PDf { class Program { static void Main(string[] args) { Document mydoc = new Document(); mydoc.LoadFromFile(@"..\sample.xml", FileFormat.Xml); mydoc.SaveToFile("Test.doc", FileFormat.Doc); mydoc.SaveToFile("test.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("Test.pdf"); } } }
using System; using Spire.Doc; using Spire.Doc.Documents; namespace DoctoPDF { class toPDF { static void Main(string[] args) { //Load Document Document document = new Document(); document.LoadFromFile(@"E:\work\documents\TestSample.docx"); //Convert Word to PDF document.SaveToFile("toPDF.PDF", FileFormat.PDF); //Launch Document System.Diagnostics.Process.Start("toPDF.PDF"); } } }
using System; using System.Windows.Forms; using Spire.Doc; using Spire.Doc.Documents; namespace tohtml_3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"D:\Work\Stephen\2011.12.05\Sample.doc"); //Save doc file. document.SaveToFile("Sample.txt", FileFormat.Txt); //Launching the MS Word file. WordDocViewer("Sample.txt"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } } }
using Spire.Doc; using Spire.Doc.Documents; namespace Word_to_HTML { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"..\wordtohtml.doc"); //Save doc file to html document.SaveToFile("toHTML.html", FileFormat.Html); WordDocViewer("toHTML.html"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } } }
using System; using Spire.Doc; using Spire.Doc.Documents; namespace Html2Doc { class Program { static void Main(string[] args) { Document document = new Document(); document.LoadFromFile(@"D:\test.html",FileFormat.Html,XHTMLValidationType.None); document.SaveToFile("test.doc", FileFormat.Doc); } } }
using Spire.Doc; using System; namespace DOCRTF { class Program { static void Main(string[] args) { } private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc"); //Save doc file. document.SaveToFile("Sample.rtf", FileFormat.Rtf); //Launching the MS Word file. WordDocViewer("Sample.rtf"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Imaging; using Spire.Doc; using Spire.Doc.Documents; namespace HTML2Image { class Program { static void Main(string[] args) { } } }
using System; using System.Collections.Generic; using System.Text; using Spire.Doc; namespace Doc_to_xps { class Program { static void Main(string[] args) { //doc file String file = "doc to xpsdoc.docx"; //open doc document Document doc = new Document(file); //convert to xps file. doc.SaveToFile("doc to xpsSample.xps", FileFormat.XPS); System.Diagnostics.Process.Start("doc to xpsSample.xps"); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace HTML2PDFXPS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Document document = new Document(); document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None); //Save html to PDF. document.SaveToFile("Sample.pdf", FileFormat.PDF); } private void button2_Click(object sender, EventArgs e) { Document document = new Document(); document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None); //Save html to PDF. document.SaveToFile("Sample.xps", FileFormat.XPS); } } }
using Spire.Doc; namespace wordconversion.Case { class WordtoSVG { public WordtoSVG() { Document doc = new Document(); doc.LoadFromFile("Sample.docx"); doc.SaveToFile("result.svg", FileFormat.SVG); } } }如果您有任何疑問或需求,請隨時,我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn