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 MSO = Microsoft.Office.Core;using Word = Microsoft.Office.Interop.Word;using System.Text.RegularExpressions;using System.Reflection;
namespace WindowsFormsApplication2{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            Word.Application WordApp = new Word.Application();            WordApp.Visible = true;            Word.Document WordDoc = WordApp.Documents.Add();            object oMissing = System.Reflection.Missing.Value;                                 string strContent;               strContent = "标题\n";            WordDoc.Paragraphs.Last.Range.Font.Name = "黑体";            WordDoc.Paragraphs.Last.Range.Font.Size = 16;            WordDoc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;            WordDoc.Paragraphs.Last.Range.Text = strContent;                       //写u入黑体文本                        strContent = "正文:在VS2008平台下\n";            WordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;            WordDoc.Paragraphs.Last.Range.Font.Name ="宋体";            WordDoc.Paragraphs.Last.Range.Font.Size = 14;            WordDoc.Paragraphs.Last.Range.ParagraphFormat.FirstLineIndent = 22;            WordDoc.Paragraphs.Last.Range.Text = strContent;                        Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Last.Range, 12, 3, ref oMissing, ref oMissing);            newTable.Cell(1, 1).Range.Text = "产品名称";            newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体            newTable.Cell(1, 2).Range.Text = "产品数量";            newTable.Cell(1, 2).Range.Bold = 2;//设置单元格中字体为粗体            WordDoc.Paragraphs.Last.Range.InlineShapes.AddPicture(@"C:\Users\Administrator\Desktop\2.jpg");            WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 50f;//图片宽度            WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 50f;//图片高度 WordDoc.SaveAs2("C:\\1.doc");            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(WordApp);            WordDoc.Close();             WordApp.Quit();        }        private void Form1_Load(object sender, EventArgs e)        {        }    }}