Printing Spreadsheet Documents

From Apache OpenOffice Wiki
Jump to: navigation, search

Printer and Print Job Settings

Printing is a common office functionality. The chapter Office Development provides in-depth information about it. The spreadsheet document implements the interface for printing. It consists of three methods:

 sequence< com::sun::star::beans::PropertyValue > getPrinter()
 void setPrinter([in] sequence< com::sun::star::beans::PropertyValue > aPrinter)
 void print([in] sequence< com::sun::star::beans::PropertyValue > xOptions)

The following code is used with a given document xDoc to print to the standard printer without any settings:

  // query the XPrintable interface from your document
  XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
  // create an empty printOptions array
  PropertyValue[] printOpts = new PropertyValue[0];
  // kick off printing

There are two groups of properties involved in general printing. The first one is used with setPrinter() and getPrinter(), and controls the printer, and the second is passed to print() and controls the print job. comprises the properties for the printer:

Properties of
Name string - Specifies the name of the printer queue to be used.
PaperOrientation Specifies the orientation of the paper.
PaperFormat Specifies a predefined paper size or if the paper size is a user-defined size.
PaperSize Specifies the size of the paper in 100th mm.
IsBusy boolean - Indicates if the printer is busy.
CanSetPaperOrientation boolean - Indicates if the printer allows changes to PaperOrientation.
CanSetPaperFormat boolean - Indicates if the printer allows changes to PaperFormat.
CanSetPaperSize boolean - Indicates if the printer allows changes to PaperSize. contains the following possibilities for a print job:

Properties of
CopyCount short - Specifies the number of copies to print.
FileName string - If set, specifies the name of the file to print to.
Collate boolean - Advises the printer to collate the pages of the copies. If true, a whole document is printed prior to the next copy, otherwise the page copies are completed together.
Sort boolean - Advises the printer to sort the pages of the copies.
Pages string - Specifies the pages to print with the same format as in the print dialog of the GUI, for example, "1, 3, 4-7, 9-".
Wait boolean - Advises that the print job should be performed synchronously, i.e. wait until printing is complete before returning from printing. Otherwise return is immediate and following actions (e.g. closing the corresponding model) may fail until printing is complete. Default is false.

The following method uses PrinterDescriptor and PrintOptions to print to a special printer, and preselect the pages to print.

  protected void printDocComponent(XComponent xDoc) throws java.lang.Exception {
      XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
      PropertyValue[] printerDesc = new PropertyValue[1];
      printerDesc[0] = new PropertyValue();
      printerDesc[0].Name = "Name";
      printerDesc[0].Value = "5D PDF Creator"; 
      PropertyValue[] printOpts = new PropertyValue[1];
      printOpts[0] = new PropertyValue();
      printOpts[0].Name = "Pages";
      printOpts[0].Value = "3-5,7"; 

Page Breaks and Scaling for Printout

Manual page breaks can be inserted and removed using the property IsStartOfNewPage of the services and For details, refer to the section about page breaks in the chapter Spreadsheet Documents.

To reduce the page size of a sheet so that the sheet fits on a fixed number of printout pages, use the properties PageScale and ScaleToPages of the current page style. Both of the properties are short numbers. The PageScale property expects a percentage and ScaleToPages is the number of pages the printout is to fit. The page style is available through the interface of the document component, and is described in the chapter Overall Document Features.

Print Areas

The Interface is available at spreadsheets. It provides access to the addresses of all printable cell ranges, represented by a sequence of structs.

Methods of
getPrintAreas() Returns the print areas of the sheet.
setPrintAreas() Sets the print areas of the sheet.
getPrintTitleColumns() Returns true if the title columns are repeated on all subsequent print pages to the right.
setPrintTitleColumns() Specifies if the title columns are repeated on all subsequent print pages to the right.
getTitleColumns() Returns the range of columns that are marked as title columns.
setTitleColumns() Sets the range of columns marked as title columns.
getPrintTitleRows() Returns true if the title rows are repeated on all subsequent print pages to the bottom.
setPrintTitleRows() Specifies if the title rows are repeated on all subsequent print pages to the bottom.
getTitleRows() Returns the range of rows that are marked as title rows.
setTitleRows() Sets the range of rows marked as title rows.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages