【发布时间】:2012-01-15 05:05:45
【问题描述】:
在从 HTML 文本导出到 Excel 工作表期间,我试图保留基本格式,例如 HTML 换行符(<br>、<p>)、列表(<ol>、<ul>)等。
示例输入:
<p>This is a test.</p>
<p>This is another<br>test.</p>
<ul>
<li>10</li>
<li>20</li>
<li>30</li>
</ul>
<p>End.</p>
示例输出:
This is a test.
This is another
test.
- 10
- 20
- 30
End.
来自著名的 NirSoft 的免费实用程序 HTMLAsText 似乎正是我想要的,不幸的是它没有源代码:
即使在检查了大约。在 Stack Overflow 上有 20 个类似的问题并在 Google 上浏览了几个小时,我能找到的最接近的问题是 this Code Project article。
因此我的问题是:
是否有人知道可以将 HTML 转换为纯文本同时保留基本格式的类/库?
2013 年 5 月 10 日更新
我最终得到了一个函数,see the full code over at Pastebin。
【问题讨论】:
标签: c# html string html-parsing