您好,欢迎访问三七文档
再谈word2003编程近期因为项目需要,写了许多word2003编程的东东.有时候遇到难题想查sdk说明,很难找到中文解释,对于e文不好的我来说,简直是天书.想必很多人多有感慨.下面列出内容是一些常用的内容说明,希望对大家有帮助.那就开始吧注意,下文的WAPP是我定义的word文档工程变量的//合并单元格table.Cell(2,2).Merge(table.Cell(2,3));//单元格分离objectRownum=2;objectColumnnum=2;table.Cell(2,2).Split(refRownum,refColumnnum);//单元格对齐方式WApp.Selection.Cells.VerticalAlignment=Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//插入表行table.Rows.Add(refmissing);//分页objectib=Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;WApp.Selection.InsertBreak(refib);//换行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;//版式模式为“只指定行网格”三、光标移动//移动光标//光标下移3行上移3行objectunit=Microsoft.Office.Interop.Word.WdUnits.wdLine;objectcount=3;WApp.Selection.MoveEnd(refunit,refcount);WApp.Selection.MoveUp(refunit,refcount,refmissing);//Microsoft.Office.Interop.Word.WdUnits说明//wdCellAcell.//wdCharacterAcharacter.//wdCharacterFormattingCharacterformatting.//wdColumnAcolumn.//wdItemTheselecteditem.//wdLineAline.//行//wdParagraphAparagraph.//wdParagraphFormattingParagraphformatting.//wdRowArow.//wdScreenThescreendimensions.//wdSectionAsection.//wdSentenceAsentence.//wdStoryAstory.//wdTableAtable.//wdWindowAwindow.//wdWordAword.//录制的vb宏//,移动光标至当前行首//Selection.HomeKeyunit:=wdLine//'移动光标至当前行尾//Selection.EndKeyunit:=wdLine//'选择从光标至当前行首的内容//Selection.HomeKeyunit:=wdLine,Extend:=wdExtend//'选择从光标至当前行尾的内容//Selection.EndKeyunit:=wdLine,Extend:=wdExtend//'选择当前行//Selection.HomeKeyunit:=wdLine//Selection.EndKeyunit:=wdLine,Extend:=wdExtend//'移动光标至文档开始//Selection.HomeKeyunit:=wdStory//'移动光标至文档结尾//Selection.EndKeyunit:=wdStory//'选择从光标至文档开始的内容//Selection.HomeKeyunit:=wdStory,Extend:=wdExtend//'选择从光标至文档结尾的内容//Selection.EndKeyunit:=wdStory,Extend:=wdExtend//'选择文档全部内容(从WholeStory可猜出Story应是当前文档的意思)//Selection.WholeStory//'移动光标至当前段落的开始//Selection.MoveUpunit:=wdParagraph//'移动光标至当前段落的结尾//Selection.MoveDownunit:=wdParagraph//'选择从光标至当前段落开始的内容//Selection.MoveUpunit:=wdParagraph,Extend:=wdExtend//'选择从光标至当前段落结尾的内容//Selection.MoveDownunit:=wdParagraph,Extend:=wdExtend//'选择光标所在段落的内容//Selection.MoveUpunit:=wdParagraph//Selection.MoveDownunit:=wdParagraph,Extend:=wdExtend//'显示选择区的开始与结束的位置,注意:文档第1个字符的位置是0//MsgBox(第&Selection.Start&个字符至第&Selection.End&个字符)//'删除当前行//Selection.HomeKeyunit:=wdLine//Selection.EndKeyunit:=wdLine,Extend:=wdExtend//Selection.Delete//'删除当前段落//Selection.MoveUpunit:=wdParagraph//Selection.MoveDownunit:=wdParagraph,Extend:=wdExtend//Selection.Delete//表格的光标移动//光标到当前光标所在表格的地单元格WApp.Selection.Tables[1].Cell(1,1).Select();//unit对象定义objectunith=Microsoft.Office.Interop.Word.WdUnits.wdRow;//表格行方式objectextend=Microsoft.Office.Interop.Word.WdMovementType.wdExtend;///extend对光标移动区域进行扩展选择objectunitu=Microsoft.Office.Interop.Word.WdUnits.wdLine;//文档行方式,可以看成表格一行.不过和wdRow有区别objectunitp=Microsoft.Office.Int
本文标题:word编程
链接地址:https://www.777doc.com/doc-6014671 .html