打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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;

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# VS2012操作word文档 (一).创建文档
C# ASP.Net VS2010 word 2010生成水印
[转]C#操作Word的超详细总结
html在线显示word怎么在html中显示word
asp.net操作Word
(转)C# Office操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服