title: How to limit paper size to number of rows in c# excel?
body: <p>I want to limit page size to 30 rows and rest of the data start from next page in excel. Currently it is set to <strong>Excel.XlPaperSize.xlPaperA4</strong>. I tried page break with a condition<br>
  <br></p>
  
  <pre><code> if (row_no &gt;= 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;
   }
  </code></pre>
  
  <p>but the code above did not start from next page.
  <br>
  My code for page setup:</p>
  
  <pre><code>        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";
  </code></pre>