取消链接图像(将图片保存在文档中) [英] Unlinking Images (Saving pictures in document)

查看:103
本文介绍了取消链接图像(将图片保存在文档中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数千个RTF文档的目录,我需要转换为docx文件才能被其他程序读取。 这些RTF文档都包含链接中的图像。 我正在使用Office 2010 PIA以编程方式打开
RTF文档并将其保存为docx文档,使用以下代码保留向后兼容性:

I have a directory with many thousands of RTF documents that I need to convert to docx files to be read by another program.  These RTF documents all have images in them that are links.  I'm using the Office 2010 PIA to programmatically open the RTF documents and save them as docx documents, preserving the backward compatibility using the following code:

var wdWord2003 = 11;

var wdWord2003 = 11;

wordDocument.SetCompatibilityMode(wdWord2003);

wordDocument.SetCompatibilityMode(wdWord2003);

这很有用,但有一个问题:因为图像是链接的而不是嵌入的,图像在我试图加载的程序中不起作用。 如果我在Word 2010中手动编辑RTF并执行以下操作,我找到了一种方法使其工作:

This works great, but with one catch: because the images are linked and not embedded, the images are not working in the program I'm trying to load them into.  I have found a way to make it work if I manually edit the RTF in Word 2010 and do the following:


  1. 打开RTF
  2. 按ALT-EK打开"链接"按钮。对话框
  3. 在"源文件"中选择图像。列表,选中"在图片中保存图片"复选框,然后单击"确定"。
  4. 另存为docx
  5. 在"另存为"中。对话框,确保"保持与以前版本的Word的兼容性"复选框已选中。

我可以使用Office 2010 PIA以编程方式在我的C#代码中执行步骤1,4和5。 问题是,我无法弄清楚如何以编程方式执行第2步和第3步。 

I can performs steps 1, 4, and 5 programmatically in my C# code by using the Office 2010 PIA.  The problem is, I can't figure out how to perform steps 2 and 3 programmatically. 

是否有人能够指出我正确的方向"取消联系"我的文档中的图像是否已保存在文件中? 我远离办公室PIA 专家所以越详细越好。

Would anybody be able to point me in the right direction to "unlink" the images in my documents so that they are saved embedded in the file?  I am far from an Office PIA  expert so the more detail the better.

谢谢!

推荐答案

我想我现在拥有它。 看起来像这样的代码并获得成功:

I think I have it now.  Looks like this code did the trick:

的foreach(Microsoft.Office.Interop.Word.InlineShape S IN wordDocument.InlineShapes)

{

    if(s.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeLinkedPicture)

    {

        if(s.LinkFormat?.SourcePath!= null)

        {

           如果(s.LinkFormat.SourcePath.ToLower()包含(QUOT; ourimagesdirectory"))

            {

                //这是一个链接的图像,指向我们的ourimagesdirectory文件夹

              &NBSP ; s.LinkFormat.SavePictureWithDocument = true;

            }
        }
    }
}

foreach (Microsoft.Office.Interop.Word.InlineShape s in wordDocument.InlineShapes)
{
    if (s.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeLinkedPicture)
    {
        if (s.LinkFormat?.SourcePath != null)
        {
            if (s.LinkFormat.SourcePath.ToLower().Contains("ourimagesdirectory"))
            {
                // This is a linked image that points to our ourimagesdirectory folder
                s.LinkFormat.SavePictureWithDocument = true;
            }
        }
    }
}


这篇关于取消链接图像(将图片保存在文档中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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