【发布时间】:2014-05-23 03:49:57
【问题描述】:
我正在尝试使用 Open XML 库从保存的 HTML 文件中生成 word 文档。 如果 HTML 文件不包含图像,我可以简单地使用下面的代码并将文本内容写入 word doc。
HtmlDocument doc = new HtmlDocument();
doc.Load(fileName); //fileName is the Htm file
string Detail = string.Empty;
string webData = string.Empty;
HtmlNode hcollection = doc.DocumentNode.SelectSingleNode("//body");
Detail = hcollection.InnerText;
但是,如果 HTML 文件包含嵌入的图像,我很难将该图像包含在 word doc 中。
使用hcollection.InnerText只写文字部分,排除图片。
当我使用时
HtmlNode hcollection = doc.DocumentNode.SelectSingleNode("//body");
Detail = hcollection.InnerHtml;
所有的 HTML 标签都被写入 word doc 以及标签中的 Image 路径
<table border='0' width='100%' cellpadding='0' cellspacing='0' align='center'>
<tr><td valign='top' align="left">
<div style='width:100%'><div id="div_img">
<div>
<img src="http://www.myweb.com/web/img/2013/07/18/img_1.jpg">
<span>Sample Text</span></div></div><br><br>Sample Text Content here<br><br> </div></td></tr></table>
如何删除 html 标签,而不是像
这样显示的路径<img src="http://www.myweb.com/web/img/2013/07/18/img_1.jpg">
相应的图片被加载。
请帮忙。
【问题讨论】:
标签: c# asp.net openxml openxml-sdk