从Word文档转换为HTML [英] Convert from Word document to HTML
本文介绍了从Word文档转换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要保存使用Word查看器的HTML格式的Word文档,而无需安装在我的机器字。 ?有什么办法在C#中做到这一点。
I want to save the Word document in HTML using Word Viewer without having Word installed in my machine. Is there any way to accomplish this in C#?
推荐答案
有关.docx文件转换为HTML格式,你可以用下面的代码:
For converting .docx file to HTML format, you can use following code:
-
添加引用OpenXmlPowerTools.dll
码:
Add reference to OpenXmlPowerTools.dll Code :
using OpenXmlPowerTools;
using DocumentFormat.OpenXml.Wordprocessing;
byte[] byteArray = File.ReadAllBytes(DocxFilePath);
using (MemoryStream memoryStream = new MemoryStream())
{
memoryStream.Write(byteArray, 0, byteArray.Length);
using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
{
HtmlConverterSettings settings = new HtmlConverterSettings()
{
PageTitle = "My Page Title"
};
XElement html = HtmlConverter.ConvertToHtml(doc, settings);
File.WriteAllText(HTMLFilePath, html.ToStringNewLineOnAttributes());
}
}
这篇关于从Word文档转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文