asp.net怎么把div中的内容导出到word文档中;而且导出的内容不能含有源代码
2. private Parser parser;
3.
4. public ParseWork(String htmlAddress) throws ParserException {
5. parser = new Parser(htmlAddress);
6. }
7.
8. /**
9. * 获取网页标题和正文组成的文本
10. * **/
11. protected String getText(String elementId) throws ParserException{
12. NodeFilter TitleFilter = new NodeClassFilter(TitleTag.class);
13. NodeFilter ElementIdFilter = new HasAttributeFilter("id", elementId);
14. OrFilter orFilter = new OrFilter(TitleFilter, ElementIdFilter); //做一个逻辑OR Filter组合
15. NodeList list = parser.extractAllNodesThatMatch(orFilter);
16.
17. StringBuffer text = new StringBuffer();
18. for (int i = 0; i < list.size(); i++)
19. text = text.append(list.elementAt(i).toPlainTextString() + "\r\n");
20. return text.toString().trim();
21. }
22.
23. public static void main(String[] args) throws ParserException, IOException {
24. ParseWork p = new ParseWork("E://JavaEye新闻.htm");
25. String mainText = p.getText("news_content");
26.
27. //写网页正文文件
28. FileUtils.writeStringToFile(new File("E://javaeye新闻.txt"), mainText, "utf-8");
29. //摘要
30. }
31.}
---------------------------------------------------
这个可以提取div里的内容 你在加上写入word的方法就行了
不好意思把分数给错人了 下次把分数给你多一点
//记得不能用ajax 请求 | submit 和服务器按钮都可以
//sbHtml div 内容
//fileName 导出来后文件名
public static void Export(StringBuilder sbHtml, string fileName)
{
try
{
if (sbHtml.Length > 0)
{
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.Charset = "Utf-8";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName + ".docx", System.Text.Encoding.UTF8));
HttpContext.Current.Response.Write(sbHtml.ToString());
HttpContext.Current.Response.End();
}
}
catch (Exception ex)
{
Logger.WriteLog("-----------导出数据异常-----------\r\n" + ex.ToString() + "\r\n");
}