【转】C#操作word定位光标
十一、上下左右移动光标位
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定位光标的更多相关文章
- C#操作Word的辅助类(word2003) 修改完善版
转自:http://blog.csdn.net/jiutao_tang/article/details/6567608 该类在他人编写的几个类基础上扩展完善而来,主要功能有: (1)插入文本 (2)插 ...
- 操作Word的辅助类(word2003)
该类在他人编写的几个类基础上扩展完善而来,主要功能有: (1)插入文本 (2)插入图片 (3)插入表格 (4)载入模版 (5)编辑模版,利用标签等 (6)插入页眉页脚 /*************** ...
- [转载]java操作word(一)
一. 需求背景 在做项目的过程中,经常会遇到要把数据库数据导出到Word文件中的需求,因为很多情况下,我们需要将数据导出到WORD中进行打印.此需求可以通过用程序填充数据到word模板中来实现.所谓模 ...
- [原创]java操作word(一)
一. 需求背景 在做项目的过程中,经常会遇到要把数据库数据导出到Word文件中的需求,因为很多情况下,我们需要将数据导出到WORD中进行打印.此需求可以通过用程序填充数据到word模板中来实现.所谓模 ...
- VC操作WORD文档总结
一.写在开头 最近研究word文档的解析技术,我本身是VC的忠实用户,看到C#里面操作WORD这么舒服,同时也看到单位有一些需求,就想尝试一下,结果没想到里面的技术点真不少,同时网络上的共享资料很多, ...
- [转]C#操作Word的超详细总结
本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...
- C#操作Word的超详细总结
本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...
- C# 操作Word书签(二)——插入图片、表格到书签;读取、替换书签
概要 书签的设置可以帮助我们快速的定位某段文字,使用起来很方便,也很节省时间.在前一篇文章“C# 如何添加/删除Word书签”中介绍了插入.删除书签的方法,本篇文章将对C# 操作Word书签的功能做进 ...
- c# 操作Word总结(车)
在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想到网页的信息创建到一个word文本中,在显示的时,可以在线打开 ...
随机推荐
- CSS--百度百科
层叠样式表是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言. CSS目前最新版本为CSS3,是能够真正做到网页表现与内容分离的一种样式设 ...
- 简单模拟Spring的注入
主要就是读XML技术和反射技术. 在xml中读出相关配置信息,然后利用反射将其实例化为对象,并调用其构造方法,在实例化的过程中将属性注入实例. 实例化和属性注入这些操作都交给了框架,不再需要自己的去n ...
- iOS CoreImage之滤镜简单使用
代码地址如下:http://www.demodashi.com/demo/11605.html 老骥伏枥,志在千里 前记 最近一直在研究图像处理方面,既上一篇iOS Quart2D绘图之UIImage ...
- C语言-一个fopen函数中未使用二进制模式(b)引发的血案
转自:http://blog.csdn.net/hinyunsin/article/details/6401854 最近写了一个网络文件传输模块,为了让这个模块具有更好的移植性,我尽量使用C标准IO ...
- AngularJs学习笔记(4)——自定义指令
对指令的第一印象:它是一个自定义标签! 先来看一个简单的指令: <!doctype html> <html ng-app="myApp"> <head ...
- 一个文件查看你选择 Run as Android applications 都干了啥
<?xml version="1.0" encoding="UTF-8"?> <project name="PushFastDemo ...
- JanusGraph的schema及数据建模
每个JanusGraph都有一个schema,该schema由edge labels, property keys和vertex labels组成.JanusGraph的schema可以显式或隐式创建 ...
- 使用swap 清空vector
//最简单的使用swap,清除元素并回收内存 vector <int>().swap(vecInt); //清除容器并最小化它的容量, // vecInt.swap(vector<i ...
- Mac 上的传奇效率神器 Alfred 3
下载地址:https://www.alfredapp.com/ 第三方教程:https://www.jianshu.com/p/e9f3352c785f 一.内置快捷键介绍 1.默认快捷呼出热键是: ...
- unity, 显示像素图,以及iOS下像素图变模糊解决办法
在PS里画了个16x16像素的图: 在webplayer下Filter Mode选为Point,显示效果为: 在ios下显示效果为: 是由于iOS下会将图片压缩为pvr所致,想得到清晰的效果,需将Fo ...