Table Auto Formats

From Apache OpenOffice Wiki
Jump to: navigation, search

Table auto formats are used to apply different formats to a cell range. A table auto format is a collection of cell styles used to format all cells of a range. The style applied is dependent on the position of the cell.

The table auto format contains separate information about four different row types and four different column types:

  • First row (header), first data area row, second data area row, last row (footer)
  • First column, first data area column, second data area column, last column

The row or column types for the data area (between first and last row/column) are repeated in sequence. Each cell of the formatted range belongs to one of the row types and column types, resulting in 16 different auto-format fields. In the example below, the highlighted cell has the formatting of the first data area row and last column field. Additionally, this example shows the indexes of all the auto format fields. These indexes are used to access the field with the interface

First column
Second data area column
First data area column
Last Column
First row (header)
First data area row
Second data area row
Last row (footer)


A table auto format is represented by the service It contains exactly 16 auto format fields (service Each auto format field contains all properties of a single cell.

The cell range interface contains the method autoFormat() that applies a table auto format to a cell range. The cell range must have a size of at least 3x3 cells. The boolean properties of the table auto format determine the formatting properties are copied to the cells. The default setting of all the properties is true.

Documentation note.png In the current implementation it is not possible to modify the cell borders of a table auto format (the property TableBorder is missing). Nevertheless, the property IncludeBorder controls whether the borders of default auto formats are applied to the cells.

The collection of all table auto formats is represented by the service There is only one instance of this collection in the whole application. It contains all default and user-defined auto formats that are used in spreadsheets and tables of the word-processing application. It is possible to iterate through all table auto formats with an enumeration, or to access them directly using their index or their name.


The following example shows how to insert a new table auto format, fill it with properties, apply it to a cell range and remove it from the format collection.

  public void doAutoFormatSample(
     xDocument) throws RuntimeException, Exception { 
      // get the global collection of table auto formats, use global service manager
      Object aAutoFormatsObj = xServiceManager.createInstance(""); xAutoFormatsNA = (
          UnoRuntime.queryInterface(, aAutoFormatsObj);
      // create a new table auto format and insert into the container
      String aAutoFormatName = "Temp_Example";
      boolean bExistsAlready = xAutoFormatsNA.hasByName(aAutoFormatName);
      Object aAutoFormatObj = null;
      if (bExistsAlready)
          // auto format already exists -> use it
          aAutoFormatObj = xAutoFormatsNA.getByName(aAutoFormatName);
      else {
          // create a new auto format (with document service manager!)
 xDocServiceManager =
              ( UnoRuntime.queryInterface(
        , xDocument);
          aAutoFormatObj = xDocServiceManager.createInstance("");
          xAutoFormatsNA.insertByName(aAutoFormatName, aAutoFormatObj);
      // index access to the auto format fields xAutoFormatIA = (
          UnoRuntime.queryInterface(, aAutoFormatObj);
      // set properties of all auto format fields
      for (int nRow = 0; nRow < 4; ++nRow) {
          int nRowColor = 0;
          switch (nRow) {
              case 0: nRowColor = 0x999999; break;
              case 1: nRowColor = 0xFFFFCC; break;
              case 2: nRowColor = 0xEEEEEE; break;
              case 3: nRowColor = 0x999999; break;
          for (int nColumn = 0; nColumn < 4; ++nColumn) {
              int nColor = nRowColor;
              if ((nColumn == 0) || (nColumn == 3))
                  nColor -= 0x333300;
              // get the auto format field and apply properties
              Object aFieldObj = xAutoFormatIA.getByIndex(4 * nRow + nColumn);
     xPropSet = (
                  UnoRuntime.queryInterface(, aFieldObj);
              xPropSet.setPropertyValue("CellBackColor", new Integer(nColor));
      // set the auto format to the second spreadsheet xSheets = xDocument.getSheets(); xSheetsIA = (
          UnoRuntime.queryInterface(, xSheets); xSheet =
          ( xSheetsIA.getByIndex(1); xCellRange = xSheet.getCellRangeByName("A5:H25"); xAutoForm = (
          UnoRuntime.queryInterface(, xCellRange);
      // remove the auto format
      if (!bExistsAlready)
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages