查找当前word文档(word, c#)的选定/聚焦页面

本文关键字:word 聚焦 文档 查找 | 更新日期: 2023-09-27 18:16:21

我正在寻找一种方法来确定当前焦点所在的页面(如int)。在方法

document.ExportAsFixedFormat(outputpath, 
                             Word.WdExportFormat.wdExportFormatPDF, 
                             false, 
                             Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen,
                           **Word.WdExportRange.wdExportCurrentPage**, 
                             0, 0, Word.WdExportItem.wdExportDocumentContent, 
                             true, false, 
                             Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, 
                             false, false, false,ref missing);

是它的参数。但我想保存为Worddocument。在方法

document.SaveAs2(outputpath, 
                 missing, missing, missing, 
                 missing, missing, missing, 
                 missing, missing, missing, 
                 missing, missing, missing, 
                 missing, missing, missing, missing);

不是这样的形参。

有人知道如何保存当前焦点的文档吗?

查找当前word文档(word, c#)的选定/聚焦页面

如果你的"focus"指的是"插入点所在的页面",那么基于以下VBA示例的c#可能就足够了:

activedocument.Bookmarks("'page").range.exportfragment "c:'a'frag1.docx",wdSaveFormat.wdFormatXMLDocument

(编辑:OP提供了以下c#:

worddocument.Bookmarks[@"'Page"].Range.ExportFragment(exportPath, Word.WdSaveFormat.wdFormatDocumentDefault);

)