Calc Guide
Listing 13. Create a database range and an auto filter.
Sub AddNewDatabaseRange()
Dim oRange 'DatabaseRange object.
Dim oAddr 'Cell address range for the database range.
Dim oSheet 'First sheet, which will contain the range.
Dim oDoc 'Reference ThisComponent with a shorter name.
oDoc = ThisComponent
If NOT oDoc.DatabaseRanges.hasByName("MyName") Then
oSheet = ThisComponent.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:F10")
oAddr = oRange.getRangeAddress()
oDoc.DatabaseRanges.addNewByName("MyName", oAddr)
End If
oRange = oDoc.DatabaseRanges.getByName("MyName")
oRange.AutoFilter = True
End Sub
Sorting
The sorting mechanism in a Calc document rearranges the data in the
sheet. The first step in sorting data is to select the data that you want
to sort. To sort the data in Table 23, select the cells from A1 to G16—if
you include the column headers, indicate this in the sort dialog (see
Figure 308). Use Data > Sort to open the Sort dialog (see Figure 307).
You can sort by up to three columns or rows at a time.
Figure 307. Sort by the Name column.
Chapter 13 Calc as a Simple Database 365