Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512264
  • 博文数量: 60
  • 博客积分: 1445
  • 博客等级: 上尉
  • 技术积分: 507
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-14 19:15
文章分类

全部博文(60)

文章存档

2012年(1)

2011年(7)

2010年(52)

我的朋友

分类: C/C++

2010-07-12 14:07:45

表格的插入方法
1  表格的插入很简单,图表可参照
2  表格插入后如何获取表格请注意.用书签的Range对象的Tables集合

  1. #region 插入表格数据  
  2.   
  3.         private bool InsertTabletoBookmark(string objTable,ref Microsoft.Office.Interop.Word.Document wDoc, ref  Microsoft.Office.Interop.Word.Application WApp)  
  4.         {  
  5.             object oEndOfDoc = "\\endofdoc";  
  6.             object missing = System.Reflection.Missing.Value;  
  7.   
  8.             object objBookmark = objTable;  
  9.   
  10.             WApp.ActiveDocument.Bookmarks.get_Item(ref objBookmark).Select();  
  11.   
  12.             Microsoft.Office.Interop.Word.Table table = wDoc.Tables.Add(WApp.Selection.Range, 3, 4, ref missing, ref missing);  
  13.             table.Cell(1, 1).Range.Text = "表:" + WApp.ActiveDocument.Bookmarks.get_Item(ref objBookmark).Range.Tables[1].Rows.Count;  
  14.   
  15.             return true;  
  16.         }  

 

  1. //合并单元格  
  2.    table.Cell(2, 2).Merge(table.Cell(2, 3));  
  3.   
  4.  //单元格分离  
  5.     object Rownum = 2;  
  6.     object Columnnum = 2;  
  7.     table.Cell(2, 2).Split(ref Rownum, ref  Columnnum);  
  8.   
  9. //单元格对齐方式  
  10.      WApp.Selection.Cells.VerticalAlignment =Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;  
  11.   
  12. //插入表行  
  13.      table.Rows.Add(ref missing);  
  14.   
  15. //分页  object ib = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;  
  16.     WApp.Selection.InsertBreak(ref ib);  
  17.   
  18. //换行  
  19.      WApp.Selection.TypeParagraph();  

二、word文档设置

  1. WApp.ActiveDocument.PageSetup.LineNumbering.Active =0;//行编号  
  2.             WApp.ActiveDocument.PageSetup.Orientation =Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;//页面方向  
  3.             WApp.ActiveDocument.PageSetup.TopMargin =WApp.CentimetersToPoints(float.Parse("2.54"));//上页边距  
  4.             WApp.ActiveDocument.PageSetup.BottomMargin = WApp.CentimetersToPoints(float.Parse("2.54"));//下页边距  
  5.             WApp.ActiveDocument.PageSetup.LeftMargin = WApp.CentimetersToPoints(float.Parse("3.17"));//左页边距  
  6.             WApp.ActiveDocument.PageSetup.RightMargin = WApp.CentimetersToPoints(float.Parse("3.17"));//右页边距  
  7.             WApp.ActiveDocument.PageSetup.Gutter = WApp.CentimetersToPoints(float.Parse("0"));//装订线位置  
  8.             WApp.ActiveDocument.PageSetup.HeaderDistance = WApp.CentimetersToPoints(float.Parse("1.5"));//页眉  
  9.             WApp.ActiveDocument.PageSetup.FooterDistance = WApp.CentimetersToPoints(float.Parse("1.75"));//页脚  
  10.             WApp.ActiveDocument.PageSetup.PageWidth = WApp.CentimetersToPoints(float.Parse("21"));//纸张宽度  
  11.             WApp.ActiveDocument.PageSetup.PageHeight = WApp.CentimetersToPoints(float.Parse("29.7"));//纸张高度  
  12.             WApp.ActiveDocument.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;//纸张来源  
  13.             WApp.ActiveDocument.PageSetup.OtherPagesTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;//纸张来源  
  14.             WApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.Word.WdSectionStart.wdSectionNewPage;//节的起始位置:新建页  
  15.             WApp.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = 0;//页眉页脚-奇偶页不同  
  16.             WApp.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0;//页眉页脚-首页不同  
  17.             WApp.ActiveDocument.PageSetup.VerticalAlignment = Microsoft.Office.Interop.Word.WdVerticalAlignment.wdAlignVerticalTop;//页面垂直对齐方式  
  18.             WApp.ActiveDocument.PageSetup.SuppressEndnotes =0;//不隐藏尾注  
  19.             WApp.ActiveDocument.PageSetup.MirrorMargins = 0;//不设置首页的内外边距  
  20.             WApp.ActiveDocument.PageSetup.TwoPagesOnOne = false;//不双面打印  
  21.             WApp.ActiveDocument.PageSetup.BookFoldPrinting =false;//不设置手动双面正面打印  
  22.             WApp.ActiveDocument.PageSetup.BookFoldRevPrinting =false;//不设置手动双面背面打印  
  23.             WApp.ActiveDocument.PageSetup.BookFoldPrintingSheets = 1;//打印默认份数  
  24.             WApp.ActiveDocument.PageSetup.GutterPos = Microsoft.Office.Interop.Word.WdGutterStyle.wdGutterPosLeft;//装订线位于左侧  
  25.             WApp.ActiveDocument.PageSetup.LinesPage = 40;//默认页行数量  
  26.             WApp.ActiveDocument.PageSetup.LayoutMode = Microsoft.Office.Interop.Word.WdLayoutMode.wdLayoutModeLineGrid;//版式模式为“只指定行网格”  

 

阅读(2387) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~