彩票走势图

文档转换攻略第四弹!国产工具Spire.Doc 2020格式转换全新攻略来啦!

原创|使用教程|编辑:李显亮|2020-11-24 10:44:09.870|阅读 549 次

概述:Spire系列文档处理API是国产开发工具中功能可媲美Aspose的强大控件,帮助开发者轻松将文档功能集成到应用程序中。临近年终,小编为您倾情献上Spire.Doc在各类开发语言中格式转换的示例教程,记得收藏哦!

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

将文档从一种格式转换为另一种格式是Spire.Doc的主要功能之一。这种转换只不过是加载和保存操作的组合。因此,使用Spire.Doc可以将文档从任何受支持的加载格式转换为任何受支持的保存格式。

本文整理了包括在C#中以下文件格式的转换指南,希望对您有所帮助:

>>你可以点击这里下载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:\work\documents\TestSample.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:\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 { }
        }

    }
}

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);
         }

    }
}
如果您有任何疑问或需求,请随时,我们很高兴为您提供查询和咨询
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP