http://blog.csdn.net/jglie/article/details/7394256

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

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();

}

C#控制定位Word光标移动到任意行或者最后一行,取得光标位置等操作的更多相关文章

  1. K1 K2作为中断源控制红色LED灯,实现任意键按一下LED灯亮或者灭

    #include "stm32f10x.h" // 相当于51单片机中的 #include <reg51.h> #include "stm32f10x_gpi ...

  2. [No000018E]Vim快速跳转任意行、任意列以及高亮显示当前行、当前列方法-Vim使用技巧(3)

    vim提供了丰富的快速跳转任意行.任意列的方法,方便高效地移动光标,定位文件位置. 一.Vim行跳转 使用vim查看文件时,使用以下命令可以快速跳转文件首.尾行,方便对整个文件有个全局把握. 1.1 ...

  3. 解决“Word无法访问您试图使用的功能所在的网络位置”问题

    解决“Word无法访问您试图使用的功能所在的网络位置”问题 打开Word时出现现现在的对话框,按取消,又可以打开word文档 按取消时,仍然可以打开word文档.为了解决这个问题,我借助网络,知道这是 ...

  4. DataGridView 访问任意行不崩溃

    int index= this.dataGridView1.rows.Add(); 先执行这行代码,然后访问任意行,不崩溃, 赋值不存在的行,只是不显示,或者无值. 什么原理呢? 一些其他 priva ...

  5. centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课

    centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...

  6. Vim-复制选中内容至系统剪贴板,光标移动到指定行的行首和行尾

    1.全选并复制到系统剪贴板 ggVG或ggvG 然后 "+y gg 让光标移到首行,在vim才有效,vi中无效 V 是进入Visual(可视)模式 G 光标移到最后一行 "+y 复 ...

  7. Java 如何给Word文档添加多行文字水印

    前言 我在以往的文章中曾介绍过如何给Word文档添加文本水印和图片水印,及怎样删除文档中的水印.关于文本水印,之前那篇教程里主要指的是单行字体的水印,而在操作Word文档时,有时也会碰到需要添加多行文 ...

  8. Android百度地图开发03之地图控制 + 定位

    前两篇关于百度地图的blog写的是,一些基本图层的展示 和 覆盖物的添加+地理编码和反地理编码. 接下来,这篇blog主要说一些关于地图控制方面的内容和定位功能. 百度地图提供的关于地图的操作主要有: ...

  9. js实现类似微信网页版在可编辑的div中粘贴内容时过滤剪贴板的内容,光标始终在粘贴内容后面,以及将光标定位到最后的方法

    过滤剪贴板内容以及定位可编辑div光标的方法: <!DOCTYPE html><html lang="en"><head>  <meta ...

随机推荐

  1. 改写java TreeMap制造方便查询的ip内存库

    http://www.54chen.com/java-ee/chang-java-treemap-store-ip.html

  2. POJ 1062 昂贵的聘礼(Dijkstra)

    题意 : 真真是做POJ第一次遇到中文题,好吧,虽然语言通了,我一开始也没看懂样例什么意思,题意的话就是说这个探险家想娶酋长的女儿,但是没有钱,酋长说他可以用祭司的水晶球或者皮袄来换取少花一部分钱,同 ...

  3. 360 chrome不能登录Google账户

    用过Google chrome,枫树,360 chrome国际版,今天还是回到Google chrome了. 因为除了Chrome自己,其他的都不能正常登录Google账户(偶尔偶尔一次可以,直到今天 ...

  4. js中的call、apply

    function qingyezhuA(a0, a1) { this.qingyezhuX = a0 + a1; } var qingyezhuObj1 = { }; qingyezhuA.apply ...

  5. java四种数组排序

    数组的四种排序 1.快速排序法Arrays.sort(); 用法1.sort(byte[] a)      对指定的 byte 型数组按数字升序进行排序. sort(byte[] a, int fro ...

  6. 如何删除ArcSde Service服务

    1)打开“控制面板”,“服务”,找到“ArcSde Service(somename)”,这里somename就是你的ArcSde服务的真实的名字,记住这个名字(为叙述方便,以下用somename表示 ...

  7. 5、处理模型数据ModelAndView、Map、Model以及@SessionAttributes注解

    Spring MVC提供了以下几种途径输出模型数据 —— ModelAndView: 处理方法返回值类型为ModelAndView时,方法体即可通过该对象添加模型数据.数据会添加到request域中. ...

  8. C# 调用命令行,参数有空格

    在程序中调用cmd命令打开一个文件,而文件路径带有空格,如果直接把路径传给cmd,那么cmd就会把路径空格前面的部分当做是一个参数,空格后当做另一个参数,命令行执行把后边截掉了,导致程序出错,会弹出了 ...

  9. UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树

    Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/ ...

  10. PHP JSON 操作总结

    由于JSON可以在很多种程序语言中使用,所以我们可以用来做小型数据中转,如:PHP输出JSON字符串供JavaScript使用等.在PHP中可以使用 json_decode() 由一串规范的字符串解析 ...