I had all of this done in Excel, but it doesn't work now that I moved over to OO. I would like to do the following:
1) Remove all page breaks for the entire sheet
2) Remove all cell borders
3) Find the last row in the sheet with content (I already know what the column is going to be)
4) Loop through all rows with content and apply 1 (one) page break if it reaches a row whose "A" cell is empty, but has content in "C". Do not apply anymore page breaks.
5) Select all rows "A:C" with content and apply a border for better print readability
Like I said, I had this all working in Excel. I just want this to work in OO. I don't care what language. Can anyone or many of you point me in the right direction? Thank you in advance.
[Solved] Removing/Adding Page Breaks, cell borders
-
- Posts: 4
- Joined: Wed Jun 15, 2011 9:49 pm
[Solved] Removing/Adding Page Breaks, cell borders
Last edited by Hagar Delest on Thu Jun 16, 2011 8:45 pm, edited 2 times in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 3.2 on Ubuntu 10.04
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Removing/Adding Page Breaks, cell borders
I'm doing ooBasic here, leave it as an exercise to translate. I'll be working on the active sheet.lieutdan13 wrote:I had all of this done in Excel, but it doesn't work now that I moved over to OO. I would like to do the following:
1) Remove all page breaks for the entire sheet
Remove the page breaks:
Code: Select all
Sub removePageBreaks
Dim oDoc as Object
Dim oSheet As Object
oDoc = ThisComponent
oSheet = oDoc.CurrentController.ActiveSheet
oSheet.removeAllManualPageBreaks()
End Sub
Pass the activesheet as fromRange to:2) Remove all cell borders
Code: Select all
Sub removeCellBorders(fromRange As Object)
Dim BlankBorder As new com.sun.star.table.BorderLine
BlankBorder.Color = 0
BlankBorder.InnerLineWidth = 0
BlankBorder.LineDistance = 0
BlankBorder.OuterLineWidth = 0
With fromRange
.DiagonalBLTR = BlankBorder
.DiagonalTLBR = BlankBorder
.TopBorder = BlankBorder
.BottomBorder = BlankBorder
.LeftBorder = BlankBorder
.RightBorder = BlankBorder
End With
End Sub
Couple of ways to do this. I'll just get the entire used area, starting at A13) Find the last row in the sheet with content (I already know what the column is going to be)
Code: Select all
Function getUsedArea() As Object
Dim oDoc As Object
Dim oSheet As Object
Dim oCellCursor As Object
oDoc = ThisComponent
oSheet = oDoc.CurrentController.getActiveSheet()
oCellCursor = oSheet.createCursor()
oCellCursor.GotoEndOfUsedArea(True)
getUsedArea = oCellCursor
End Function
Code: Select all
Function getEndofUsedArea() As new com.sun.star.table.CellAddress
Dim oCellCursor As Object
Dim UsedArea As Object
Dim ca As new com.sun.star.table.CellAddress
UsedArea = getUsedArea()
ca.Sheet = UsedArea.RangeAddress.Sheet
ca.Column = UsedArea.RangeAddress.EndColumn
ca.Row = UsedArea.RangeAddress.EndRow
getEndofUsedArea = ca
End Function
Here's the main routine, which does 1-3 and then 4. It inserts the break above said row, you might want to make it happen one more row down.4) Loop through all rows with content and apply 1 (one) page break if it reaches a row whose "A" cell is empty, but has content in "C". Do not apply anymore page breaks.
Code: Select all
Sub Main
Dim oDoc As Object
Dim oSheet As Object
Dim aRow As Object
Dim BreakRow As Boolean
Dim i As Long
Dim end_row As Long
oDoc = ThisComponent
oSheet = oDoc.CurrentController.getActiveSheet()
removePageBreaks()
removeCellBorders(oSheet)
end_row = getEndofUsedArea.Row
i = 0
BreakRow = False
Do While i <= end_row and not BreakRow
aRow = oSheet.Rows(i)
if aRow.getCellByPosition(0,0).getType() = com.sun.star.table.CellContentType.EMPTY And aRow.getCellByPosition(2,0).getType() <> com.sun.star.table.CellContentType.EMPTY then
BreakRow = True
else
i = i + 1
endif
Loop
if BreakRow then
aRow.isStartOfNewPage = True
endif
End Sub
See if you can manage part 5 given 1-4.5) Select all rows "A:C" with content and apply a border for better print readability
Like I said, I had this all working in Excel. I just want this to work in OO. I don't care what language. Can anyone or many of you point me in the right direction? Thank you in advance.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 4
- Joined: Wed Jun 15, 2011 9:49 pm
Re: Removing/Adding Page Breaks, cell borders
Thank you Charlie for taking the time to write your post!! This is exactly what I needed. I had no problem with the code. It was just a matter of copy and paste. And I did figure out how to add the border to the active range. I copied and modified removeCellBorders, got the active range "oRange = oSheet.getCellRangeByPosition(0, 0, 2, end_row)" and called my new sub-routine. Thanks a bunch.
OpenOffice 3.2 on Ubuntu 10.04