简体   繁体   English

使用C#在Excel中获取每页的行数

[英]Getting the number of rows PER PAGE in Excel using C#

I stated the question above the way I did, because I can already do the following, and it doesn't give me the solution I need. 我在做事的上方说了这个问题,因为我已经可以做以下事情了,但并没有给我我需要的解决方案。

I can: 我可以:

  • Get the number of pages per sheet 获取每张纸的页数
  • Get the last USED row on any given SHEET (not per printed page, so that doesn't help) 获取任何给定SHEET上的最后一个USED行(不是每个打印页面,因此无济于事)
  • I can find out if manual or automatic page breaks have been inserted (just not WHERE) 我可以确定是否插入了手动或自动分页符(只是没有插入)

And that's what I need: To know the number of the row for each page break on any given sheet. 那就是我需要的:要知道给定工作表上每个分页符的行数。 Some sheets have 1 page, some have 100. 有些纸有1页,有些纸有100页。

I need to do this because I need to put something at the bottom of each page, however, the number of pages per sheet is not static. 我需要这样做,因为我需要在每页的底部放置一些内容,但是每张纸的页数不是静态的。 Some sheets have been set to landscape, others to portrait. 有些图纸已设置为横向,另一些已设置为纵向。 Some sheets have the "Put all columns on one page" option set, which CHANGES the number of rows on that page. 某些工作表具有“将所有列放在一页上”选项集,该选项会更改该页面上的行数。

PLEASE NOTE: The solution to this problem is not "Use the footer", as the footer will not accept the data that I need to put on each page. 请注意:解决此问题的方法不是“使用页脚”,因为页脚将不接受我需要在每页上放置的数据。

I also cannot statically decide the number of rows each page type might have -- I let Excel decide that when I set the orientation. 我也不能静态地确定每种页面类型可能具有的行数-我让Excel在设置方向时进行确定。

I've been looking for several days now, and I have been unable to find how to determine what the last row on a printed page will be. 我一直在寻找几天,但一直无法找到如何确定打印页面的最后一行。

I'm using office and VS 2010 and I'm using the office interop. 我正在使用Office和VS 2010,并且正在使用Office互操作。 I'm not posting much code because I have no idea what to use at this point. 我不会发布太多代码,因为此时我不知道该使用什么。 However, it is safe to say that to access any given worksheet I'm using the following code: 但是,可以肯定地说,我正在使用以下代码访问任何给定的工作表:

Excel.Application excelApp = new Excel.Application();

Excel.Worksheet workSheet; Excel.Worksheet workSheet;

I'd be willing to bet that there's a very simple way to do this, and I just haven't hit across the right combination of google search terms. 我愿意打赌,有一种非常简单的方法可以做到这一点,而我只是没有找到正确的Google搜索字词组合。 But it's been a few days now, so I thought I'd post something here. 但是已经过去了几天,所以我想在这里发布一些内容。 Thanks for any help. 谢谢你的帮助。

I don't think you have a way to calculate that on your own... It is very complicated, because the number of rows on each page depends on many variables (Printer page size, orientation, zoom level, etc.). 我认为您没有办法自行计算……这非常复杂,因为每页上的行数取决于许多变量(打印机页面大小,方向,缩放级别等)。

You can try to use this: Repeat specific rows or columns on every printed page 您可以尝试使用此方法: 在每个打印页面上重复特定的行或列

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

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