【问题标题】:How to read msword file along with images, styles etc whole document?如何读取 msword 文件以及图像、样式等整个文档?
【发布时间】:2014-08-27 15:15:47
【问题描述】:

我想使用 c# 阅读 msword (.doc/.docx) 文件的全部内容,其中包含图像、样式、文本在 asp .net 中的所有内容。

我曾经写过以下代码,它运行良好。

//   Microsoft.Office.Interop.Word.ApplicationClass wordApp = new

Microsoft.Office.Interop.Word.ApplicationClass();
string filePath1 = @"G:\ABOUT.docx";
object file = filePath1;
object nullobj = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file,
                 ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                 ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                                                                 ref nullobj);
Microsoft.Office.Interop.Word.Document doc1 = wordApp.ActiveDocument;
string m_Content = doc1.Content.Text;

txtbook.Text = m_Content;
doc.Close(ref nullobj, ref nullobj, ref nullobj);

但它无法读取图像文件。

请帮助我想将数据库中的全部内容保存为 html 格式并以 html 格式检索。

【问题讨论】:

  • Open xml sdk 是很好的解决方案。

标签: c# asp.net


【解决方案1】:

注意:这可能不是您的问题的直接原因,但需要提及并且评论太长。

您正在使用 Office 自动化从 ASP.NET 应用程序访问 Word 文档。 This is not officially supported by Microsoft:

Microsoft 目前不推荐也不支持任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)的 Microsoft Office 应用程序自动化,因为 Office 可能表现出不稳定Office 在此环境中运行时的行为和/或死锁。

所以,显然,解决您的问题的方法是

【讨论】:

    【解决方案2】:

    doc1.Content.Text

    您不能使用 MS Word 文档内容文本,因为它不是 HTML 格式。 (这是在 ASP.NET 网页上显示图像和样式所必需的)

    选项 1

    您可以使用 Word Interop 将文档转换为 HTML 并以文字形式获取 HTML 标记(文本框在此处不起作用)

    选项 2

    使用 Google Doc viewer 之类的工具来查看您的 Word 文档。也有付费查看器,例如 Aspose,您可以使用它来查看 ASP.NET 站点上的 Word 文档http://www.aspose.com/.net/word-component.aspx

    在任何一种情况下,您都需要通过 google 获取有关方法的更多信息,并为您的 ASP.NET 网站实施

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2012-01-24
      • 1970-01-01
      • 2019-10-14
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      相关资源
      最近更新 更多