How to set page layout break on worksheet using EPPlus

thatstevedude picture thatstevedude · Feb 2, 2016 · Viewed 10k times · Source

Is there a way to set specify where to break the page using EEPlus? I have the following code that sets the printer properties but haven't found a way to set a break point on a certain column.

// Set printer settings
ws.PrinterSettings.PaperSize = ePaperSize.Tabloid;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.FitToPage = true;
ws.PrinterSettings.FitToHeight = 1;
ws.PrinterSettings.FooterMargin = .05M;
ws.PrinterSettings.TopMargin = .05M;
ws.PrinterSettings.LeftMargin = .05M;
ws.PrinterSettings.RightMargin = .05M;

Edit (this helped solve my problem)

ws.Column(30).PageBreak = true;
ws.PrinterSettings.PaperSize = ePaperSize.A3;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.Scale = 75;  

Answer

Ernie S picture Ernie S · Feb 2, 2016

Just need to get reference to the Row and/or Column objects:

ws.Row(20).PageBreak = true;
ws.Column(2).PageBreak = true;

But keep in mind that FitToPage might suppress these.