word convert to html,How to Convert HTML to Word

Why Use C#/VB.NET to Convert HTML to Word?

Save HTML file content into Word document can be very easy only through copy and paste. Or users can right click on the html document and then choose edit. It automatically opens in Word. Then you can save it as a Word .doc file. But first, “Copy and paste” method can only used on text-only pages or some very basic HTML pages. For complex HTML, it may happen to formatting is not rendered properly, images are placed incorrectly, sometimes even missing, and CSS layout seems to be ignored completely. Second, edit on HTML document also will lead CSS ignored. But with C#/VB.NET, save files from HTML to Word could be much better. Furthermore, it doesn’t need Microsoft Office installed on your system.

How to Use C#/VB.NET to Convert HTML to Word?

With a .NET library, we can use C#/VB.NET convert HTML to Word effortlessly. Spire.Doc is a MS Word component which enables user to perform a wide range of Word document processing tasks directly for .NET and Silverlight. Like Microsoft Word can help you save Word files to different format, Spire.Doc also support converting files from Word Doc to HTML, PDF, XML, RTF, Text, Docx, Dot, etc. Furthermore, besides converting files from Word to other popular file format, Spire.Doc can also transfer files from HTML to Doc, XML to Doc, RTF to Doc, Text to Doc, Docx to Doc, Dot to Doc, etc.

Download Spire.Doc (or Spire.Office) with .NET framework together and follow the simple steps below to convert HTML to Word.

Step 1: Create a project in Visual Studio and add Spire.Doc as reference.

Step 2: Load the HTML file which will be converted to Word doc file by using the follow code:

Document document = new Document();

document.LoadFromFile(@"D:\Work\Stephen\2011.12.06\test.html",FileFormat.Html,XHTMLValidationType.None);

Step 3: The following code below can help us convert the HTML file to Word doc. Furthermore, Spire.Doc also enables convert HTML to PDF, XML, ePub, Text, Dot, etc.

document.SaveToFile("test.doc", FileFormat.Doc);

Step 4: Write the whole simple code into the project and press F5 to start the conversion.

Full code:

[C#]

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

}

}

}

[VB.NET]

Imports System

Imports Spire.Doc

Imports Spire.Doc.Documents

Namespace Html2Doc

Friend Class Program

Shared Sub Main(ByVal args() As String)

Dim document As New Document()

document.LoadFromFile("D:\test.html",FileFormat.Html,XHTMLValidationType.None)

document.SaveToFile("test.doc", FileFormat.Doc)

End Sub

End Class

End Namespace

The output Word doc file can be find in Bin folder

4aa434426acbccf75d84ad575121de08.png

Effective Screeshot:

04a47c354ce1b1f658d8a5243f78d509.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值