Spire系列文档处理API是国产开发工具中功能可媲美Aspose的强大控件,帮助开发者轻松将文档功能集成到应用程序中。临近年终,小编为您倾情献上Spire.Doc在各类开发语言中格式转换的示例教程,记得收藏哦!
将文档从一种格式转换为另一种格式是Spire.Doc的主要功能之一。这种转换只不过是加载和保存操作的组合。因此,使用Spire.Doc可以将文档从任何受支持的加载格式转换为任何受支持的保存格式。
- word和XML互转
- XML转PDF
- Word转PDF
- Word转TXT
- Word和HTML互转
- Word转RTF
- HTML转image
- Word转xps
- HTML转xps
- Word转SVG
>>你可以点击这里下载Spire.Doc for .NET测试体验。
(篇幅较长,建议收藏阅读)
Word转XML
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 { } } }}
XML转Word
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); } }}
XML转PDF
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"); } }}
Word转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:workdocumentsTestSample.docx"); //Convert Word to PDF document.SaveToFile("toPDF.PDF", FileFormat.PDF); //Launch Document System.Diagnostics.Process.Start("toPDF.PDF"); } }}
Word转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:WorkStephen2011.12.05Sample.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 { } } }}
Word转HTML
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 { } } }}
HTML转Word
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); } }}
Word转RTF
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 { } } }}
HTML转图片
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) { } }}
Word转xps
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"); } }}
HTML转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); } }}
Word转SVG
using Spire.Doc;namespace wordconversion.Case{ class WordtoSVG { public WordtoSVG() { Document doc = new Document(); doc.LoadFromFile("Sample.docx"); doc.SaveToFile("result.svg", FileFormat.SVG); } }}
如果您有任何疑问或需求,请随时联系客服,我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!