word生成

        private Microsoft.Office.Interop.Word.Document wDoc = null;
        private Microsoft.Office.Interop.Word.Application wApp = null;
        public Microsoft.Office.Interop.Word.Document Document
        {
            get { return wDoc; }
            set { wDoc = value; }
        }
        public Microsoft.Office.Interop.Word.Application Application
        {
            get { return wApp; }
            set { wApp = value; }
        }
        #endregion
        #region 从模板创建新的Word文档
        public bool CreateNewWordDocument(string templateName)
        {
            try
            {
                return CreateNewWordDocument(templateName, ref wDoc, ref wApp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 从模板创建新的Word文档,并且返回对象Document,Application
        public static bool CreateNewWordDocument(string templateName, ref Microsoft.Office.Interop.Word.Document wDoc, ref  Microsoft.Office.Interop.Word.Application WApp)
        {
            Microsoft.Office.Interop.Word.Document thisDocument = null;
            Microsoft.Office.Interop.Word.Application thisApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
            thisApplication.Visible = false;
            thisApplication.Caption = "";
            thisApplication.Options.CheckSpellingAsYouType = false;
            thisApplication.Options.CheckGrammarAsYouType = false;

            Object Template = templateName;
            Object NewTemplate = false;
            Object DocumentType = Microsoft.Office.Interop.Word.WdNewDocumentType.wdNewBlankDocument;
            Object Visible = true;
            try
            {
                Microsoft.Office.Interop.Word.Document wordDoc = thisApplication.Documents.Add(ref Template, ref NewTemplate, ref DocumentType, ref Visible);
                thisDocument = wordDoc;
                wDoc = wordDoc;
                WApp = thisApplication;
                return true;
            }
            catch (Exception ex)
            {
                string err = string.Format("创建Word文档出错,错误原因:{0}", ex.Message);
                throw new Exception(err, ex);
            }
        }
        #endregion
        #region 文档另存为其他文件名
        public bool SaveAs(string fileName)
        {
            try
            {
                return SaveAs(fileName, wDoc);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 自定义表格
        public void drawTable(int linesize)
        {
            Object Nothing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.Table secondTable = wDoc.Tables.Add(this.wApp.Selection.Range, 13 + linesize, 5, ref  Nothing, ref  Nothing);
            //this._wordApplication.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.wd
            //设置表格样式wdLineStyleThickThinLargeGap
            secondTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
            secondTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            secondTable.Cell(1, 1).Width = 100f;
            //secondTable.Rows[2].Height = 55f;//指定行的高度
            secondTable.Rows[1].Height = 20f;
            secondTable.Cell(1, 1).Range.Text = "测试用例名称";
            secondTable.Cell(1, 1).Range.Bold = 8;
            secondTable.Cell(1, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            // 填充表格内容
            secondTable.Cell(1, 2).Merge(secondTable.Cell(1, 5));
            secondTable.Cell(1, 2).Range.Text = "logo";
            secondTable.Cell(1, 2).Select();
            secondTable.Cell(1, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(2, 1).Merge(secondTable.Cell(2, 2));
            secondTable.Cell(2, 1).Range.Text = "测试用例标识";
            secondTable.Cell(2, 1).Range.Bold = 8;
            secondTable.Cell(2, 1).Select();
            secondTable.Cell(2, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(2, 1).Width = 100f;
            secondTable.Cell(2, 2).Width = 115f;
            secondTable.Cell(2, 2).Range.Text = "logo";
            secondTable.Cell(2, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(2, 3).Width = 111f;
            secondTable.Cell(2, 3).Range.Text = "测试追踪";
            secondTable.Cell(2, 3).Range.Bold = 8;
            secondTable.Cell(2, 3).Select();
            secondTable.Cell(2, 3).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(2, 4).Width = 115f;
            secondTable.Cell(2, 4).Range.Text = "logo";
            secondTable.Cell(2, 4).Select();
            secondTable.Cell(2, 4).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(3, 1).Width = 100f;
            secondTable.Cell(3, 2).Merge(secondTable.Cell(3, 5));
            secondTable.Cell(3, 1).Range.Text = "测试用例描述";
            secondTable.Cell(3, 1).Range.Bold = 8;
            secondTable.Cell(3, 1).Select();
            secondTable.Cell(3, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(3, 2).Range.Text = "logo";
            secondTable.Cell(3, 2).Select();
            secondTable.Cell(3, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(4, 1).Width = 100f;
            secondTable.Cell(4, 2).Merge(secondTable.Cell(4, 5));
            secondTable.Cell(4, 1).Range.Text = "测试方法";
            secondTable.Cell(4, 1).Range.Bold = 8;
            secondTable.Cell(4, 1).Select();
            secondTable.Cell(4, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(4, 2).Range.Text = "黑盒测试";
            secondTable.Cell(4, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(5, 1).Width = 100f;
            secondTable.Cell(5, 1).Range.Text = "测试类型";
            secondTable.Cell(5, 1).Range.Bold = 8;
            secondTable.Cell(5, 1).Select();
            secondTable.Cell(5, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(5, 2).Merge(secondTable.Cell(5, 5));
            secondTable.Cell(5, 2).Range.Text = "功能测试";
            secondTable.Cell(5, 2).Select();
            secondTable.Cell(5, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(6, 1).Width = 100f;
            secondTable.Cell(6, 2).Merge(secondTable.Cell(6, 5));
            secondTable.Cell(6, 1).Range.Text = "前提和约束(包括初始化要求)";
            secondTable.Cell(6, 1).Range.Bold = 8;
            secondTable.Cell(6, 1).Select();
            secondTable.Cell(6, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(6, 2).Range.Text = "";
            secondTable.Cell(6, 2).Select();
            secondTable.Cell(6, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(7, 1).Width = 100f;
            secondTable.Cell(7, 2).Merge(secondTable.Cell(7, 5));
            secondTable.Cell(7, 1).Range.Text = "终止测试条件";
            secondTable.Cell(7, 1).Select();
            secondTable.Cell(7, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(7, 1).Range.Bold = 8;
            secondTable.Cell(7, 2).Range.Text = "所有测试步骤执行结束而终止,或因测试步骤不能执行,软件运行错误等而终止";
            secondTable.Cell(7, 2).Select();
            secondTable.Cell(7, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(8, 1).Merge(secondTable.Cell(8, 5));
            secondTable.Cell(8, 1).Range.Text = "测试过程";
            secondTable.Cell(8, 1).Range.Bold = 8;
            secondTable.Cell(8, 1).Select();
            secondTable.Cell(8, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            secondTable.Cell(8, 1).Width = 441f;


            secondTable.Cell(9, 1).Width = 50f;
            secondTable.Cell(9, 1).Range.Text = "序号";
            secondTable.Cell(9, 1).Range.Bold = 8;
            secondTable.Cell(9, 1).Select();
            secondTable.Cell(9, 1).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            secondTable.Cell(9, 2).Width = 130f;
            secondTable.Cell(9, 2).Range.Text = "输入及操作步骤";
            secondTable.Cell(9, 2).Range.Bold = 8;
            secondTable.Cell(9, 2).Select();
            secondTable.Cell(9, 2).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            secondTable.Cell(9, 3).Width = 100f;
            secondTable.Cell(9, 3).Range.Text = "期望测试结果";
            secondTable.Cell(9, 3).Range.Bold = 8;
            secondTable.Cell(9, 3).Select();
            secondTable.Cell(9, 3).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            secondTable.Cell(9, 4).Width = 80f;
            secondTable.Cell(9, 4).Range.Text = "评估准则";
            secondTable.Cell(9, 4).Range.Bold = 8;
            secondTable.Cell(9, 4).Select();
            secondTable.Cell(9, 4).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            secondTable.Cell(9, 5).Width = 81f;
            secondTable.Cell(9, 5).Range.Text = "实际测试结果";
            secondTable.Cell(9, 5).Range.Bold = 8;
            secondTable.Cell(9, 5).Select();
            secondTable.Cell(9, 4).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            for (int i = 1; i < linesize + 1; i++)
            {
                //for (int j = 1; j < 5; j++)
                //{
                //    secondTable.Cell(9 + i, j).Select();
                //    secondTable.Cell(9 + i, j).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                //}
                secondTable.Cell(9 + i, 1).Range.Text = i.ToString();
                secondTable.Cell(9 + i, 1).Width = 50f;
                secondTable.Cell(9 + i, 2).Range.Text = "logo";
                secondTable.Cell(9 + i, 2).Width = 130f;
                secondTable.Cell(9 + i, 3).Range.Text = "logo";
                secondTable.Cell(9 + i, 3).Width = 100f;
                secondTable.Cell(9 + i, 4).Range.Text = "logo";
                secondTable.Cell(9 + i, 4).Width = 80f;
                secondTable.Cell(9 + i, 5).Range.Text = "";
                secondTable.Cell(9 + i, 5).Width = 81f;
            }

            secondTable.Cell(10 + linesize, 1).Range.Text = "设计人员";
            secondTable.Cell(10 + linesize, 1).Select();
            secondTable.Cell(10 + linesize, 1).Range.Bold = 8;
            secondTable.Cell(10 + linesize, 1).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(10 + linesize, 1).Width = 70f;

            secondTable.Cell(10 + linesize, 2).Range.Text = "mycount";
            secondTable.Cell(10 + linesize, 2).Select();
            secondTable.Cell(10 + linesize, 2).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            secondTable.Cell(10 + linesize, 2).Width = 150f;

            secondTable.Cell(10 + linesize, 3).Merge(secondTable.Cell(10 + linesize, 4));
            secondTable.Cell(10 + linesize, 3).Width = 71f;
            secondTable.Cell(10 + linesize, 3).Range.Text = "设计日期";
            secondTable.Cell(10 + linesize, 3).Range.Bold = 8;
            secondTable.Cell(10 + linesize, 3).Select();
            secondTable.Cell(10 + linesize, 3).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;


            secondTable.Cell(10 + linesize, 4).Range.Text = DateTime.Now.ToShortDateString();
            secondTable.Cell(10 + linesize, 4).Width = 150f;
            secondTable.Cell(10 + linesize, 4).Select();
            secondTable.Cell(10 + linesize, 4).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;


            secondTable.Cell(11 + linesize, 1).Width = 70f;
            secondTable.Cell(11 + linesize, 1).Range.Text = "问题标识";
            secondTable.Cell(11 + linesize, 1).Range.Bold = 8;
            secondTable.Cell(11 + linesize, 1).Select();
            secondTable.Cell(11 + linesize, 1).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;


            secondTable.Cell(11 + linesize, 2).Merge(secondTable.Cell(11 + linesize, 5));
            secondTable.Cell(11 + linesize, 2).Range.Text = " logo";
            secondTable.Cell(11 + linesize, 2).Width = 371f;
            secondTable.Cell(11 + linesize, 2).Select();
            secondTable.Cell(11 + linesize, 2).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(12 + linesize, 1).Range.Text = "执行结果";
            secondTable.Cell(12 + linesize, 1).Range.Bold = 8;
            secondTable.Cell(12 + linesize, 1).Width = 70f;
            secondTable.Cell(12 + linesize, 1).Select();
            secondTable.Cell(12 + linesize, 1).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(12 + linesize, 2).Width = 150f;
            secondTable.Cell(12 + linesize, 2).Range.Text = "未通过";
            secondTable.Cell(12 + linesize, 2).Select();
            secondTable.Cell(12 + linesize, 2).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(12 + linesize, 3).Range.Text = "测试人员";
            secondTable.Cell(12 + linesize, 3).Width = 71f;
            secondTable.Cell(12 + linesize, 3).Range.Bold = 8;
            secondTable.Cell(12 + linesize, 3).Select();
            secondTable.Cell(12 + linesize, 3).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(12 + linesize, 4).Merge(secondTable.Cell(12 + linesize, 5));
            secondTable.Cell(12 + linesize, 4).Width = 150f;
            secondTable.Cell(12 + linesize, 4).Range.Text = "logo";
            secondTable.Cell(12 + linesize, 4).Select();
            secondTable.Cell(12 + linesize, 4).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(13 + linesize, 1).Width = 70f;
            secondTable.Cell(13 + linesize, 1).Range.Text = "测试监督员";
            secondTable.Cell(13 + linesize, 1).Range.Bold = 8;
            secondTable.Cell(13 + linesize, 1).Select();
            secondTable.Cell(13 + linesize, 1).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(13 + linesize, 2).Width = 150f;
            secondTable.Cell(13 + linesize, 2).Range.Text = "logo";
            secondTable.Cell(13 + linesize, 2).Select();
            secondTable.Cell(13 + linesize, 2).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;


            secondTable.Cell(13 + linesize, 3).Width = 71f;
            secondTable.Cell(13 + linesize, 3).Range.Text = "测试执行时间";
            secondTable.Cell(13 + linesize, 3).Range.Bold = 8;
            secondTable.Cell(13 + linesize, 3).Select();
            secondTable.Cell(13 + linesize, 3).Range.Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            secondTable.Cell(13 + linesize, 4).Merge(secondTable.Cell(13 + linesize, 5));
            secondTable.Cell(13 + linesize, 4).Range.Text = "";
            secondTable.Cell(13 + linesize, 4).Width = 150f;

            wDoc.Paragraphs.Last.Range.Text = "文档创建时间: " + DateTime.Now.ToString(); // “落款”
        }
        #endregion
        #region 文档另存为其他文件名
        public static bool SaveAs(string fileName, Microsoft.Office.Interop.Word.Document wDoc)
        {
            Object FileName = fileName;
            Object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
            Object LockComments = false;
            Object Password = System.Type.Missing;
            Object AddToRecentFiles = false;
            Object WritePassword = System.Type.Missing;
            Object ReadOnlyRecommended = false;
            Object EmbedTrueTypeFonts = false;
            Object SaveNativePictureFormat = true;
            Object SaveFormsData = false;
            Object SaveAsAOCELetter = false;
            Object Encoding = System.Type.Missing;
            Object InsertLineBreaks = true;
            Object AllowSubstitutions = false;
            Object LineEnding = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
            Object AddBiDiMarks = true;
            try
            {
                wDoc.SaveAs(ref FileName, ref FileFormat, ref LockComments, ref Password, ref AddToRecentFiles, ref WritePassword
                        , ref ReadOnlyRecommended, ref EmbedTrueTypeFonts, ref SaveNativePictureFormat
                        , ref SaveFormsData, ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks, ref AllowSubstitutions
                        , ref LineEnding, ref AddBiDiMarks);
                return true;
            }
            catch (Exception ex)
            {
                string err = string.Format("另存文件出错,错误原因:{0}", ex.Message);
                throw new Exception(err, ex);
            }
        }
        #endregion
        #region 添加索引目录
        //public void AddList(ref Word.Application wApp)
        //{
        //    wApp.Selection.Start = 0;
        //    wApp.Selection.End = 0;//
        //    object beginLevel = 2;//
        //    object endLevel = 2;//
        //    object rightAlignPageNumber = true;// 指定页码右对其
        //    object miss = System.Reflection.Missing.Value;
        //    wApp.ActiveDocument.TablesOfContents.Add(wApp.Selection.Range, ref miss, ref rightAlignPageNumber, ref miss, ref miss, ref miss, ref miss, ref miss);//写入目录
        //}
        public void DocumentTablesOfContents()
        {
            wDoc.Tables[3].Range.InsertBefore("ABC");
            Object missing = System.Reflection.Missing.Value;
            object Style1 = Microsoft.Office.Interop.Word.WdBuiltinStyle.wdStyleHeading1;
            wDoc.Tables[3].set_Style(ref Style1);

            object Style2 = Microsoft.Office.Interop.Word.WdBuiltinStyle.wdStyleHeading2;
            wDoc.Tables[3].set_Style(ref Style2);

            object HeadingLevel = 1;
            wDoc.TablesOfContents.Add(this.Application.Selection.Range,
                ref missing, ref HeadingLevel, ref HeadingLevel,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing);
        }
        #endregion
        #region 关闭文档
        public void Close()
        {
            Close(wDoc, wApp);
            wDoc = null;
            wApp = null;
        }
        #endregion
        #region 关闭文档
        public static void Close(Microsoft.Office.Interop.Word.Document wDoc, Microsoft.Office.Interop.Word.Application WApp)
        {
            Object SaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
            Object OriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;
            Object RouteDocument = false;
            try
            {
                if (wDoc != null) wDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
                if (WApp != null) WApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 填充书签
        public void Replace(string bookmark, string value, string position)
        {
            try
            {
                object bkObj = bookmark;
                if (wApp.ActiveDocument.Bookmarks.Exists(bookmark) == true)
                {
                    wApp.ActiveDocument.Bookmarks.get_Item(ref bkObj).Select();
                    wApp.Selection.Range.Bold = 0;
                    if (position == "left")
                    {
                        wApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;// 水平居中
                    }
                    else if (position == "center")
                    {
                        wApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;// 水平居中
                    }
                }
                else return;
                wApp.Selection.TypeText(value);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region
        public bool findTable_3(string bookmark)
        {
            try
            {
                object bk = bookmark;
                if (getTable().Application.ActiveDocument.Bookmarks.Exists(bookmark) == true)
                {
                    getTable().Application.ActiveDocument.Bookmarks.get_Item(ref bk).Select();
                    return true;
                }
                else
                    return false;
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion
        #region 表格定位
        public bool FindTable(string bookmarkTable)
        {
            try
            {
                object bkObj = bookmarkTable;
                if (wApp.ActiveDocument.Bookmarks.Exists(bookmarkTable) == true)
                {
                    wApp.ActiveDocument.Bookmarks.get_Item(ref bkObj).Select();
                    object count = 14;
                    object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
                    Object Nothing = System.Reflection.Missing.Value;
                    wApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
                    wApp.Selection.TypeParagraph();//插入段落

                    return true;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region
        public void moveToEnd()
        {
            try
            {
                Object unit = Microsoft.Office.Interop.Word.WdUnits.wdRow;
                Object count = 7;
                wApp.Selection.Move(ref unit, ref count);
                wApp.Application.Selection.TypeParagraph();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 回车
        public void clickEnter()
        {
            wApp.Application.Selection.TypeParagraph();
        }
        #endregion
        #region 移动单元格
        public void MoveNextCell()
        {
            try
            {
                Object unit = Microsoft.Office.Interop.Word.WdUnits.wdCell;
                Object count = 1;
                wApp.Selection.Move(ref unit, ref count);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 为单元格赋值
        public void SetCellValue(string value)
        {
            try
            {
                wApp.Selection.TypeText(value);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region 换行
        public void MoveNextRow()
        {
            try
            {
                Object extend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
                Object unit = Microsoft.Office.Interop.Word.WdUnits.wdCell;
                Object count = 1;
                wApp.Selection.MoveRight(ref unit, ref count, ref extend);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                throw ex;
            }
        }
        #endregion
        #region
        public Table getTable()
        {
            //Table table = wDoc.Tables[3];
            Microsoft.Office.Interop.Word.Table table = wDoc.Tables[3];
            return table;
        }
        #endregion
        #region 添加行
        public void AddRows(int i)
        {
            object beforeRow = wDoc.Tables[3].Rows[10 + i];
            wDoc.Tables[3].Rows.Add(ref beforeRow);
            wDoc.Tables[3].Rows[10 + i].Range.Bold = 0;
        }
        #endregion
        #region 得到焦点
        public void GetPoint()
        {
            object BookMarkName = "表格";
            object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
            object missing = System.Reflection.Missing.Value;
            wDoc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
        }
        #endregion
        #region 删除多余的一行
        public void DeleteRow(int i)
        {
            wDoc.Tables[3].Rows[10 + i].Delete();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值