省略numpages aspose .net上的最后一页

发布于 2025-01-22 01:09:48 字数 416 浏览 1 评论 0原文

我正在寻找Aspose .NET中的解决方案以减少数字。原因是我不想计算文档的最后一页。这是我到目前为止尝试的:

builder.Write("Page ");
builder.InsertField("Page", "");
builder.Write(" of ");
builder.InsertField("NUMPAGES", $"{(doc.PageCount - 1)}");

// Another try in separate build
builder.InsertField("NUMPAGES - 1", "");

// Another try in separate build
builder.InsertField("NUMPAGES", "NUMPAGES - 1");

文档要么没有显示任何内容,要么也计算最后一页。

I'm looking for a solution in ASPOSE .Net to decrement the NUMPAGES. Reason is that I don't want to count the last page of the document. Here is what I tried so far:

builder.Write("Page ");
builder.InsertField("Page", "");
builder.Write(" of ");
builder.InsertField("NUMPAGES", 
quot;{(doc.PageCount - 1)}");

// Another try in separate build
builder.InsertField("NUMPAGES - 1", "");

// Another try in separate build
builder.InsertField("NUMPAGES", "NUMPAGES - 1");

Document either doesn't display anything or count the last page as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情洁癖 2025-01-29 01:09:48

您应该使用公式和嵌套数字字段来获取所需的输出。您的MS Word文档中的字段代码应该看起来像:
{= {numpages} -1}。要使用aspose.words插入此类字段。您可以使用这样的代码:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert formula field
Field formula = builder.InsertField("=", "");
// Move document builder inside field code of the inserted field
// And put NUMPAGES field in it.
builder.MoveTo(formula.Separator);
builder.InsertField("NUMPAGES");
builder.Write("-1");

doc.UpdateFields();
doc.Save(@"C:\Temp\out.docx");

请参阅Aspose.words文档以学习如何使用字段

You should use formula and nested NUMPAGES field to get the desired output. Field code in your MS Word document should look like this:
{={NUMPAGES}-1}. To insert such field using Aspose.Words you can use code like this:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert formula field
Field formula = builder.InsertField("=", "");
// Move document builder inside field code of the inserted field
// And put NUMPAGES field in it.
builder.MoveTo(formula.Separator);
builder.InsertField("NUMPAGES");
builder.Write("-1");

doc.UpdateFields();
doc.Save(@"C:\Temp\out.docx");

Please see Aspose.Words documentation to learn how to work with fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文