C# Word里面直接插入图片对象,不用图片路径~ Word wordc#Image 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考: How to insert barcode images into a Microsoft Word document using C# or VB.NET and Barcode Professional for .NET先把图片复制到剪贴板,在粘贴进Word//Copy the image into ClipboardClipboard.SetDataObject(Image);//Paste the imagerange.Paste(); Word文档插入图片 private Word.Application G_wa;//定义Word应用程序字段 private object G_missing = //定义missing字段并赋值 System.Reflection.Missing.Value; private object G_str_path;//定义文件保存路径字段 private OpenFileDialog G_OpenFileDialog;//定义打开文件对话框字段 private FolderBrowserDialog G_FolderBrowserDialog;//定义文件夹浏览对话框字段 private void btn_Select_Click(object sender, EventArgs e) { G_FolderBrowserDialog =//创建浏览文件夹对象 new FolderBrowserDialog(); DialogResult P_DialogResult = //浏览文件夹 G_FolderBrowserDialog.ShowDialog(); if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹 { btn_New.Enabled = true;//启用新建按钮 txt_path.Text = //显示选择路径 G_FolderBrowserDialog.SelectedPath; } } private void btn_Image_Click(object sender, EventArgs e) { G_OpenFileDialog =//创建浏览文件夹对象 new OpenFileDialog(); DialogResult P_DialogResult = //浏览文件夹 G_OpenFileDialog.ShowDialog(); if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹 { txt_ImagePath.Text =//显示选择路径 G_OpenFileDialog.FileName; btn_Select.Enabled = true;//启用浏览文档按钮 this.Width = 553;//设置窗体宽度 pbox_Image.Image = //显示图片 Image.FromFile(G_OpenFileDialog.FileName); } } private void btn_New_Click(object sender, EventArgs e) { btn_New.Enabled = false;//停用新建按钮 ThreadPool.QueueUserWorkItem(//使用线程池 (P_temp) =>//使用lambda表达式 { G_wa = new Word.Application();//创建Word应用程序对象 Word.Document P_wd = G_wa.Documents.Add(//建立新文档 ref G_missing, ref G_missing, ref G_missing, ref G_missing); Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围 object P_Ranges = P_Range;//创建ojbect对象 P_wd.InlineShapes.AddPicture(//向文档中插入图片 G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges); G_str_path = string.Format(//计算文件保存路径 @"{0}\{1}", G_FolderBrowserDialog.SelectedPath, DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc"); P_wd.SaveAs(//保存Word文件 ref G_str_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._Application)G_wa.Application).Quit(//退出应用程序 ref G_missing, ref G_missing, ref G_missing); this.Invoke(//开始执行窗体线程 (MethodInvoker)(() =>//使用lambda表达式 { btn_Display.Enabled = true;//启用显示按钮 MessageBox.Show("成功创建Word文档!", "提示!"); })); }); } Process.Start() 和 WaitForExit() 没有正确执行 如何修改HtmlDocument中JS函数? 请教confirm的问题 请问这个数据怎么格式化 excel导入碰到奇怪的问题,请高手指教 一个新手关于对 System.Drawing 和 System.Windows.Forms的疑问 一个小问题,菜鸟求救! 未找到路径“E:\”的一部分。请教。 如何判断一个字符串当中是否包含某一个字符? 在线请教!!C# web应用程序问题——预览或编译后,不能正常显示链接的.aspx页面上的服务器控件 关于Jmail组件 c#Excel表格数据丢失
先把图片复制到剪贴板,在粘贴进Word//Copy the image into Clipboard
Clipboard.SetDataObject(Image);
//Paste the image
range.Paste();
private Word.Application G_wa;//定义Word应用程序字段
private object G_missing = //定义missing字段并赋值
System.Reflection.Missing.Value;
private object G_str_path;//定义文件保存路径字段
private OpenFileDialog G_OpenFileDialog;//定义打开文件对话框字段
private FolderBrowserDialog G_FolderBrowserDialog;//定义文件夹浏览对话框字段 private void btn_Select_Click(object sender, EventArgs e)
{
G_FolderBrowserDialog =//创建浏览文件夹对象
new FolderBrowserDialog();
DialogResult P_DialogResult = //浏览文件夹
G_FolderBrowserDialog.ShowDialog();
if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹
{
btn_New.Enabled = true;//启用新建按钮
txt_path.Text = //显示选择路径
G_FolderBrowserDialog.SelectedPath;
}
} private void btn_Image_Click(object sender, EventArgs e)
{
G_OpenFileDialog =//创建浏览文件夹对象
new OpenFileDialog();
DialogResult P_DialogResult = //浏览文件夹
G_OpenFileDialog.ShowDialog();
if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹
{
txt_ImagePath.Text =//显示选择路径
G_OpenFileDialog.FileName;
btn_Select.Enabled = true;//启用浏览文档按钮
this.Width = 553;//设置窗体宽度
pbox_Image.Image = //显示图片
Image.FromFile(G_OpenFileDialog.FileName);
}
} private void btn_New_Click(object sender, EventArgs e)
{
btn_New.Enabled = false;//停用新建按钮
ThreadPool.QueueUserWorkItem(//使用线程池
(P_temp) =>//使用lambda表达式
{
G_wa = new Word.Application();//创建Word应用程序对象
Word.Document P_wd = G_wa.Documents.Add(//建立新文档
ref G_missing, ref G_missing, ref G_missing, ref G_missing);
Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围
object P_Ranges = P_Range;//创建ojbect对象
P_wd.InlineShapes.AddPicture(//向文档中插入图片
G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges);
G_str_path = string.Format(//计算文件保存路径
@"{0}\{1}", G_FolderBrowserDialog.SelectedPath,
DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");
P_wd.SaveAs(//保存Word文件
ref G_str_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._Application)G_wa.Application).Quit(//退出应用程序
ref G_missing, ref G_missing, ref G_missing);
this.Invoke(//开始执行窗体线程
(MethodInvoker)(() =>//使用lambda表达式
{
btn_Display.Enabled = true;//启用显示按钮
MessageBox.Show("成功创建Word文档!", "提示!");
}));
});
}