> -----Original Message----- > From: Alexandro Colorado [mailto:[EMAIL PROTECTED] > Sent: Wednesday, 15 November, 2006 19:18 > To: [email protected] > Subject: Re: [api-dev] Export selected sheets from Calc to PDF > > Hi this was asked some time ago, there are some parameters to specify a > range. Please read the IDL Reference. > > DeCouto, Douglas wrote: > > Dear All, > > > > Is there a way to programmatically tell the calc_pdf_Export filter to > > only export a particular sheet in a spreadsheet document? I see that > > using the GUI, I can choose `selected' in the PDF export dialog box, > > which will only print the frontmost sheet, which is a good start. > > > > Where can I find documentation on options for cald_pdf_Export?
I've spent a lot of time searching the documentation (the guide and the IDL reference) and, FWIW, there is no mention of the calc_pdf_Export filter in any of it. However, if you search the source code, you can find the PDF export implementation, complete with a list of the parameters (also featured on this list previously, e.g. http://api.openoffice.org/servlets/ReadMsg?listName=dev&msgNo=4472) Previous discussion on this list was about how to print specified pages, which is a different problem (I am not printing, I am using the storeToUrl function, and I want sheets, not pages). One message suggested using the "Selection" property, which is also what the GUI uses when it prints the topmost sheet, but I was unable to replicate this functionality in my code. Instead, I used the idea of setting all sheets invisible except for the one I want, which I saw on this list. This works, you just have to be careful because OOo always wants at least one sheet visible. Here's some code in Python using Python-UDK. I am also using my system Python, not the one supplied with OOo, so I am having problems with getting strings back from OOo, and this code works around that. def path_to_url(p): osPath = os.path.abspath(p) return "file://" + osPath def print_pdf(doc, pdf_filename): outProps = (PropertyValue("FilterName", 0, "calc_pdf_Export", 0), PropertyValue("Overwrite", 0, True, 0), ) url = path_to_url(pdf_filename) doc.storeToURL(url, outProps) def print_sheet_to_pdf(doc, sheet_name, pdf_filename): # 1. I can't get the strings from OpenOffice to work, e.g. for # comparing against the suplied sheet name; I can only pass # strings in to OpenOffice. Furthermore, repeated calls to # getName() on the same object seem to return different data, # so can't be used for comparison. # # 2. Can't use object equality, as repeat calls to get the # object (e.g. getByName() vs. getByIndex()) will return # unique proxy objects for the same underlying OpenOffice # object. # # 3. OpenOffice always wants to have at least one visible # sheet, so ignores any request to make the last visible sheet # invisible. sheets = doc.Sheets # Remember original visibility setting was_vis = {} onw_was_vis = False for i in range(sheets.Count): was_vis[i] = sheets.getByIndex(i).IsVisible if was_vis[i]: one_was_vis = True assert one_was_vis # Make all sheets invisible, except the last one. We start by # making the last sheet visible so that there is always some # other sheet visible, ensuring that when we mark the others # as invisible, OpenOffice doesn't silently make them visible # again. last_sheet = sheets.getByIndex(sheets.Count - 1) last_sheet.IsVisible = True for i in range(sheets.Count - 1): sheets.getByIndex(i).IsVisible = False # Make visible the sheet we want to print. sheets.getByName(sheet_name).IsVisible = True # If the last sheet is the one we don't want to print # (i.e. some other sheet is also visible), make the last sheet # invisible. for i in range(sheets.Count - 1): if sheets.getByIndex(i).IsVisible: last_sheet.IsVisible = False break # Actually print the sheet, that's why we're here, remember? print_pdf(doc, pdf_filename) # Restore original visibility of sheets. Remember trickery # with last sheet so visibility isn't silently reset by # OpenOffice. last_sheet.IsVisible = True for i in range(sheets.Count - 1): sheets.getByIndex(i).IsVisible = was_vis[i] last_sheet.IsVisible = was_vis[sheets.Count - 1] -- Douglas S. J. De Couto *** This e-mail, including attachments, may contain information that is privileged, proprietary, non-public, confidential or exempt from disclosure and is intended to be conveyed only to the designated recipient(s). If you are not an intended recipient, please delete this e-mail, including attachments, and do not disseminate, distribute or copy this communication, by e-mail or otherwise. The unauthorized use, dissemination, distribution or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. We reserve the right to monitor and review the content of all messages sent to or from this e-mail address. We use digital certificates on email where appropriate to protect sensitive information and to identify our employees. To validate our digital signatures, please use this quick update from security authority Quovadis(http://www.quovadis.bm/root.asp). --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
