21.08.2013 Views

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A database range provides behavior that is useful when performing database related activities. For<br />

example, you can mark the first row as headings. To create, modify, or delete a database range,<br />

use Data > Define Range to open the Define Data Range dialog (see Figure 316). When you first<br />

define a range, the Modify button shown in the example is labeled New.<br />

Figure 316. Define a database range<br />

In a macro, a database range is accessed, created, and deleted from the DatabaseRanges<br />

property. <strong>The</strong> macro in Listing 13 creates a database range named MyName and sets the range to<br />

be used as an auto filter.<br />

Listing 13. Create a database range and an auto filter.<br />

Sub AddNewDatabaseRange()<br />

Dim oRange 'DatabaseRange object.<br />

Dim oAddr 'Cell address range for the database range.<br />

Dim oSheet 'First sheet, which will contain the range.<br />

Dim oDoc 'Reference ThisComponent with a shorter name.<br />

oDoc = ThisComponent<br />

If NOT oDoc.DatabaseRanges.hasByName("MyName") <strong>The</strong>n<br />

oSheet = ThisComponent.getSheets().getByIndex(0)<br />

oRange = oSheet.getCellRangeByName("A1:F10")<br />

oAddr = oRange.getRangeAddress()<br />

oDoc.DatabaseRanges.addNewByName("MyName", oAddr)<br />

End If<br />

Chapter 13 <strong>Calc</strong> as a Simple Database 301

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!