Tutorial :Page Breaks In Excel VB.Net



Question:

I'm working with the Office Interop and having trouble inserting page breaks in Excel. My code is working fine with the horizontal page break but I also need to set the vertical pagebreak. Can somone modify my code below, to make a vertical page break on column I?

This code is making the correct horizontal pagebreaks but is still 150 pages long because the vertical pagebreak is not set correctly.

Dim r As Excel.Range = CType(xlWorkSheet.Cells(27, 1), Excel.Range)    r.PageBreak = 1  


Solution:1

Try setting the vertical pagebreak for the right Column object itself, rather than the cells range.


Solution:2

This

sheet.VPageBreaks.Add(sheet.Range["J1"]);   

worked for me to set a vertical page break. As shown in the picture, it seems to put the page break before the specified column: enter image description here


Solution:3

If you want page like A1:D15
for that

excelWorksheet.Range(E16).PageBreak = 1   

It will create both vertical and horizontal page break.

This is just example. Code accordingly.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »