C#获取Word文档页数,并跳转到指定的页面获取页面信息
2010-04-29 12:35
633 查看
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;
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;
相关文章推荐
- C#获取Word文档页数,并跳转到指定的页面获取页面信息
- C#获取Word文档页数,并跳转到指定的页面获取内容,且插入分页符
- C# 获取PDF文档的字体信息及指定文字的坐标,宽度和高度
- 微信公众号获取用户信息已经菜单栏跳转指定页面
- C++和python如何获取百度搜索结果页面下信息对应的真实链接(百度搜索爬虫,可指定页数)
- GridView获取当前行的信息以及在一列上添加页面跳转
- 示例 - 10行代码在C#中获取页面元素布局信息
- 10行代码在C#中获取页面元素布局信息
- 转:C# 获取指定目录下所有文件信息、移动目录、拷贝目录
- C#获取word文件信息相关资料
- C# 获取word批注信息
- 批量获取Word文档的文件名信息
- C#在Word文档指定位置处理表格
- C#获取指定PDF文件页数的方法
- 前后端分离,html页面中怎么获取当前登录用户信息,并写入html页面的指定位置?
- 一个非常实用的C#弹出对话框类(包括弹出对话框,跳转到指定页面,关闭窗口)
- C# 设置word文档页面大小
- 在C#获取word文档的字数,并输出到excel
- 黄聪:C# web word文档操作,任意指定位置插入图片,表格简单操作
- C#实现上传WORD文档并另存为WEB页面