利用 Spire.Doc 组件,NuGet搜索“FreeSpire.Doc”有个免费版.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System; using Spire.Doc; using Spire.Doc.Documents; using System.IO;
public static void htmltoWord(string sFile) { //sFile = @"E:\work\documents\TestSample.html"; //Load Document Document document = new Document(); TextReader r = File.OpenText(sFile); document.LoadHTML(r,XHTMLValidationType.None); //Convert Word to PDF document.SaveToFile("toDoc.doc", FileFormat.Docx); //Launch Document System.Diagnostics.Process.Start("toDoc.doc"); }
更多官方参考:https://www.e-iceblue.com/Introduce/word-for-net-introduce/Demo.html#.XP-2Nnot0dU
|
请发表评论