亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

C#控制定位Word光標移動到任意行或者最后一行,

系統 2652 0

轉: 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光標移動到任意行或者最后一行,取得光標位置等操作


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲精品第一页中文字幕 | 9999在线视频 | 美女又黄又免费的视频 | 小说区图片区综合久久亚洲 | 天天干天天操天天添 | 人人做人人爽久久久精品 | 婷婷综合五月中文字幕欧美 | 天码毛片一区二区三区入口 | 老司机午夜影院 | 四虎最新在线 | 99在线影院 | 免费一级a毛片夜夜看 | 国产成人综合亚洲亚洲欧美 | 五月天婷婷在线免费观看 | 香港a毛片免费全部播放 | 国产色在线 | 国产精品欧美亚洲韩国日本久久 | 99视频精品全部国产盗摄视频 | 在线播放免费一级毛片欧美 | 我想看一级毛片免费的 | 久久综合狠狠综合久久综合88 | 日韩视频一区二区三区 | 国产成人一区二区在线不卡 | 在线观看成人小视频 | 国产性精品 | 亚洲欧美色图片 | 伊人久久青草青青综合 | 亚久久 | 日本中文字幕高清 | 天堂精品高清1区2区3区 | 国产97色在线 | 免费 | 久操视频免费在线观看 | 亚洲综合网在线观看 | 欧美成人区 | 国产精品久久久久久久久ktv | 久久久久国产视频 | 国产精品久久久久一区二区 | 在线欧美一区 | 国产精品欧美日韩精品 | 青青久久久 | www一区|