I found some snippets lying around that looked like they were supposed to do this, but I can't quite get them to work. This is what I have so far:
Code: Select all
REM ***** BASIC *****
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
dim pages as integer
pages = thisComponent.Sheets(4).getCellRangeByName("F7").Value
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DefinePrintArea", "", 0, Array())
rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "PrintArea"
args2(0).Value = "$A$1:$X$"&mid(Str(pages*54), 2) ' I found it was inserting a space between X and the row number for some reason, so I remove it.
args2(1).Name = "PrintRepeatRow"
args2(1).Value = ""
args2(2).Name = "PrintRepeatCol"
args2(2).Value = ""
' This line is just to put the value out somwhere I can see it; it's not meant functionally
thisComponent.Sheets(0).getCellRangeByName("F15").String = "$A$1:$X$"&mid(Str(pages*54), 2)
dispatcher.executeDispatch(document, ".uno:EditPrintArea", "", 0, args2())
end subIn more detail, it's a "showbook" - a listing of item numbers, their retail and regular dealer prices, and a discounted price, for our yearly trade show. For eternity, we've been pasting in the data one page at a time, with each of the 400+ pages being a separate spreadsheet. If we wanted to insert more items onto a page, we would then have to manually edit the rest of the pages for that vendor (sometimes 12 or more). My idea here is to bring us down to one spreadsheet file per vendor, wherein the user pastes the data onto a separate worksheet within the file, and Calc does the work of filling that data into our template. The page would have multiple templates, one below the other, and fill them in top to bottom.
Of course, if there's a better way to do it, I'd love to hear it. As far as I can tell, using headers and footers wouldn't quite do it, since we like to have a page number both for the whole book and for the page number within the vendor (e.g. page 123 is page 3 of 4 for Widgetco).
Sadly, I'm not very familiar with OO.o macros or BASIC in general, so I appologize that I'm sort of bumbling through this.