简体   繁体   English

在Excel VB.Net中分页

[英]Page Breaks In Excel VB.Net

I'm working with the Office Interop and having trouble inserting page breaks in Excel. 我正在使用Office Interop,并且无法在Excel中插入分页符。 My code is working fine with the horizontal page break but I also need to set the vertical pagebreak . 我的代码在horizontal page break vertical pagebreak正常工作,但我还需要设置vertical pagebreak Can somone modify my code below, to make a vertical page break on column I ? 可以在下面修改我的代码,在第一column I上进行vertical page break吗?

This code is making the correct horizontal pagebreaks but is still 150 pages long because the vertical pagebreak is not set correctly. 此代码正在进行正确的horizontal pagebreaks但仍然是150页长,因为未正确设置垂直分页。

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

r.PageBreak = 1

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: 如图所示,它似乎将分页放在指定的列之前: 在此输入图像描述

尝试为右列对象本身而不是单元格范围设置垂直分页符。

If you want page like A1:D15 如果你想要像A1:D15这样的页面
for that 为了那个原因

excelWorksheet.Range(E16).PageBreak = 1 

It will create both vertical and horizontal page break. 它将创建垂直和水平分页符。

This is just example. 这只是一个例子。 Code accordingly. 相应的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM