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

问题描述 投票:-1回答:2

题 :

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

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

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

参考我做过:

  1. OLE as Image in RTF

在这里,他们完成了一个程序来提取嵌入在RTF中的OLE的图像。

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

  1. 使用OpenXML SDK。 (它无法打开RTF文件。)
  2. 其他一些像GemBox等的SDK。其中无法打开内部文件即。在RTF中的ole)

我做过的工作:

我已经完成了使用microsoft.office.interop.word.dll,它提供了准确的答案,但它不适用于服务器。

例如:它使用MS WORD打开一个RTF文件,并安装在服务器中没有安装WORD APPLICATION的客户机中。

所以,这不适合我。

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

任何人都有想法解决我的问题。

c# rtf ole aspose
2个回答
2
投票

请使用以下代码示例从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一起担任开发者布道者。


0
投票

谢谢你的回答。这是代码的另一个版本,它使用原始文件名在本地路径中迭代并保存所有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);
                }
            }
© www.soinside.com 2019 - 2024. All rights reserved.