[Solved] Limit number of rows or columns when saving to pdf

The Application Programming Interface and the OASIS Open Document Format

[Solved] Limit number of rows or columns when saving to pdf

Postby bhh1988 » Wed Nov 20, 2013 7:25 am

Hi guys,

How can I limit/cut-off the number of rows or columns of a spreadsheet when saving to pdf? Effectively, I want to crop or cut-off spreadsheets that are too large, usually because there are too many empty rows.

I know that you can get the bounds of the spreadsheet with something like:
Code: Select all   Expand viewCollapse view
cursor = sheet.createCursor()
cursor.gotoStartOfUsedArea(False)
cursor.gotoEndOfUsedArea(True)
usedRange = cursor.getRangeAddress()

(usedRange.StartColumn, usedRange.EndColumn, usedRange.StartRow, usedRange.EndRow are defined here).

But I don't know how to use this to cut off the sheet.

Thanks.
Last edited by Hagar Delest on Thu Nov 21, 2013 8:56 am, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.5 on Linux
bhh1988
 
Posts: 6
Joined: Wed Nov 20, 2013 5:53 am

Re: Limit number of rows or columns when saving to pdf

Postby Villeroy » Wed Nov 20, 2013 12:22 pm

Code: Select all   Expand viewCollapse view
sh = ThisComponent.Sheets.getByIndex(wantedRange.Sheet)
sh.setPrintArea(Array(wantedRange))

You can print disjunct ranges, therefore the print area is an array of range addresses.
If you need to print other sheets than that one, you have to declare the other sheets print areas too (e.g. by their used range).

Code: Select all   Expand viewCollapse view
sh = ThisComponent.Sheets.getByIndex(wantedRange.Sheet
rows = sh.getRows()
cols = sh.getColumns()
for r = 50 to usedRange.EndRow
  rows.getByIndex(r).IsVisible = False
next r
for c = 50 to usedRange.EndColumn
  cols.getByIndex(c).IsVisible = False
next c

Should be reset after printing (or not).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27760
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Limit number of rows or columns when saving to pdf

Postby bhh1988 » Thu Nov 21, 2013 1:51 am

Awesome. This works!

I also stumbled upon this which was helpful and I think you wrote this as well:
https://wiki.openoffice.org/wiki/Python ... agesRanges
OpenOffice 3.5 on Linux
bhh1988
 
Posts: 6
Joined: Wed Nov 20, 2013 5:53 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest