c#创建word时如何设置图片插入到指定文字后
我们学校要求做一个c#的小程序,用c#连接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 Microsoft.Office.Interop.Word;
using System.IO;
using System.Collections.Specialized;
namespace WindowsFormsApplication23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory("C:\\Users\\dell3\\Desktop"); //创建文件所在目录
string name = "7.doc";
object filename = "C:\\Users\\dell3\\Desktop\\" + name; //文件保存路径
//创建Word文档
_Application WordApp = new ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add();
//WordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //设置对齐方式
string text1 = richTextBox1.Text;
WordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
WordDoc.Paragraphs.Last.Range.Bold = 2;
WordDoc.Paragraphs.Last.Range.Font.Size = 20; //设置字号大小
WordDoc.Paragraphs.Last.Range.Text = "实验目的\n";
WordApp.Selection.TypeParagraph(); //插入段落
WordDoc.Paragraphs.Last.Range.Bold = 0;
WordDoc.Paragraphs.Last.Range.Font.Size = 13; //设置字号大小
WordDoc.Paragraphs.Last.Range.Text = text1 + "\n