21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Doc.Text.insertTextContent(Cursor, Table, False)<br />

Rows = Table.getRows<br />

Cols = Table.getColumns<br />

For RowIndex = 1 To Rows.getCount()<br />

For ColIndex = 1 To Cols.getCount()<br />

CellName = Chr(Asc("A") - 1 + ColIndex) & RowIndex<br />

Cell = Table.getCellByName(CellName)<br />

Cell.String = "row: " & CStr(RowIndex) + ", column: " & CStr(ColIndex)<br />

Next<br />

Next<br />

More Than Just Text<br />

A table cell is comparable with a standard text. It supports the createTextCursor interface for creating an<br />

associated TextCursor object.<br />

CellCursor = Cell.createTextCursor()<br />

All formatting options for individual characters and paragraphs are therefore automatically available.<br />

The following example searches through all tables of a text document and applies the right-align format to all cells<br />

with numerical values by means of the corresponding paragraph property.<br />

Dim Doc As Object<br />

Dim TextTables As Object<br />

Dim Table As Object<br />

Dim CellNames<br />

Dim Cell As Object<br />

Dim CellCursor As Object<br />

Dim I As Integer<br />

Dim J As Integer<br />

Doc = ThisComponent<br />

TextTables = Doc.getTextTables()<br />

For I = 0 to TextTables.count - 1<br />

Table = TextTables(I)<br />

CellNames = Table.getCellNames()<br />

For J = 0 to UBound(CellNames)<br />

Cell = Table.getCellByName(CellNames(J))<br />

If IsNumeric(Cell.String) Then<br />

CellCursor = Cell.createTextCursor()<br />

CellCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT<br />

End If<br />

Next<br />

Next<br />

The example creates a TextTables list containing all tables of a text that are traversed in a loop. <strong>OpenOffice</strong>.<strong>org</strong><br />

then creates a list of the associated cell names for each of these tables. There are passed through in turn in a loop.<br />

If a cell contains a numerical value, then the example changes the formatting correspondingly. To do this, it first<br />

creates a TextCursor object which makes reference to the content of the table cell and then adapts the<br />

paragraph properties of the table cell.<br />

Text Frames<br />

Text frames are considered to be TextContent objects, just like tables and graphs. They may essentially consist<br />

of standard text, but can be placed at any position on a page and are not included in the text flow.<br />

As with all TextContent objects, a distinction is also made with text frames between the actual creation and<br />

insertion in the document.<br />

Dim Doc As Object<br />

Dim TextTables As Object<br />

Dim Cursor As Object<br />

Dim Frame As Object<br />

Doc = ThisComponent<br />

Cursor = Doc.Text.createTextCursor()<br />

Frame = Doc.createInstance("com.sun.star.text.TextFrame")<br />

Doc.Text.insertTextContent(Cursor, Frame, False)<br />

The text frame is created using the createInstance method of the document object. The text frame created in<br />

Chapter 6 · Text Documents 85

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

Saved successfully!

Ooh no, something went wrong!