表格的插入方法
1 表格的插入很简单,图表可参照
2 表格插入后如何获取表格请注意.用书签的Range对象的Tables集合
- #region 插入表格数据
-
- private bool InsertTabletoBookmark(string objTable,ref Microsoft.Office.Interop.Word.Document wDoc, ref Microsoft.Office.Interop.Word.Application WApp)
- {
- object oEndOfDoc = "\\endofdoc";
- object missing = System.Reflection.Missing.Value;
-
- object objBookmark = objTable;
-
- WApp.ActiveDocument.Bookmarks.get_Item(ref objBookmark).Select();
-
- Microsoft.Office.Interop.Word.Table table = wDoc.Tables.Add(WApp.Selection.Range, 3, 4, ref missing, ref missing);
- table.Cell(1, 1).Range.Text = "表:" + WApp.ActiveDocument.Bookmarks.get_Item(ref objBookmark).Range.Tables[1].Rows.Count;
-
- return true;
- }
-
- table.Cell(2, 2).Merge(table.Cell(2, 3));
-
-
- object Rownum = 2;
- object Columnnum = 2;
- table.Cell(2, 2).Split(ref Rownum, ref Columnnum);
-
-
- WApp.Selection.Cells.VerticalAlignment =Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
-
-
- table.Rows.Add(ref missing);
-
-
- WApp.Selection.InsertBreak(ref ib);
-
-
- WApp.Selection.TypeParagraph();
二、word文档设置
- WApp.ActiveDocument.PageSetup.LineNumbering.Active =0;
- WApp.ActiveDocument.PageSetup.Orientation =Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;
- WApp.ActiveDocument.PageSetup.TopMargin =WApp.CentimetersToPoints(float.Parse("2.54"));
- WApp.ActiveDocument.PageSetup.BottomMargin = WApp.CentimetersToPoints(float.Parse("2.54"));
- WApp.ActiveDocument.PageSetup.LeftMargin = WApp.CentimetersToPoints(float.Parse("3.17"));
- WApp.ActiveDocument.PageSetup.RightMargin = WApp.CentimetersToPoints(float.Parse("3.17"));
- WApp.ActiveDocument.PageSetup.Gutter = WApp.CentimetersToPoints(float.Parse("0"));
- WApp.ActiveDocument.PageSetup.HeaderDistance = WApp.CentimetersToPoints(float.Parse("1.5"));
- WApp.ActiveDocument.PageSetup.FooterDistance = WApp.CentimetersToPoints(float.Parse("1.75"));
- WApp.ActiveDocument.PageSetup.PageWidth = WApp.CentimetersToPoints(float.Parse("21"));
- WApp.ActiveDocument.PageSetup.PageHeight = WApp.CentimetersToPoints(float.Parse("29.7"));
- WApp.ActiveDocument.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;
- WApp.ActiveDocument.PageSetup.OtherPagesTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;
- WApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.Word.WdSectionStart.wdSectionNewPage;
- WApp.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = 0;
- WApp.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0;
- WApp.ActiveDocument.PageSetup.VerticalAlignment = Microsoft.Office.Interop.Word.WdVerticalAlignment.wdAlignVerticalTop;
- WApp.ActiveDocument.PageSetup.SuppressEndnotes =0;
- WApp.ActiveDocument.PageSetup.MirrorMargins = 0;
- WApp.ActiveDocument.PageSetup.TwoPagesOnOne = false;
- WApp.ActiveDocument.PageSetup.BookFoldPrinting =false;
- WApp.ActiveDocument.PageSetup.BookFoldRevPrinting =false;
- WApp.ActiveDocument.PageSetup.BookFoldPrintingSheets = 1;
- WApp.ActiveDocument.PageSetup.GutterPos = Microsoft.Office.Interop.Word.WdGutterStyle.wdGutterPosLeft;
- WApp.ActiveDocument.PageSetup.LinesPage = 40;
- WApp.ActiveDocument.PageSetup.LayoutMode = Microsoft.Office.Interop.Word.WdLayoutMode.wdLayoutModeLineGrid;
阅读(2428) | 评论(0) | 转发(0) |