读取包含 OLE 嵌入对象的 RTF 文件

Reading RTF File Containing an OLE Embedded Object

问题:

我需要读取包含 OLE 对象的 RTF 文件作为内部文档。

RTF 文件 = [其中嵌入了 Ole 对象(word 文档)。]

Sample RTF File that contains word as OLE Embedded into it.

参考我做过:

  1. OLE as Image in RTF

他们在这里做了一个程序来提取以 OLE 格式嵌入到 RTF 中的图像。

我已经提取了标记为正确答案的程序,但它对我不起作用。

  1. 使用 OpenXML SDK。 (无法打开 RTF 文件。)

  2. 一些其他 SDK,如 GemBox 等。无法打开 innerdocument 即。 RTF 中的 ole)

我做过的工作:

我已经使用 microsoft.office.interop.word.dll 给出了准确的答案,但它在服务器上不起作用。

例如: 它使用 MS WORD 打开一个 RTF 文件,该文件安装在客户端机器上,而服务器上没有安装 WORD 应用程序。

所以,这个不适合我。

我需要打开并阅读 RTF OLE 内容并且我需要存储在一个字符串中(例如)。 bcoz with string 我可以做很多事情。

谁能解决我的问题?

请使用以下代码示例从RTF中提取OLE对象(Word文档)并将其导入Aspose.Words'DOM以阅读其内容。希望对你有帮助。

Document doc = new Document(MyDir + "SAMPLE.rtf");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
if (shape.OleFormat != null)
{
    //Save the document to disk.
    shape.OleFormat.Save(MyDir + "output" + shape.OleFormat.SuggestedExtension);

    if (shape.OleFormat.SuggestedExtension == ".docx")
    {
        //Import the .docx ole object into Aspose.Words' DOM
        Document ole = new Document(MyDir + "output" + shape.OleFormat.SuggestedExtension);
        Console.WriteLine(ole.ToString(SaveFormat.Text));
    }

}

我在 Aspose 工作,担任开发人员推广员。

感谢您的上述回答。这是代码的另一个版本,它使用本地路径中的原始文件名迭代并保存所有 OLE。

string MyDir = @"E:\temp\";
            Document doc = new Document(MyDir + "Requirement#4.rtf");

            NodeCollection nodeColl = doc.GetChildNodes(NodeType.Shape, true);
            foreach (var node in nodeColl)
            {
                Shape shape1 = (Shape)node;
                if (shape1.OleFormat != null)
                {
                    shape1.OleFormat.Save(MyDir + shape1.OleFormat.SuggestedFileName + shape1.OleFormat.SuggestedExtension);
                }
            }