简体   繁体   English

如何将纸张大小限制为c#excel中的行数?

[英]How to limit paper size to number of rows in c# excel?

I want to limit page size to 30 rows and rest of the data start from next page in excel. 我想将页面大小限制为30行,其余数据从excel中的下一页开始。 Currently it is set to Excel.XlPaperSize.xlPaperA4 . 目前它设置为Excel.XlPaperSize.xlPaperA4 I tried page break with a condition 我尝试了一个有条件的分页符

 if (row_no >= 30)
 {
 rng = (Excel.Range)xl_sheet.Range[xl_sheet.Cells[row_no, 1],xl_sheet.Cells[row_no, 1]];
 xl_sheet.HPageBreaks.Add(rng);
 row_no = 12;
 }

but the code above did not start from next page. 但上面的代码并没有从下一页开始。
My code for page setup: 我的页面设置代码:

        xl_sheet.Select(Type.Missing);
        var ps = xl_sheet.PageSetup;
        ps.Orientation = Excel.XlPageOrientation.xlLandscape;
        ps.FitToPagesTall = false;
        ps.FitToPagesWide = 1;
        ps.Zoom = false;
        ps.PaperSize = Excel.XlPaperSize.xlPaperA4;
        ps.PrintTitleRows = "$1:$11";

I fixed the issue using following code and it working fine: 我使用以下代码修复了问题,它工作正常:

if (row_no% 30==0)
 {
 rng = (Excel.Range)xl_sheet.Range[xl_sheet.Cells[row_no, 1],xl_sheet.Cells[row_no, 1]];
 xl_sheet.HPageBreaks.Add(rng);

 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM