NPOI 分页符 [英] NPOI Page Breaks

查看:98
本文介绍了NPOI 分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NPOI 框架生成 97/2003 Excel 工作簿.我需要每 44 行设置一个分页符,从框架下载中提供的示例来看,执行此操作的代码是:

I am using the NPOI framework to generate a 97/2003 Excel workbook. I need to set a page break every 44 rows and from the example provided in the framework download, the code to do this is:

sheet.SetRowBreak(int row)

sheet.SetRowBreak(int row)

我可以验证这些设置了一组行整数,但是在打开文档并查看分页预览时,只有一个页面包含整个工作表.

I can verify these are setting a collection of row integers but when opening the document and viewing the Page Break preview, there is but a single page that encompasses the entire worksheet.

以下示例代码:

for(int rowCount = 0; rowCount < MaxRows; rowCount += 44)
{
   worksheet.SetRowBreak(rowCount);
}

想法?

推荐答案

这是因为 NPOI 的默认值.它被设置为适合整个页面.只需将此行添加到您的代码中,如果工作表包含足够多的行或列,您应该有不止一页.

This is because of the default values from NPOI. It is set to fit the whole thing to one page. Just add this line to your code and you should have more than one page if the worksheet contains enough rows or columns.

worksheet.FitToPage = false;

但是,如果您想将工作表的宽度调整到一页,请不要更改 FitToPage 属性,而是在您的代码中添加如下内容:

But if you want to fit your worksheets width to one page don't change the FitToPage property, but add something like this to your code:

worksheet.PrintSetup.FitHeight = 9999;
// worksheet.PrintSetup.FitWidth = 1; // this is the default value

那么您的工作表的宽度总是不超过一页,高度不超过 9999 页.

Then your worksheet always will have the width of one page or less and the height of 9999 pages or less.

这篇关于NPOI 分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆