搜集了Microsoft.Office.Interop.Word生产word的一些方法,想整理编写了一些类库用于自动创建word文档的。 先将现有的劳动成功放在这里。有时间在加以完善! 一、添加页眉 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; namespace WordCreateDLL { public class AddHeader { public static void AddSimpleHeader(Application WordApp,string HeaderText) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//设置左对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); //WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;//设置字体颜色 WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置左对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,float fontsize) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.Font.Color =fontcolor;//设置字体颜色 WordApp.Selection.Font.Size = fontsize;//设置字体大小 WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置对齐方式 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } } } 二、插入图片 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; namespace WordCreateDLL { public class AddPic