Calc Guide
If NOT oRanges.hasByName(sName$) Then
REM I can obtain the cell address by obtaining the cell
REM and then extracting the address from the cell.
Dim oCellAddress As new com.sun.star.table.CellAddress
oCellAddress.Sheet = 0 'The first sheet.
oCellAddress.Column = 1 'Column B.
oCellAddress.Row = 2 'Row 3.
REM The first argument is the range name.
REM The second argument is formula or expression to
REM use. The second argument is usually a string that
REM defines a range.
REM The third argument specifies the base address for
REM relative cell references.
REM The fourth argument is a set of flags that define
REM how the range is used, but most ranges use 0.
REM The fourth argument uses values from the
REM NamedRangeFlag constants (see Table 13).
s$ = "$Sheet1.$B$3:$D$6"
oRanges.addNewByName(sName$, s$, oCellAddress, 0)
End If
REM Get a range using the created named range.
oRange = ThisComponent.NamedRanges.getByName(sName$)
REM Print the string contained in cell $Sheet1.$B$3
oCell = oRange.getReferredCells().getCellByPosition(0,0)
Print oCell.getString()
End Sub
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.
Chapter 13 Calc as a Simple Database 361