Page breaks in Excel VB.Net

I work with office interaction and I am having problems inserting page breaks in excel. My code works fine with horizontal page breaks, but I also need to set the page layout to vertical. My code is lower, can someone change it to make a vertical page break in the ā€œIā€ column, this code does the correct horizontal page layout, but still 150 pages because the vertical page layout is not set correctly. Thanks in advance.

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

r.PageBreak = 1 
+4
source share
3 answers

Try setting vertical page layout for the column object itself, and not for a range of cells.

0
source

it

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

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

+3
source

If you need a page like A1: D15
for this

 excelWorksheet.Range(E16).PageBreak = 1 

It will create both vertical and horizontal page breaks.

This is just an example. The corresponding code.

0
source

Source: https://habr.com/ru/post/1305137/


All Articles