C#获取Word文档页数,并跳转到指定的页面获取页面信息

using MSWord = Microsoft.Office.Interop.Word;

private MSWord.Application wordApp;  //Word应用程序变量
private MSWord.Document wordDoc;     //Word文档变量
private Object Nothing = Missing.Value;
  //初始化
wordApp = new MSWord.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
// 打开Word
object FileName = strPath;
object readOnly = false;
object isVisible = true;
wordDoc = wordApp.Documents.Open(ref FileName, ref Nothing, ref readOnly,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref isVisible, ref Nothing,
ref Nothing, ref Nothing, ref Nothing);

// 计算Word文档页数
MSWord.WdStatistic stat = MSWord.WdStatistic.wdStatisticPages;
int num = wordDoc.ComputeStatistics(stat, ref  Nothing);

// 跳转到指定书签
object BookMarkName = "BookMark1";
object what = MSWord.WdGoToItem.wdGoToBookmark;
wordDoc.ActiveWindow.Selection.GoTo(ref what, ref Nothing, ref Nothing, ref BookMarkName);
MessageBox.Show( wordDoc.ActiveWindow.Selection.Paragraphs[1].Range.Text.ToString());


//  跳转到指定页

object What = MSWord.WdGoToItem.wdGoToPage;
object Which = MSWord.WdGoToDirection.wdGoToNext;
object Name = "1"; // 页数
wordDoc.ActiveWindow.Selection.GoTo(ref What, ref Which, ref Nothing, ref Name); // 第二个参数可以用Nothing
wordDoc.ActiveWindow.Selection.Paragraphs[1].Range.Text.ToString();

//  以下是跳转到某个页面之后的操作

// 通过PageSetup可以获取某个页面的信息

// 获取页面的分栏
wordDoc.ActiveWindow.Selection.PageSetup.TextColumn;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值