The primary purpose of a Calc document is to contain multiple spreadsheets, which in turn contain rows and columns of data-in other words, tables. This chapter introduces appropriate methods to manipulate, traverse, format, and modify the content contained in a Calc document.
OpenOffice.org supports three primary table types: text tables in Writer documents, database tables, and spreadsheets in Calc documents. Each of the different table types is tailored for a specific purpose. Text tables in Writer documents support complex text formatting but only simple table calculations. Spreadsheet documents, on the other hand, support complex calculations and only simple text formatting.
Conceptually, all document types have two components : the data they contain and the controller that determines how the data is displayed. In OpenOffice.org, the collection of data contained in a document is called the model. Each model has a controller that is responsible for the visual presentation of the data. The controller knows the location of the visible text cursor and the current page, and knows what is currently selected.
Every Calc document supports the com.sun.star.sheet.SpreadsheetDocument service. When I write a macro that must be user -friendly and requires a spreadsheet document, I verify that the document is the correct type by using the object method supportsService(). See Listing 1 .
REM If it really matters, you should check the document type REM to avoid a run-time error. s$ = "com.sun.star.sheet.SpreadsheetDocument" If NOT ThisComponent.SupportsService(s$) Then MsgBox "The current document is not a Calc document", 48, "Error" Exit Sub End If
An interface defines a series of methods. If an object implements an interface, it implements every method defined by that interface. A service defines an object by specifying the interfaces that it implements, the properties that it contains, and the other services that it exports. A service indirectly specifies the implemented methods by specifying interfaces. The interfaces supported by the CalcDocument service provide a good overview of the provided functionality (see Table 1 ).
Service | Description |
---|---|
com.sun.star.document.XActionLockable | Temporarily lock the document from user interaction and automatic cell updates. Locking an object makes it possible to prevent internal object updates while you quickly change multiple parts of the objects that might temporarily invalidate each other. |
com.sun.star.drawing.XDrawPagesSupplier | Access all draw pages in this document; there is one draw page for each contained sheet. |
com.sun.star.sheet.XCalculatable | Control automatic calculation of cells . |
com.sun.star.sheet.XConsolidatable | Perform data consolidation. |
com.sun.star.sheet.XGoalSeek | Perform a "Goal Seek" for a cell. |
com.sun.star.sheet.XSpreadsheetDocument | Access the contained spreadsheets. |
com.sun.star.style.XStyleFamiliesSupplier | Access the contained styles by type. |
com.sun.star.util.XNumberFormatsSupplier | Access the number formats. |
com.sun.star.util.XProtectable | Protect and unprotect the document. |