qq_33359572 2017-03-09 08:17 采纳率: 0%
浏览 935

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条回答 默认 最新

  • threenewbee 2017-03-09 11:01
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看