【问题标题】:get text from word using DocumentFormat.OpenXml使用 DocumentFormat.OpenXml 从 word 中获取文本
【发布时间】:2015-07-29 09:41:11
【问题描述】:

我正在尝试从 .docx 文件中获取文本,当在 Visual Studio 中使用此代码时,它运行良好,但在上传到服务器时出现错误:

错误:无法加载文件或程序集“DocumentFormat.OpenXml,Version=2.5.5631.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。系统找不到指定的文件。

using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true)) {
    DocumentFormat.OpenXml.Wordprocessing.Body body
        = wordDoc.MainDocumentPart.Document.Body;
    totaltext = body.InnerText;
}

【问题讨论】:

    标签: c# asp.net ms-word


    【解决方案1】:

    您必须在要使用您的代码的每台机器上注册 dll“DocumentFormat.OpenXml.dll”。

    在服务器上注册 dll,它应该可以正常工作

    【讨论】:

    • 感谢它现在的作品,但如果文件有图像'文件包含损坏的数据',无论如何都可以忽略图像并只获取文本?
    • 你必须使用 body.Descendants().ToList().Foreach(i => i.Remove());
    猜你喜欢
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2019-05-26
    相关资源
    最近更新 更多