十一、上下左右移动光标位

private void moveLeft()

{

object moveUnit = Microsoft.Office.Interop.Word.WdUnits.wdWord;

object moveCount = 1;

object moveExtend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;

thisDocument.Application.Selection.MoveLeft(ref moveUnit, ref moveCount, ref MissingValue);

}

private void moveRight()

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

object dummy=System.Reflection.Missing.Value;

object count=1;

object Unit=Word.WdUnits.wdCharacter;

selection.MoveRight(ref Unit,ref count,ref dummy);

}

十二、取得当前光标位

public void GetCursor()

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

object a=selection.get_Information(Word.WdInformation.wdFirstCharacterLineNumber);

object b=selection.get_Information(Word.WdInformation.wdFirstCharacterColumnNumber);

object c=selection.get_Information(Word.WdInformation.wdActiveEndAdjustedPageNumber);

MessageBox.Show(a.ToString()+”行,”+b.ToString()+”列,”+c.ToString()+”页”);

}

十三、定位到指定行或相对行

/// <summary>

/// 定位到指定行

/// </summary>

/// <param name=”lineNum”>行号</param>

private void gotoAbsolutLine(int lineNum)

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

object dummy=System.Reflection.Missing.Value;

object what=Word.WdGoToItem.wdGoToLine;

object which=Word.WdGoToDirection.wdGoToFirst;

object count=lineNum;

selection.GoTo(ref what,ref which,ref count,ref dummy);

}

/// <summary>

/// 定位到相对行,例如+4

/// </summary>

/// <param name=”lineNum”>行数</param>

private void gotoOppositeLine(int lineNum)

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

object dummy=System.Reflection.Missing.Value;

object what=Word.WdGoToItem.wdGoToLine;

object which;

if(lineNum<0)

which=Word.WdGoToDirection.wdGoToPrevious;

else

which=Word.WdGoToDirection.wdGoToNext;

object count=Math.Abs(lineNum);

selection.GoTo(ref what,ref which,ref count,ref dummy);

}

十四、定位到文档最后一行

private void gotoLastLine(Document thisDocument)

{

object dummy = System.Reflection.Missing.Value;

object what = WdGoToItem.wdGoToLine;

object which = WdGoToDirection.wdGoToLast;

object count = 99999999;

thisDocument.Application.Selection.GoTo(ref what, ref which, ref count, ref dummy);

}

十五、定位到第一个字符

private void gotoFirstCharacter()

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

int oldLine=0;

gotoAbsolutLine(1);

object a=selection.get_Information(Word.WdInformation.wdFirstCharacterLineNumber);//得到当前行号

while(oldLine!=int.Parse(a.ToString()))//一直按右键,直到光标不再往下了为止

{

oldLine++;

moveRight();

a=selection.get_Information(Word.WdInformation.wdFirstCharacterLineNumber);

}

gotoAbsolutLine(int.Parse(a.ToString()));

}

十六、定位到最后一个字符

public void gotoLastCharacter()

{

if(selection==null||selection!=document.Application.Selection)

selection=document.Application.Selection;

gotoLastLine();

object dummy=System.Reflection.Missing.Value;

object count=99999999;

object Unit=Word.WdUnits.wdCharacter;

selection.MoveRight(ref Unit,ref count,ref dummy);

}

二十一、 取得行、列、页信息

public string WordGetRCP()

{

selection=document.Application.Selection;//wd.Selection;

object a=selection.get_Information(Word.WdInformation.wdFirstCharacterLineNumber);

object b=selection.get_Information(Word.WdInformation.wdFirstCharacterColumnNumber);

object c=selection.get_Information(Word.WdInformation.wdActiveEndAdjustedPageNumber);

return a.ToString()+”,”+b.ToString()+”,”+c.ToString();

}

最新文章

  1. 【算法】C语言实现数组的动态分配
  2. Linux LVM逻辑卷配置过程详解
  3. Mybatis-mapper-xml-基础
  4. 泛函编程(23)-泛函数据类型-Monad
  5. Opencv step by step - 图像变换
  6. jQuery 屏蔽鼠标快速经过
  7. 数据结构学习笔记05图 (邻接矩阵 邻接表--&gt;BFS DFS、最短路径)
  8. [解决方案] 当 IDENTITY_INSERT 设置为 OFF 时
  9. 在imge控件中直接显示图片(图片是byte[]格式)
  10. UIPickerView(选择控制器) 自学之初体验
  11. IT大数据服务管理高级课程(IT服务,大数据,云计算,智能城市)
  12. java内部类继承--构造函数传参
  13. c#之向ftp服务器传文件
  14. C#中访问私有成员
  15. 在CYGWIN下编译和运行软件Bundler ,以及PMVS,CMVS的编译与使用
  16. JWT
  17. 【Java】 剑指offer(30) 包含min函数的栈
  18. JAVA之多线程概念及其几种实现方法优劣分析
  19. linux批量改名
  20. 记录一下SpringMVC扫描注解包的配置

热门文章

  1. Python——实现代理服务功能
  2. 用箭头函数精简Vue 模块
  3. Python中函数参数传递问题【转】
  4. unity, PlayerPrefs.GetInt(key,defaultValue)
  5. doT js模板入门 2
  6. JsCal( JS Calendar)
  7. Creating Context Menu / 创建上下文菜单项 / VC++, Windows, DLL, ATL, COM
  8. Mat::operator =
  9. java编译器特性
  10. Painting Fence