在 c# 中使用 microsoft.office.tools.word 我们如何将单个页面保存为 rtf 文件

In c# using microsoft.office.tools.word how do we save a single page as rtf file

在 c# 中使用 microsoft.office.tools.word 我们如何将文档的单页保存为 rtf 文件。

假设只有第 5 页必须保存为 rtf。

我无法看到 Document.Pages[5] 之类的内容来访问某个页面。

这会将第 2 页保存为 "page2.pdf"

    Document d = wordApp.ActiveDocument;

    object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
    object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst;
    object count = 2;

    Range r =wordApp.Selection.GoTo(ref what, ref which, ref count);
    count = (int)count+1;
    Range r2 = wordApp.Selection.GoTo(ref what, ref which, ref count);
    r.End = r2.End;
    r.Select();

    r.ExportAsFixedFormat(@"d:\temp\page2.pdf", WdExportFormat.wdExportFormatPDF);

它应该给出关于如何 select 另一个页面并将其保存为 RTF 格式的想法...

页面是另一个故事:

Pages pages = wordApp.ActiveDocument.ActiveWindow.ActivePane.Pages;
MessageBox.Show("This document has "+pages.Count+" pages");

但是我对此的了解有限,无法在这两行之后停止...

编辑:我找不到将 selected 文本写入 RTF 的解决方案,但是,您始终可以将其复制到新文档,然后另存为....

随着select离子:

        r.Copy();
        Document dtmp = wordApp.Documents.Add();
        dtmp.Activate();
        Selection sel = wordApp.ActiveWindow.ActivePane.Selection;
        sel.Paste();
        dtmp.SaveAs2(@"d:\temp\page2.rtf", WdSaveFormat.wdFormatRTF);
        dtmp.Close();