qq_33359572
2017-03-09 08:17
采纳率: 66.7%
浏览 928

c#word 用图片picA替换office.word文档中的图片picB、picC和picD

用图片picA替换office.word文档中的图片picB、picC和picD,这个功能卡了我两天
了,不知道怎么实现, 请求各位大神指点一下,最好有具体的源码!

下面是我用的打开 、 保存 和 关闭word的方法,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using word = Microsoft.Office.Interop.Word;
using System.Threading;
namespace word_20170301_replacePic
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private OpenFileDialog G_OpenFileDialog;
private word.Application G_wordApplication;
private object G_Missing = System.Reflection.Missing.Value;

    private void bt_select_Click(object sender, EventArgs e)
    {
        G_OpenFileDialog = new OpenFileDialog();
        G_OpenFileDialog.Filter = "(*.doc,*.docx)|*.doc;*.docx";
        DialogResult G_DialogResult = G_OpenFileDialog.ShowDialog();
        if (G_DialogResult==DialogResult.OK)
        {
            tb_selectedpath.Text = G_OpenFileDialog.FileName;
        }
    }

    private void bt_replace_Click(object sender, EventArgs e)
    {
        ThreadPool.QueueUserWorkItem(

            (o) =>
            {
                G_wordApplication = new Microsoft.Office.Interop.Word.Application();
                object path = G_OpenFileDialog.FileName;
                word.Document document = G_wordApplication.Documents.Open(
                    ref path, ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing
                    , ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing
                    , ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing, ref G_Missing
                    );
                word.Range range = document.Range(ref G_Missing, ref G_Missing);
                word.Find P_wordFind = range.Find;





                    );
                G_wordApplication.Documents.Save(ref G_Missing, ref G_Missing);
                ((word._Document)document).Close(ref G_Missing, ref G_Missing, ref G_Missing);
                ((word._Application)G_wordApplication.Application).Quit(ref G_Missing, ref G_Missing, ref G_Missing);

            }

            );
    }



}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • blownewbee 2017-03-09 11:01

    用word录制一个宏,然后对照生成vba代码写,思路是选中要替换的图片然后插入

    点赞 评论

相关推荐 更多相似问题