Difference between revisions of "Documentation/DevGuide/Spreadsheets/Label Ranges"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 19: Line 19:
 
The following example inserts a column label range with the label area G48:H48 and the data area G49:H50, that is, the content of G48 is used as a label for G49:G50 and the content of H48 is used as a label for H49:H50, as shown in the two formulas the example inserts.  
 
The following example inserts a column label range with the label area G48:H48 and the data area G49:H50, that is, the content of G48 is used as a label for G49:G50 and the content of H48 is used as a label for H49:H50, as shown in the two formulas the example inserts.  
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
+
<syntaxhighlight lang="java">
 
   com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByPosition(6, 47, 7, 49);
 
   com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByPosition(6, 47, 7, 49);
 
   com.sun.star.sheet.XCellRangeData xData = (com.sun.star.sheet.XCellRangeData)
 
   com.sun.star.sheet.XCellRangeData xData = (com.sun.star.sheet.XCellRangeData)
Line 52: Line 52:
 
   xSheet.getCellByPosition(8, 48).setFormula("=Apples+Oranges");
 
   xSheet.getCellByPosition(8, 48).setFormula("=Apples+Oranges");
 
   xSheet.getCellByPosition(8, 49).setFormula("=Apples+Oranges");
 
   xSheet.getCellByPosition(8, 49).setFormula("=Apples+Oranges");
 
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Latest revision as of 15:46, 3 January 2021



A label range consists of a label area containing the labels, and a data area containing the data that the labels address. There are label ranges for columns and rows of data, which are kept in two separate collections in the document.

Label Ranges

The com.sun.star.sheet.LabelRanges service contains the document's column label ranges or row label ranges, depending if the ColumnLabelRanges or RowLabelRanges property was used to get it. The com.sun.star.sheet.XLabelRanges interface's addNew() method is used to add a new label range, specifying the label area and data area. The removeByIndex() method removes a label range.

The com.sun.star.sheet.LabelRange service represents a single label range and contains the com.sun.star.sheet.XLabelRange interface to modify the label area and data area.

The following example inserts a column label range with the label area G48:H48 and the data area G49:H50, that is, the content of G48 is used as a label for G49:G50 and the content of H48 is used as a label for H49:H50, as shown in the two formulas the example inserts.

  com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByPosition(6, 47, 7, 49);
  com.sun.star.sheet.XCellRangeData xData = (com.sun.star.sheet.XCellRangeData)
      UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeData.class, xRange);
  Object[][] aValues =
  {
      {"Apples", "Oranges"},
      {new Double(5), new Double(7)},
      {new Double(6), new Double(8)}
  };
  xData.setDataArray(aValues);
 
  // insert a column label range
  Object aLabelsObj = xDocProp.getPropertyValue("ColumnLabelRanges");
  com.sun.star.sheet.XLabelRanges xLabelRanges = (com.sun.star.sheet.XLabelRanges)
      UnoRuntime.queryInterface(com.sun.star.sheet.XLabelRanges.class, aLabelsObj);
  com.sun.star.table.CellRangeAddress aLabelArea = new com.sun.star.table.CellRangeAddress();
  aLabelArea.Sheet = 0;
  aLabelArea.StartColumn = 6;
  aLabelArea.StartRow = 47;
  aLabelArea.EndColumn = 7;
  aLabelArea.EndRow = 47;
  com.sun.star.table.CellRangeAddress aDataArea = new com.sun.star.table.CellRangeAddress();
  aDataArea.Sheet = 0;
  aDataArea.StartColumn = 6;
  aDataArea.StartRow = 48;
  aDataArea.EndColumn = 7;
  aDataArea.EndRow = 49;
  xLabelRanges.addNew(aLabelArea, aDataArea);
 
  // use the label range in formulas
  xSheet.getCellByPosition(8, 48).setFormula("=Apples+Oranges");
  xSheet.getCellByPosition(8, 49).setFormula("=Apples+Oranges");
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages