c# 将html转化到word
1)HtmlToWordConverter.cs
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using HtmlAgilityPack;
using System.Collections.Generic;
namespace ConsoleApp9
{
public class HtmlToWordConverter
{
public void ConvertHtmlToWord(List<string> bodyStrings, string titleString, string docxFilePath)
{
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(docxFilePath, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
// Add centered title
if (!string.IsNullOrEmpty(titleString))
{
Paragraph titleParagraph = new Paragraph();

最低0.47元/天 解锁文章
353

被折叠的 条评论
为什么被折叠?



