This project has moved and is read-only. For the latest updates, please go here.

More trouble with PageBreak

Nov 9, 2010 at 9:19 PM

Jan,

I can't seem to get pagebreak to work.  I look at your comment in another post "trouble with pagebreak" and tried that solution.

here's what I have tried:

   oR = worksheet.Cells["A26"];
   oR.Value = "X";
   oR.Worksheet.Row(26).PageBreak = true;
   //worksheet.Cells[26, 1].Value = "X";
   //worksheet.Row(26).PageBreak = true;

I don't see a pagebreak in the worksheet.

Thanks,

Duardo

Nov 10, 2010 at 3:36 PM

Hi,

I tried this code and it worked fine (I used the latest source). Not sure what your problem can be.

Anyway I will do a fix in the new version so pagebreaks on empty rows will appear.

Jan

Nov 10, 2010 at 3:53 PM

I am using 2.7.0.1 version.  Is there another planned release?

Duardo

Nov 10, 2010 at 4:02 PM

2.8.0.1 in a week or two.

It should work in 2.7.0.1. Can you provide me with a full sample that fails?

Nov 10, 2010 at 4:19 PM

Thank you Jan for your time.

private void Sample3() {
   //string filename = UniqueFileName(Server.MapPath("~/Reports/"), "GoalReport.xlsx");
   //string justFile = filename;
   //filename = Server.MapPath("~/Reports/") + filename;
   //FileInfo newFile = new FileInfo(filename);

   using (ExcelPackage package = new ExcelPackage()) {
      // add a new worksheet to the empty workbook
      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Performance Report");
      //FileInfo fi = new FileInfo(Server.MapPath("~/SMSlogo.jpg"));

      //ExcelPicture pic = worksheet.Drawings.AddPicture("Logo", fi);
      //pic.SetSize(67, 41);
      //pic.SetPosition(0, 0);

      //Add the headers
      worksheet.Cells["A3:B3"].Merge = true;
      worksheet.Cells["A3"].Value = "Performance";
      worksheet.Cells["A3"].Style.Fill.PatternType = ExcelFillStyle.Solid;
      worksheet.Cells["A3"].Style.Fill.BackgroundColor.SetColor(Color.Navy);
      worksheet.Cells["A3"].Style.Font.Color.SetColor(Color.White);
      worksheet.Cells["A3"].Style.Font.Bold = true;
      worksheet.Cells["A3"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

      worksheet.Cells[4, 1].Value = "Month";
      worksheet.Cells[4, 2].Value = "Number";
      worksheet.Cells["A4:B4"].Style.Fill.PatternType = ExcelFillStyle.Solid;
      worksheet.Cells["A4:B4"].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
      worksheet.Cells["A4:B4"].Style.Font.Color.SetColor(Color.Black);
      worksheet.Cells["A4:B4"].Style.Font.Bold = true;
      worksheet.Cells["A4:B4"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

      worksheet.Cells["A5"].Value = "Sep-07";
      worksheet.Cells["B5"].Value = 9;
      worksheet.Cells["A6"].Value = "Oct-07";
      worksheet.Cells["B6"].Value = 1;

      worksheet.Cells["A7"].Value = "Nov-07";
      worksheet.Cells["B7"].Value = 3;
      worksheet.Cells["A8"].Value = "Dec-07";
      worksheet.Cells["B8"].Value = 3;

      worksheet.Cells["A9"].Value = "Jan-08";
      worksheet.Cells["B9"].Value = 3;
      worksheet.Cells["A10"].Value = "Feb-08";
      worksheet.Cells["B10"].Value = 5;

      worksheet.Cells["A11"].Value = "Mar-08";
      worksheet.Cells["B11"].Value = 5;
      worksheet.Cells["A12"].Value = "Apr-08";
      worksheet.Cells["B12"].Value = 10;
      worksheet.Cells["A13"].Value = "May-08";
      worksheet.Cells["B13"].Value = 3;

      ExcelRange oR = worksheet.Cells["A4:B13"];
      oR.Style.Border.Left.Style = ExcelBorderStyle.Thin;
      oR.Style.Border.Right.Style = ExcelBorderStyle.Thin;
      oR.Style.Border.Top.Style = ExcelBorderStyle.Thin;
      oR.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

      var lineChart = worksheet.Drawings.AddChart("Performance", eChartType.Line) as ExcelLineChart;
      lineChart.SetPosition(4, 0, 2, 0);
      lineChart.SetSize(400, 400);
      lineChart.Series.Add(ExcelRange.GetAddress(5, 2, 13,2), ExcelRange.GetAddress(5, 1, 13, 1));

      lineChart.Title.Text = "Performance";
      lineChart.Series[0].Header = "Number";

      oR = worksheet.Cells["A26"];
      oR.Value = "X";
      oR.Worksheet.Row(26).PageBreak = true;
      //worksheet.Cells[26, 1].Value = "X";
      //worksheet.Row(26).PageBreak = true;
   
      Response.Clear();
      package.SaveAs(Response.OutputStream);
      Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      Response.AddHeader("content-disposition", "attachment;  filename=GoalReport.xlsx");
      Response.End();
   }

}

 Duardo