用图片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);
}
);
}
}
}