以编程方式更新链接对象中的链接对象 [英] Programatically update linked objects in linked objects

查看:62
本文介绍了以编程方式更新链接对象中的链接对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

只是试图将一个单词文档(test0.docx)嵌入到另一个单词文档(test1.docx)中作为链接对象.到目前为止很容易.现在,我获取了此文档(test1.docx),并将其嵌入到下一个文档(test2.docx)中.这里的问题是,如果我更改了test0.docx,请保存并关闭它,test2.docx不会使用新文本进行更新.

有机会以编程方式解决吗?

提前致谢

奥利

有一个可行的主意...不幸的是它没有...有人有主意吗?

Hello,

just tried to embed a word document (test0.docx) in another word document (test1.docx) as linked object. So far so easy. Now I took this document (test1.docx) and embedded it in the next one (test2.docx). Issue here is, that if I change test0.docx, save it and close it test2.docx isn''t updated with the new text.

Is there a chance to work it out programatically?

Thx in advance

Olli

Got an idea which should work... unfortunately it dose not... Anybody an idea?

public static void DoSomething(string docPath)
{
  Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
  try
  {
    Document doc = wordApp.Documents.Open(docPath, ReadOnly: false, Visible: false, AddToRecentFiles: false);
    doc.Activate();
    for(int i = doc.InlineShapes.Count; i > 0; i--)
    {
      if (doc.InlineShapes[i].Type == WdInlineShapeType.wdInlineShapeLinkedOLEObject)
      {
        if (doc.InlineShapes[i].LinkFormat.SourceName.Split('.')[doc.InlineShapes[i].LinkFormat.SourceName.Split('.').Length - 1] == "docx")
          DoSomething(doc.InlineShapes[i].LinkFormat.SourceFullName);
        doc.InlineShapes[i].LinkFormat.Update();
        doc.Save();
      }
    }
    (doc as _Document).Close();
    (wordApp as _Application).Quit();
  }
  catch { }
  System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
}

推荐答案

已解决.不是我最想要的解决方案,但至少可以奏效.如果您使用".doc"而不是".docx",则上述代码可以正常工作.对于微软公司而言,如此之妙的是基于xml的新优秀文件格式……至少在这种情况下;-)
似乎未引用docx中的OLEObject.而是将它们另存为xml中的".emf"图片.也许".docx"的解决方案是直接编辑基于xml的".docx"或以编程方式将源文档中的InlineShape作为Word文档打开.
Solved it. Not the solution I would like most but at least it works. Above code just works fine if you use ".doc" instead of ".docx". So much for microsofts wonderful new xml based file formats... at least in that case ;-)
It seems, that the OLEObjects in docx are not referenced. Instead they are saved as ".emf"-pictures inside the xml. Maybe possible solutions for ".docx" would be to edit the xml based ".docx" directly or open the InlineShape in the source document as word document programatically.


这篇关于以编程方式更新链接对象中的链接对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆