OpenOffice.org OpenOffice - 3.3 Základní průvodce Strana 317

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 434
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 316
The method addNewByname() accepts four arguments; the name, content, position,
and type. The fourth argument to the method addNewByName() is a combination of
flags that specify how the named range will be used (see Table 13). The most
common value is 0, which is not a defined constant value.
Table 13. com.sun.star.sheet.NamedRangeFlag constants.
Value Name Description
1 FILTER_CRITERIA The range contains filter criteria.
2 PRINT_AREA The range can be used as a print range.
4 COLUMN_HEADER The range can be used as column headers for
printing.
8 ROW_HEADER The range can be used as row headers for
printing.
The third argument, a cell address, acts as the base address for cells referenced in a
relative way. If the cell range is not specified as an absolute address, the referenced
range will be different based on where in the spreadsheet the range is used. The
relative behavior is illustrated in Listing 11, which also illustrates another usage of a
named range—defining an equation. The macro in Listing 11 creates the named
range AddLeft, which refers to the equation A3+B3 with C3 as the reference cell. The
cells A3 and B3 are the two cells directly to the left of C3, so, the equation
=AddLeft() calculates the sum of the two cells directly to the left of the cell that
contains the equation. Changing the reference cell to C4, which is below A3 and B3,
causes the AddLeft equation to calculate the sum of the two cells that are to the left
on the previous row.
Listing 11. Create the AddLeft named range.
Sub AddNamedFunction()
Dim oSheet 'Sheet that contains the named range.
Dim oCellAddress 'Address for relative references.
Dim oRanges 'The NamedRanges property.
Dim oRange 'Single cell range.
Dim sName As String 'Name of the equation to create.
sName = "AddLeft"
oRanges = ThisComponent.NamedRanges
If NOT oRanges.hasByName(sName) Then
oSheet = ThisComponent.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("C3")
oCellAddress = oRange.getCellAddress()
oRanges.addNewByName(sName, "A3+B3", oCellAddress, 0)
End If
End Sub
Tip
Listing 11 illustrates two capabilities that are not widely known. A named
range can define a function. Also, the third argument acts as the base
address for cells referenced in a relative way.
Chapter 13 Calc as a Simple Database 317
Zobrazit stránku 316
1 2 ... 312 313 314 315 316 317 318 319 320 321 322 ... 433 434

Komentáře k této Příručce

Žádné komentáře