[Solved] Can I query the print row of a cell?

Discuss the spreadsheet application
Post Reply
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

[Solved] Can I query the print row of a cell?

Post by Duhhh »

Is there a way to determine what the print row of a cell is? For example, if I move a page break to just above a cell, is there a way for that cell to know its print row is now 1, so I could change the format? I could also underline every 10th row on a page if I could know the print row. Yes, I can do this manually, but when I move page breaks, I'd like to make the change automatic.
Last edited by Duhhh on Thu Jun 26, 2008 9:47 pm, edited 1 time in total.
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can I query the print row of a cell?

Post by Villeroy »

You can set one header row per sheet to be repeated on every print page. Always print row #1 on top of every page: Menu:Format>PrintRanges>Edit... Rows to repeat: $1
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

Re: Can I query the print row of a cell?

Post by Duhhh »

That doesn't answer the question. I know about repeating rows, but that's not what I want to do. I want to format rows based on how far down the page they show up. I've looked for something like ROW(), only one that returns the distance from the last page break.
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can I query the print row of a cell?

Post by Villeroy »

OK, that was just in case you don't know the "normal" (and static) method. Can you be shure that your row-heights are the same across pages? Can you assume the same row count on every page?
If so, create a cell style, select your list (or entire columns) and call menu:Format>Conditional ...
[X]Condition 1
[Formula is] NOT(MOD(ROW();40))
Style: MyHeader
[OK]
[I assumed 40 rows per page and a style named "MyHeader"]
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

Re: Can I query the print row of a cell?

Post by Duhhh »

No, I didn't want to assume any of that. The whole reason I wanted to do this is if someone moved a page break. I have some special formats set up based on page position. If I manually move a page break (or insert a row up top which shifts things down the page) I wanted to handle the format change automatically.

The only way I can see to do this is to be able to query the location of page breaks. I haven't found anything to do that yet. I admit it's not something that many people would do (heck, I've been using spreadsheets for 25 years, and this is the first time I've thought about doing such a thing). But it wouldn't surprise me if someone has attacked this already and solved it in a very clever way.

Here's an example of what I want to do. I have one spreadsheet that has a sparsely populated column A, and a fully-populated column B. If I break a page on a row that has a blank in column A, I'd like to print the last valid column-A value on the first detail line of the page. I could create a formula that only printed something in column A if it was the first row on the page, or if it was different than the last value in that colum.
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can I query the print row of a cell?

Post by Villeroy »

[Calc, Basic]Introspective cell functions
Just added CELL_ISHORIZONTALPAGEBREAK and CELL_ISVERTICALPAGEBREAK
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

Re: Can I query the print row of a cell?

Post by Duhhh »

Cool. From that, I can also see how to return WHERE on a page a cell resides, so I could number a sheet based on page and have it update automatically.
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Can I query the print row of a cell?

Post by Villeroy »

Not that cool. This type of function is quite an ugly hack. It is very slow and does not recalculate well. You can use it directly with conditional formatting. Then it will update dynamically when you insert cells or change height/width of rows or columns. But this is very slow as you may test with a conditional format "Function is: CELL_ISHORIZONTALPAGEBREAK(SHEET();ROW();COLUMN())" across some hundreds of rows.
You may use it in a separate hidden column (or row respectively). In this case the recalculation of all cells can be enforced with Ctrl+Shift+F9 before printing.
Right now I notice that it seems to require hard recalculation while in page break preview (menu:View>Page Break Preview). No, it's not really cool.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

Re: [Solved] Can I query the print row of a cell?

Post by Duhhh »

I'm guessing that you pass ROW(); COLUMN() because there's no way to duplicate the behavior of built-in functions that can figure out what cell the formula is in, and act on that cell? (like the CELL() function). Since in my case, I'm always interested in the state of the CURRENT cell, I'd like to write a simpler function that tells me if the cell where the function is being executed is on a page break.

After seeing how difficult the designers made it to get the CURRENT cell, I'm guessing it's even harder to get the cell where a formula executes from?
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Can I query the print row of a cell?

Post by Villeroy »

After seeing how difficult the designers made it to get the CURRENT cell, I'm guessing it's even harder to get the cell where a formula executes from?
In fact it's impossible "from outside". The devs needed years to improve the source code to make the INDIRECT function work with named ranges and relative references.
Sheet,Row,Column-indices simply work while beeing as flexible as the relative/absolute addressing scheme. I don't know how to solve the problems with your page break functions. At least they return the desired information when you turn on page break preview and hit Ctrl+Shift+F9.
All the other CELL_ functions on my module intend to fix badly designed sheets where information is hidden in colours, notes, hyperlink-fields. I recommend them to extract info from cells. Then replace those formulas with their return values, so you can use conditional formatting, function HYPERLINK or whatever regular spreadsheet function. These functions are not intended to extend Calc's functionality. Whenever you want to read another cell property, copy one of the functions, replace the function name and the property/method to be called. This is how I derived the 2 page break functions within a seconds.
The performance issue is due to the fact that every single API-call seems to be very expensive, independent from the used scripting language (I tested with Basic and Python).
Regular cell functions (crunching some values without API calls) work fairly performant (although Basic is really slow compared to Python).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply