逐页读取MS WORD文件

本文关键字:WORD 文件 MS 读取 | 更新日期: 2023-09-27 18:20:35

我正在创建一个C#WPF应用程序,以便逐页复制MS Word文件并将其粘贴到MS Excel文件中。

我找到了以下链接来阅读整个MS Word文件。

http://www.mindstick.com/Articles/5cd1b721-9b94-4ea0-bd6e-2bb157401069/

但我想一页一页地阅读,请帮助我任何人。

谢谢,

逐页读取MS WORD文件

像文章中那样打开文档后,应该可以使用类似的方法;它来自内存/文档,因此相似性可能会有所不同:)

object missing = System.Reflection.Missing.Value; 
var document = application.ActiveDocument;
Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages; 
int num =  aDoc.ComputeStatistics(stat, ref missing);    // Get number of pages
for(int i=0; i<num; i++)
{
    document.ActiveWindow.Selection           // Go to page "i"
            .GoTo(WdGoToItem.wdGoToPage, missing, missing, i.ToString());
    document.ActiveWindow.Selection           // Select whole page
            .GoTo(WdGoToItem.wdGoToBookmark, missing, missing, "''page");
    document.ActiveWindow.Selection.Copy();   // Copy to clipboard
    // Do whatever you want with the selection
}