1、公式及表格操作
- 插入公式
string strDir = Directory.GetCurrentDirectory();
string docName = strDir + @"\test.doc";
object nothing = System.Reflection.Missing.Value;
MSWord.ApplicationClass newapp = null;
MSWord.Document newdoc = null;
object docObject = docName;
newapp = new MSWord.ApplicationClass();
newapp.Visible = true; //所打开的MSWord程序,是否是可见的
newdoc = newapp.Documents.Add(ref docObject, ref nothing, ref nothing, ref nothing);//生成一个word文档
//插入公式
object oEndOfDoc = "\\endofdoc";
MSWord.Range rang1 = newdoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
object fieldType = MSWord.WdFieldType.wdFieldEmpty;
object formula = @"eq \i(a,b,ξxdx)";
object presrveFormatting = false;
rang1.Text = formula.ToString();
rang1.Font.Size = 14;
rang1.Font.Bold = 0;
rang1.Font.Subscript = 0;
rang1.Font.Color = MSWord.WdColor.wdColorBlue;
rang1.Font.Name = "宋体";
rang1.ParagraphFormat.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle;
rang1.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphRight;
newdoc.Fields.Add(rang1, ref fieldType, ref formula, r