Difference between revisions of "NO/Documentation/BASIC Guide/More Than Text"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Created page with '{{NO/Documentation/BASICGuideTOC/v2 |ShowPrevNext=block |ShowPrevPage=block |PrevPage=NO/Documentation/BASIC Guide/Editing Text Documents |NextPage=NO/Documentation/BASIC Guide/S…')
 
 
Line 6: Line 6:
 
|textdocs=block
 
|textdocs=block
 
}}
 
}}
{{DISPLAYTITLE:Fremmedobjekt i teksten}}
+
{{DISPLAYTITLE:Tabeller, figurer og andre objekt.}}
 
__NOTOC__  
 
__NOTOC__  
 
Tekstdokument kan ha mer enn ren tekst i avsnitt.  Fremmedobjekt som tabeller, tegninger, tekstfelter og annet  
 
Tekstdokument kan ha mer enn ren tekst i avsnitt.  Fremmedobjekt som tabeller, tegninger, tekstfelter og annet  
 
kan forankres eller flyte rundt i dokumentet.   
 
kan forankres eller flyte rundt i dokumentet.   
===TextContent===
+
==TextContent==
 
Forankring styres via tjenesten <idl>com.sun.star.text.TextContent</idl> som alle objekt støtter.
 
Forankring styres via tjenesten <idl>com.sun.star.text.TextContent</idl> som alle objekt støtter.
 
Egenskaper:
 
Egenskaper:
;<tt>AnchorType (Enum)</tt>: Hvordan objektet skal forankres (<idl>com.sun.star.text.TextContentAnchorType</idl>).
+
*<tt>AnchorType (Enum)</tt>: Hvordan objektet skal forankres (<idl>com.sun.star.text.TextContentAnchorType</idl>).
;<tt>AnchorTypes (sequence of Enum)</tt>: Alle typer forankring for objektet.
+
*<tt>AnchorTypes (sequence of Enum)</tt>: Alle typer forankring for objektet.
;<tt>TextWrap (Enum)</tt>: Hvordan tekst skal "omslutte" objektet (<idl>com.sun.star.text.WrapTextMode</idl>).
+
*<tt>TextWrap (Enum)</tt>: Hvordan tekst skal "omslutte" objektet (<idl>com.sun.star.text.WrapTextMode</idl>).
 
Metoder som dokumentet tilbyr:
 
Metoder som dokumentet tilbyr:
 
*createInstance() lager et nytt objekt som støtter <tt>TextContent</tt>.
 
*createInstance() lager et nytt objekt som støtter <tt>TextContent</tt>.
Line 21: Line 21:
 
*removeTextContent() fjerner et objekt fra teksten.
 
*removeTextContent() fjerner et objekt fra teksten.
  
===Tabeller===
+
==Tabeller==
 
Eksemplet viser innsetting av en ny tabell:
 
Eksemplet viser innsetting av en ny tabell:
 
<source lang="oobas">
 
<source lang="oobas">
Dim Kalender As Object
 
Dim Cursor As Object
 
 
Cursor = ThisComponent.Text.createTextCursor()
 
Cursor = ThisComponent.Text.createTextCursor()
 
Kalender = ThisComponent.createInstance("com.sun.star.text.TextTable")
 
Kalender = ThisComponent.createInstance("com.sun.star.text.TextTable")
Line 43: Line 41:
 
</source>
 
</source>
  
En tabell har rader og celler, men ingen eksplisitte kolonner.
+
Tabeller støtter <idl>com.sun.star.text.TextTable</idl> og har egenskaper
 
+
(avstander er i 1/100 mm):
Tabeller støtter <idl>com.sun.star.text.TextTable</idl> og har egenskaper som:
+
*<tt>BackColor (Long)</tt>: bakgrunnsfarge.
;<tt>BackColor (Long)</tt>:background color of table.
+
*<tt>BottomMargin (Long)</tt>: bunnmarg.
;<tt>BottomMargin (Long)</tt>:bottom margin in 100ths of a millimeter.
+
*<tt>LeftMargin (Long)</tt>: venstremarg.
;<tt>LeftMargin (Long)</tt>:left margin in 100ths of a millimeter.
+
*<tt>RightMargin (Long)</tt>: høyremarg.
;<tt>RightMargin (Long)</tt>:right margin in 100ths of a millimeter.
+
*<tt>TopMargin (Long)</tt>: toppmarg.
;<tt>TopMargin (Long)</tt>:top margin in 100ths of a millimeter.
+
*<tt>RepeatHeadline (Boolean)</tt>: True hvis overskrift skal gjentas på hver side.  
;<tt>RepeatHeadline (Boolean)</tt>:table header is repeated on every page.  
+
*<tt>Width (Long)</tt>: bredde.
;<tt>Width (Long)</tt>:absolute width of the table in 100ths of a millimeter.
+
===Alle rader og kolonner===
 
+
Tabellen tilbyr <tt>getRows</tt> og getColumns().  Begge gir en liste som
Tabellens rader nås som følger:
+
støtter <idl>com.sun.star.table.XTableRows</idl>.  De tilbyr:
 +
*<tt>getByIndex(Integer)</tt>:  enkeltobjekt.
 +
*<tt>getCount()</tt>:  antallet objekt.
 +
*<tt>insertByIndex(i, n)</tt>:  setter inn i nye objekt fra posisjon n.
 +
*<tt>removeByIndex(i, n)</tt>:  sletter n objekt fra posisjon n.
 +
OBS:  insert og remove kun hvis tabellen er fri for "merged cells".
 +
Tabellens annenhver rad får ny bakgrunnsfarge som under:
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
Cursor = ThisComponent.Text.createTextCursor()
Dim Table As Object
+
tabell = ThisComponent.createInstance("com.sun.star.text.TextTable")
Dim Cursor As Object
+
tabell.initialize(5, 4)
Dim Rows As Object
+
ThisComponent.Text.insertTextContent(Cursor, Table, False)
Dim Row As Object
+
rader = tabell.getRows
Dim I As Integer
+
For I = 0 To rader.getCount() - 1 Step 2
+
   rad = rader.getByIndex(I)
Doc = ThisComponent
+
   rad.BackColor = &HFF00FF
Cursor = Doc.Text.createTextCursor()
+
 
+
Table = Doc.createInstance("com.sun.star.text.TextTable")
+
Table.initialize(5, 4)
+
 
+
Doc.Text.insertTextContent(Cursor, Table, False)
+
Rows = Table.getRows
+
For I = 0 To Rows.getCount() - 1
+
   Row = Rows.getByIndex(I)
+
   Row.BackColor = &HFF00FF
+
 
Next
 
Next
 
</source>
 
</source>
====Liste over alle rader====
+
===Enkeltrad===
Tabellen tilbyr <tt>getRows</tt> som gir en liste med alle rader. 
+
Denne listen støtter <idl>com.sun.star.table.XTableRows</idl>, et interface som tilbyr:
+
;<tt>getByIndex(Integer)</tt>:returns a row object for the specified index.
+
;<tt>getCount()</tt>:returns the number of row objects.
+
;<tt>insertByIndex(Index, Count)</tt>:inserts Count rows in the table as of the <tt>Index</tt> position.
+
;<tt>removeByIndex(Index, Count)</tt>:deletes Count rows from the table as of the <tt>Index</tt> position.
+
OBS:  insert og remove kun hvis tabellen er fri for "merged cells".
+
 
+
====Enkeltrad====
+
 
Hver rad støtter
 
Hver rad støtter
 
<idl>com.sun.star.text.TextTableRow</idl> service og tilbyr følgende:
 
<idl>com.sun.star.text.TextTableRow</idl> service og tilbyr følgende:
;<tt>BackColor (Long)</tt>:background color of row.
+
*<tt>BackColor (Long)</tt>: bakgrunnsfarge.
;<tt>Height (Long)</tt>:height of line in 100ths of a millimeter.
+
*<tt>Height (Long)</tt>: høyde.
;<tt>IsAutoHeight (Boolean)</tt>:table height is dynamically adapted to the content.
+
*<tt>IsAutoHeight (Boolean)</tt>: om  høyde skal autotilpasses.
;<tt>VertOrient (const)</tt>:vertical orientation of the text frame — details on vertical orientation of the text within the table (values in accordance with <idl>com.sun.star.text.VertOrientation</idl>)
+
*<tt>VertOrient (const)</tt>: vertikal justering (<idl>com.sun.star.text.VertOrientation</idl>)
 
+
===Celler===
=== Columns ===
+
Hver celle har et unikt navn. Cellen "øverst, til venstre" heter vanligvis A1, der A angir kolonne og 1 er rad. Altså har neste kolonne navnet B. En tabell har metoden getCellByName(n).
 
+
Eksemplet under setter verdien i tabellens celler:
Columns are accessed in the same way as rows, using the <tt>getByIndex</tt>, <tt>getCount</tt>, <tt>insertByIndex</tt>, and <tt>removeByIndex</tt> methods on the <tt>Column</tt> object, which is reached through <tt>getColumns</tt>. They can, however, only be used in tables that do not contain merged table cells. Cells cannot be formatted by column in {{OOo}} Basic. To do so, the method of formatting individual table cells must be used.
+
 
+
=== Cells ===
+
 
+
Each cell of a {{OOo}} document has a unique name. If the cursor of {{OOo}} is in a cell, then the name of that cell can be seen in the status bar. The top left cell is usually called A1 and the bottom right row is usually called <tt>Xn</tt>, where <tt>X</tt> stands for the letters of the top column and <tt>n</tt> for the numbers of the last row. The cell objects are available through the <tt>getCellByName()</tt> method of the table object. The following example shows a loop that passes through all the cells of a table and enters the corresponding row and column numbers into the cells.
+
 
+
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
Cursor = ThisComponent.Text.createTextCursor()
Dim Table As Object
+
tabell = ThisComponent.createInstance("com.sun.star.text.TextTable")
Dim Cursor As Object
+
tabell.initialize(5, 4)
Dim Rows As Object
+
ThisComonent.Text.insertTextContent(Cursor, Table, False)
Dim RowIndex As Integer
+
rader = tabell.getRows
Dim Cols As Object
+
kolonner = tabell.getColumns
Dim ColIndex As Integer
+
For rad = 1 To rader.getCount()
Dim CellName As String
+
   For kol = 1 To kolonner.getCount()
Dim Cell As Object
+
       celleNavn = Chr(Asc("A") - 1 + kol) & rad
 
+
       celle = tabell.getCellByName(celleNavn)
Doc = ThisComponent
+
       celle.String = "rad: " & CStr(rad) + ", kolonne: " & CStr(kol)
Cursor = Doc.Text.createTextCursor()
+
 
+
Table = Doc.createInstance("com.sun.star.text.TextTable")
+
Table.initialize(5, 4)
+
 
+
Doc.Text.insertTextContent(Cursor, Table, False)
+
 
+
Rows = Table.getRows
+
Cols = Table.getColumns
+
 
+
For RowIndex = 1 To Rows.getCount()
+
   For ColIndex = 1 To Cols.getCount()
+
       CellName = Chr(Asc("A") - 1 + ColIndex) & RowIndex
+
       Cell = Table.getCellByName(CellName)
+
       Cell.String = "row: " & CStr(RowIndex) + ", column: " & CStr(ColIndex)
+
 
   Next
 
   Next
 
Next
 
Next
 
</source>
 
</source>
 
+
En celle ligner en vanlig tekst og tilbyr blant annet createTextCursor().
A table cell is comparable with a standard text. It supports the <tt>createTextCursor</tt> interface for creating an associated <tt>TextCursor</tt> object.
+
Utseendet i cellen endres som vanlig tekst.
 
+
I eksemplet under høyre-justeres alle celler med tall.
 
<source lang="oobas">
 
<source lang="oobas">
CellCursor = Cell.createTextCursor()
+
tabellListe = ThisComponent.getTextTables()
</source>
+
For I = 0 to tabellListe.count - 1
 
+
   tabell = tabellListe(I)
All formatting options for individual characters and paragraphs are therefore automatically available.
+
   celleNavn = tabell.getCellNames()
 
+
   For J = 0 to UBound(celleNavn)
The following example searches through all tables of a text document and applies the right-align format to all cells with numerical values by means of the corresponding paragraph property.
+
       celle = tabell.getCellByName( celleNavn(J) )
 
+
       If IsNumeric( celle.String ) Then
<source lang="oobas">
+
         celleCursor = celle.createTextCursor()
Dim Doc As Object
+
         celleCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
Dim TextTables As Object
+
Dim Table As Object
+
Dim CellNames
+
Dim Cell As Object
+
Dim CellCursor As Object
+
Dim I As Integer
+
Dim J As Integer
+
 
+
Doc = ThisComponent
+
TextTables = Doc.getTextTables()
+
 
+
For I = 0 to TextTables.count - 1
+
   Table = TextTables(I)
+
   CellNames = Table.getCellNames()
+
 
+
   For J = 0 to UBound(CellNames)
+
       Cell = Table.getCellByName(CellNames(J))
+
       If IsNumeric(Cell.String) Then
+
         CellCursor = Cell.createTextCursor()
+
         CellCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
+
 
       End If
 
       End If
 
   Next
 
   Next
 
Next
 
Next
 
</source>
 
</source>
 
+
==Innrammet tekst==
The example creates a <tt>TextTables</tt> list containing all tables of a text that are traversed in a loop. {{OOo}} then creates a list of the associated cell names for each of these tables. There are passed through in turn in a loop. If a cell contains a numerical value, then the example changes the formatting correspondingly. To do this, it first creates a <tt>TextCursor</tt> object which makes reference to the content of the table cell and then adapts the paragraph properties of the table cell.
+
Innrammet tekst er også et flytende objekt, som tabeller og bilder, og
 
+
behandles likt med disse. 
== Text Frames ==
+
Den tilbyr <idl>com.sun.star.text.BaseFrameProperties</idl> og
 
+
har derved egenskaper som:
Text frames are considered to be <tt>TextContent</tt> objects, just like tables and graphs. They may essentially consist of standard text, but can be placed at any position on a page and are not included in the text flow.
+
*BackColor (Long): bakgrunnsfarge.
 
+
*BottomMargin (Long): bunnmark.
As with all <tt>TextContent</tt> objects, a distinction is also made with text frames between the actual creation and insertion in the document.
+
*LeftMargin (Long): venstremark.
 
+
*RightMargin (Long): høyremark.
 +
*TopMargin (Long): toppmarg.
 +
*Height (Long): høyde.
 +
*Width (Long): bredde.
 +
*HoriOrient (const): horisontal justering <idl>com.sun.star.text.HoriOrientation</idl>).
 +
*VertOrient (const): vertikal justering (<idl>com.sun.star.text.VertOrientation</idl>).
 +
I eksemplet under lages en slik ramme og stikkes inn.
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
Cursor = ThisComponent.Text.createTextCursor()
Dim TextTables As Object
+
Dim Cursor As Object
+
Dim Frame As Object
+
 
+
Doc = ThisComponent
+
Cursor = Doc.Text.createTextCursor()
+
Frame = Doc.createInstance("com.sun.star.text.TextFrame")
+
Doc.Text.insertTextContent(Cursor, Frame, False)
+
</source>
+
 
+
The text frame is created using the <tt>createInstance</tt> method of the document object. The text frame created in this way can then be inserted in the document using the <tt>insertTextContent</tt> method of the <tt>Text</tt> object. In so doing, the name of the proper <idl>com.sun.star.text.TextFrame</idl> service should be specified.
+
 
+
The text frame's insert position is determined by a <tt>Cursor</tt> object, which is also executed when inserted.
+
 
+
{{Documentation/VBAnote|Text frames are {{OOo}}'s counterpart to the position frame used in Word. Whereas VBA uses the <tt>Document.Frames.Add</tt> method for this purpose, creation in {{OOo}} Basic is performed using the previous procedure with the aid of a <tt>TextCursor</tt> as well as the <tt>createInstance</tt> method of the document object.}}
+
 
+
Text frame objects provide a range of properties with which the position and behavior of the frame can be influenced. The majority of these properties are defined in the <idl>com.sun.star.text.BaseFrameProperties</idl> service, which is also supported by each <tt>TextFrame</tt> service. The central properties are:
+
 
+
;<tt>BackColor (Long)</tt>:background color of the text frame.
+
;<tt>BottomMargin (Long)</tt>:bottom margin in 100ths of a millimeter.
+
;<tt>LeftMargin (Long)</tt>:left margin in 100ths of a millimeter.
+
;<tt>RightMargin (Long)</tt>:right margin in 100ths of a millimeter.
+
;<tt>TopMargin (Long)</tt>:top margin in 100ths of a millimeter.
+
;<tt>Height (Long)</tt>:height of text frame in 100ths of a millimeter.
+
;<tt>Width (Long)</tt>:width of text frame in 100ths of a millimeter.
+
;<tt>HoriOrient (const)</tt>:horizontal orientation of text frame (in accordance with <idl>com.sun.star.text.HoriOrientation</idl>).
+
;<tt>VertOrient (const)</tt>:vertical orientation of text frame (in accordance with <idl>com.sun.star.text.VertOrientation</idl>).
+
 
+
The following example creates a text frame using the properties described previously:
+
 
+
<source lang="oobas">
+
Dim Doc As Object
+
Dim TextTables As Object
+
Dim Cursor As Object
+
Dim Frame As Object
+
 
+
Doc = ThisComponent
+
Cursor = Doc.Text.createTextCursor()
+
 
Cursor.gotoNextWord(False)
 
Cursor.gotoNextWord(False)
Frame = Doc.createInstance("com.sun.star.text.TextFrame")
+
Frame = ThisComponent.createInstance("com.sun.star.text.TextFrame")
  
 
Frame.Width = 3000
 
Frame.Width = 3000
Line 233: Line 145:
 
Doc.Text.insertTextContent(Cursor, Frame, False)
 
Doc.Text.insertTextContent(Cursor, Frame, False)
 
</source>
 
</source>
 +
Merk vekselvirkningen mellom <tt>AnchorType</tt> (fra <tt>TextContent</tt>) og <tt>VertOrient</tt> (fra <tt>BaseFrameProperties</tt>).
 +
Forankringen er  <tt>AS_CHARACTER</tt> så teksten settes inn midt i strømmen av tegn (karakterer). Derfor kan den f.eks. bli flyttet
 +
til neste linje hvis der blir linjeskift.  Med vertikal justering satt til <tt>LINE_TOP</tt> blir rammens topp sidestilt med
 +
tegnenes topp.
  
The example creates a <tt>TextCursor</tt> as the insertion mark for the text frame. This is positioned between the first and second word of the text. The text frame is created using <tt>Doc.createInstance</tt>. The properties of the text frame objects are set to the starting values required.
+
Innholdet i rammen kan endres ved å lage set en cursor:
 
+
The interaction between the <tt>AnchorType</tt> (from the <tt>TextContent</tt> Service) and <tt>VertOrient</tt> (from the <tt>BaseFrameProperties</tt> Service) properties should be noted here. <tt>AnchorType</tt> receives the <tt>AS_CHARACTER</tt> value. The text frame is therefore inserted directly in the text flow and behaves like a character. It can, for example, be moved into the next line if a line break occurs. The <tt>LINE_TOP</tt> value of the <tt>VertOrient</tt> property ensures that the upper edge of the text frame is at the same height as the upper edge of the character.
+
 
+
Once initialization is complete, the text frame is finally inserted in the text document using a call from <tt>insertTextContent</tt>.
+
 
+
To edit the content of a text frame, the user uses the <tt>TextCursor</tt>, which has already been mentioned numerous times and is also available for text frames.
+
 
+
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
 
Dim TextTables As Object
 
Dim Cursor As Object
 
Dim Frame As Object
 
Dim FrameCursor As Object
 
 
 
Doc = ThisComponent
 
Doc = ThisComponent
 
Cursor = Doc.Text.createTextCursor()
 
Cursor = Doc.Text.createTextCursor()
 
Frame = Doc.createInstance("com.sun.star.text.TextFrame")
 
Frame = Doc.createInstance("com.sun.star.text.TextFrame")
 
 
Frame.Width = 3000
 
Frame.Width = 3000
 
Frame.Height = 1000
 
Frame.Height = 1000
 
 
Doc.Text.insertTextContent(Cursor, Frame, False)
 
Doc.Text.insertTextContent(Cursor, Frame, False)
 
 
FrameCursor = Frame.createTextCursor()
 
FrameCursor = Frame.createTextCursor()
 
FrameCursor.charWeight = com.sun.star.awt.FontWeight.BOLD
 
FrameCursor.charWeight = com.sun.star.awt.FontWeight.BOLD
Line 264: Line 164:
 
</source>
 
</source>
  
The example creates a text frame, inserts this in the current document and opens a <tt>TextCursor</tt> for the text frame. This cursor is used to set the frame font to bold type and to set the paragraph orientation to centered. The text frame is finally assigned the “This is a small test!” string.
+
==Tekstfelt==
 
+
Nok et flytende objekt er spesielle felt som kan settes inn etter behov. De kan inneholde dato, sidenummer, forfatter og annet.
== Text Fields ==
+
 
+
Text fields are <tt>TextContent</tt> objects because they provide additional logic extending beyond pure text. Text fields can be inserted in a text document using the same methods as those used for other <tt>TextContent</tt> objects:
+
  
 +
Et datofelt settes inn som under:
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
 
Dim DateTimeField As Object
 
Dim Cursor As Object
 
Doc = ThisComponent
 
Cursor = Doc.Text.createTextCursor()
 
 
 
DateTimeField = Doc.createInstance("com.sun.star.text.textfield.DateTime")
 
DateTimeField = Doc.createInstance("com.sun.star.text.textfield.DateTime")
 
DateTimeField.IsFixed = False
 
DateTimeField.IsFixed = False
Line 283: Line 175:
 
</source>
 
</source>
  
The example inserts a text field with the current date at the start of the current text document. The <tt>True</tt> value of the <tt>IsDate</tt> property results in only the date and not time being displayed. The <tt>False</tt> value for <tt>IsFixed</tt> ensures that the date is automatically updated when the document is opened.
+
En liste med alle dokumentets felt kan gjennomgås som under:
 
+
{{Documentation/VBAnote|While the type of a field in VBA is specified by a parameter of the <tt>Document.Fields.Add</tt> method, the name of the service that is responsible for the field type in question defines it in {{OOo}} Basic.}}
+
 
+
In the past, text fields were accessed using a whole range of methods that {{OOo}} made available in the old <tt>Selection</tt> object (for example <tt>InsertField</tt>, <tt>DeleteUserField</tt>, <tt>SetCurField)</tt>.
+
 
+
In {{OOo}} 2.x, the fields are administered using an object-oriented concept. To create a text field, a text field of the type required should first be created and initialized using the properties required. The text field is then inserted in the document using the <tt>insertTextContent</tt> method. A corresponding source text can be seen in the previous example. The most important field types and their properties are described in the following sections.
+
 
+
In addition to inserting text fields, searching a document for the fields can also be an important task. The following example shows how all text fields of a text document can be traversed in a loop and checked for their relevant type.
+
 
+
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
feltListe = ThisComponent.getTextFields.createEnumeration
Dim TextFieldEnum As Object
+
While feltListe.hasMoreElements()
Dim TextField As Object
+
   felt = TextFieldEnum.nextElement()
Dim I As Integer
+
   If felt.supportsService("com.sun.star.text.textfield.DateTime") Then
 
+
Doc = ThisComponent
+
 
+
TextFieldEnum = Doc.getTextFields.createEnumeration
+
 
+
While TextFieldEnum.hasMoreElements()
+
 
+
   TextField = TextFieldEnum.nextElement()
+
 
+
   If TextField.supportsService("com.sun.star.text.textfield.DateTime") Then
+
 
       MsgBox "Date/time"
 
       MsgBox "Date/time"
   ElseIf TextField.supportsService("com.sun.star.text.textfield.Annotation") Then
+
   ElseIf felt.supportsService("com.sun.star.text.textfield.Annotation") Then
 
       MsgBox "Annotation"
 
       MsgBox "Annotation"
  Else
 
      MsgBox "unknown"
 
 
   End If
 
   End If
 
 
Wend
 
Wend
 
</source>
 
</source>
 +
Gjennomgangen skjer med en iterator og sjekker tekstfeltet for type.
  
The starting point for establishing the text fields present is the <tt>TextFields</tt> list of the document object. The example creates an <tt>Enumeration</tt> object on the basis of this list, with which all text fields can be queried in turn in a loop. The text fields found are checked for the service supported using the <tt>supportsService</tt> method. If the field proves to be a date/time field or an annotation, then the corresponding field type is displayed in an information box. If on the other hand, the example encounters another field, then it displays the information “unknown”.
+
Nummerfelt støtter
 
+
<tt>NumberingType (const)</tt> som i <idl>com.sun.star.style.NumberingType</idl>):
Below, you will find a list of the most important text fields and their associated properties. A complete list of all text fields is provided in the API reference in the <tt>com.sun.star.text.textfield</tt> module. (When listing the service name of a text field, uppercase and lowercase characters should be used in {{OOo}} Basic, as in the previous example.)
+
* <idl>com.sun.star.text.textfield.PageCount</idl> (antall sider)
 
+
* <idl>com.sun.star.text.textfield.WordCount</idl> (antall ord)
=== Number of Pages, Words and Characters ===
+
* <idl>com.sun.star.text.textfield.CharacterCount</idl> (antall tegn)
 
+
* <idl>com.sun.star.text.textfield.PageNumber</idl> (sidenummer)  
The text fields
+
 
+
* <idl>com.sun.star.text.textfield.PageCount</idl>
+
* <idl>com.sun.star.text.textfield.WordCount</idl>
+
* <idl>com.sun.star.text.textfield.CharacterCount</idl>
+
 
+
return the number of pages, words, or characters of a text. They support the following property:
+
 
+
;<tt>NumberingType (const)</tt>:numbering format (guidelines in accordance with constants from <idl>com.sun.star.style.NumberingType</idl> ).
+
 
+
=== Current Page ===
+
 
+
The number of the current page can be inserted in a document using the <idl>com.sun.star.text.textfield.PageNumber</idl> text field. The following properties can be specified:
+
 
+
;<tt>NumberingType (const)</tt>:number format (guidelines in accordance with constants from <idl>com.sun.star.style.NumberingType</idl>).
+
;<tt>Offset (short) </tt>:offset added to the number of pages (negative specification also possible).
+
 
+
The following example shows how the number of pages can be inserted into the footer of a document.
+
  
 +
Under settes slike inn i et dokument:
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
 
Dim DateTimeField As Object
 
Dim PageStyles As Object
 
Dim StdPage As Object
 
Dim FooterCursor As Object
 
Dim PageNumber As Object
 
 
 
Doc = ThisComponent
 
Doc = ThisComponent
 
 
PageNumber = Doc.createInstance("com.sun.star.text.textfield.PageNumber")
 
PageNumber = Doc.createInstance("com.sun.star.text.textfield.PageNumber")
 
PageNumber.NumberingType = com.sun.star.style.NumberingType.ARABIC
 
PageNumber.NumberingType = com.sun.star.style.NumberingType.ARABIC
 
 
PageStyles = Doc.StyleFamilies.getByName("PageStyles")
 
PageStyles = Doc.StyleFamilies.getByName("PageStyles")
 
 
StdPage = PageStyles("Default")
 
StdPage = PageStyles("Default")
 
StdPage.FooterIsOn = True
 
StdPage.FooterIsOn = True
 
 
FooterCursor = StdPage.FooterTextLeft.Text.createTextCursor()
 
FooterCursor = StdPage.FooterTextLeft.Text.createTextCursor()
 
StdPage.FooterTextLeft.Text.insertTextContent(FooterCursor, PageNumber, False)
 
StdPage.FooterTextLeft.Text.insertTextContent(FooterCursor, PageNumber, False)
 
</source>
 
</source>
 +
Først lages et tekstfelt for sidenummer. Så letes "footer" frem (mer om slike
 +
bunntekster annet sted), det ligger i en av stilene, og
 +
tekstfeltet settes inn der.
  
The example first creates a text field which supports the <idl>com.sun.star.text.textfield.PageNumber</idl> service. Since the header and footer lines are defined as part of the page templates of {{OOo}}, this is initially established using the list of all <tt>PageStyles</tt>.
+
Annotering (anmerkninger) vises som et lite gult symbol som kan beklikkes
 +
(<idl>com.sun.star.text.textfield.Annotation</idl>). Egenskaper er:
 +
*Author (String):  Forfatter.
 +
*Content (String):  Tekst.
 +
*Date (Date):  Tidspunkt.
  
To ensure that the footer line is visible, the <tt>FooterIsOn</tt> property is set to <tt>True</tt>. The text field is then inserted in the document using the associated text object of the left-hand footer line.
+
Dato og tid er et felt (<idl>com.sun.star.text.textfield.DateTime</idl>) med*IsFixed (Boolean)</tt>:  hvorvidt verdien skal endres hver gang dokumentet åpnes
 +
*IsDate (Boolean):  hvorvidt feltet skal vise dato (eller tid)
 +
*DateTimeValue (struct):  innhold (<idl>com.sun.star.util.DateTime</idl>)
 +
*NumberFormat(const): visingsformat.
  
=== Annotations ===
+
Kapitelnavn tilbyr et <idl>com.sun.star.text.textfield.Chapter</idl> og har egenskapene
 
+
*ChapterFormat(const): hvordan navn og nummer skal vises (<idl>com.sun.star.text.ChapterFormat</idl>)
Annotation fields (<idl>com.sun.star.text.textfield.Annotation</idl>) can be seen by means of a small yellow symbol in the text. Clicking on this symbol opens a text field, in which a comment on the current point in the text can be recorded. An annotation field has the following properties.
+
*Level (Integer): hvilket kapitelnivå som skal vises (0 er høyeste)
 
+
;<tt>Author (String)</tt>:name of author.
+
;<tt>Content (String)</tt>:comment text.
+
;<tt>Date (Date)</tt>:date on which annotation is written.
+
 
+
=== Date / Time ===
+
 
+
A date / time field (<idl>com.sun.star.text.textfield.DateTime</idl>) represents the current date or the current time. It supports the following properties:
+
 
+
;<tt>IsFixed (Boolean)</tt>:if <tt>True</tt>, the time details of the insertion remain unchanged, if <tt>False</tt>, these are updated each time the document is opened.
+
;<tt>IsDate (Boolean)</tt>:if <tt>True</tt>, the field displays the current date, otherwise the current time.
+
;<tt>DateTimeValue (struct)</tt>:current content of field (<idl>com.sun.star.util.DateTime</idl> structure)
+
;<tt>NumberFormat (const)</tt>:format in which the time or date is depicted.
+
 
+
=== Chapter Name / Number ===
+
 
+
The name of the current chapter is available through a text field of the <idl>com.sun.star.text.textfield.Chapter</idl> type. The form can be defined using two properties.
+
 
+
;<tt>ChapterFormat (const)</tt>:determines whether the chapter name or the chapter number is depicted (in accordance with <idl>com.sun.star.text.ChapterFormat</idl>)
+
;<tt>Level (Integer)</tt>:determines the chapter level whose name and/or chapter number is to be displayed. The value 0 stands for highest level available.
+
 
+
== Bookmarks ==
+
 
+
Bookmarks (Service <idl>com.sun.star.text.Bookmark</idl>) are <tt>TextContent</tt> objects. Bookmarks are created and inserted using the concept already described previously:
+
  
 +
==Bokmerker==
 +
Den siste typen fremmedobjekt er bokmerker(<idl>com.sun.star.text.Bookmark</idl>).
 +
Behandling blir veldig likt de foregående.
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
Bookmark = ThisComponent.createInstance("com.sun.star.text.Bookmark")
Dim Bookmark As Object
+
Bookmark.Name = "mine bokmerker"
Dim Cursor As Object
+
 
+
Doc = ThisComponent
+
 
+
Cursor = Doc.Text.createTextCursor()
+
 
+
Bookmark = Doc.createInstance("com.sun.star.text.Bookmark")
+
Bookmark.Name = "My bookmarks"
+
 
Doc.Text.insertTextContent(Cursor, Bookmark, True)
 
Doc.Text.insertTextContent(Cursor, Bookmark, True)
 
</source>
 
</source>
 
+
Tekstens bokmerker ligger i den navne- og indeksbaserte samlingen <tt>Bookmarks</tt>. T
The example creates a <tt>Cursor</tt>, which marks the insert position of the bookmark and then the actual bookmark object (<tt>Bookmark</tt>). The bookmark is then assigned a name and is inserted in the document through <tt>insertTextContent</tt> at the cursor position.
+
I eksemplet letes et navngitt bokmerker frem og en tekst innsettes.
 
+
The bookmarks of a text are accessed through a list called <tt>Bookmarks</tt>. The bookmarks can either be accessed by their number or their name.
+
 
+
The following example shows how a bookmark can be found within a text, and a text inserted at its position.
+
 
+
 
<source lang="oobas">
 
<source lang="oobas">
Dim Doc As Object
+
Bookmark = ThisDocument.Bookmarks.getByName("mine bokmerker")
Dim Bookmark As Object
+
Cursor = ThisDocument.Text.createTextCursorByRange(Bookmark.Anchor)
Dim Cursor As Object
+
 
+
Doc = ThisComponent
+
 
+
Bookmark = Doc.Bookmarks.getByName("My bookmarks")
+
 
+
Cursor = Doc.Text.createTextCursorByRange(Bookmark.Anchor)
+
 
Cursor.String = "Here is the bookmark"
 
Cursor.String = "Here is the bookmark"
 
</source>
 
</source>
 
In this example, the <tt>getByName</tt> method is used to find the bookmark required by means of its name. The <tt>createTextCursorByRange</tt> call then creates a <tt>Cursor</tt>, which is positioned at the anchor position of the bookmark. The cursor then inserts the text required at this point.
 
 
 
   
 
   
 
{{InterWiki Languages BasicGuide|articletitle=NO/Documentation/BASIC Guide/More Than Text}}
 
{{InterWiki Languages BasicGuide|articletitle=NO/Documentation/BASIC Guide/More Than Text}}
 
{{PDL1}}
 
{{PDL1}}

Latest revision as of 14:10, 16 December 2009


Tekstdokument kan ha mer enn ren tekst i avsnitt. Fremmedobjekt som tabeller, tegninger, tekstfelter og annet kan forankres eller flyte rundt i dokumentet.

TextContent

Forankring styres via tjenesten com.sun.star.text.TextContent som alle objekt støtter. Egenskaper:

Metoder som dokumentet tilbyr:

  • createInstance() lager et nytt objekt som støtter TextContent.
  • insertTextContent() legger et objekt inn i teksten.
  • removeTextContent() fjerner et objekt fra teksten.

Tabeller

Eksemplet viser innsetting av en ny tabell:

Cursor = ThisComponent.Text.createTextCursor()
Kalender = ThisComponent.createInstance("com.sun.star.text.TextTable")
Kalender.initialize(12,31)
ThisComponent.Text.insertTextContent(Cursor, Kalender, False)

En ser at en ved innsetting også skal angi posisjon (cursor) og om det utvalgte skal erstattes (True) eller beholdes (False).

Å vise alle tabeller gjøres som under:

alleTabeller = ThisComponent.getTextTables()
For I = 0 to alleTabeller.count - 1
   tabell = TextTables(I)
   ... 
Next I

Tabeller støtter com.sun.star.text.TextTable og har egenskaper (avstander er i 1/100 mm):

  • BackColor (Long): bakgrunnsfarge.
  • BottomMargin (Long): bunnmarg.
  • LeftMargin (Long): venstremarg.
  • RightMargin (Long): høyremarg.
  • TopMargin (Long): toppmarg.
  • RepeatHeadline (Boolean): True hvis overskrift skal gjentas på hver side.
  • Width (Long): bredde.

Alle rader og kolonner

Tabellen tilbyr getRows og getColumns(). Begge gir en liste som støtter com.sun.star.table.XTableRows. De tilbyr:

  • getByIndex(Integer): enkeltobjekt.
  • getCount(): antallet objekt.
  • insertByIndex(i, n): setter inn i nye objekt fra posisjon n.
  • removeByIndex(i, n): sletter n objekt fra posisjon n.

OBS: insert og remove kun hvis tabellen er fri for "merged cells". Tabellens annenhver rad får ny bakgrunnsfarge som under:

Cursor = ThisComponent.Text.createTextCursor()
tabell = ThisComponent.createInstance("com.sun.star.text.TextTable")
tabell.initialize(5, 4)
ThisComponent.Text.insertTextContent(Cursor, Table, False)
rader = tabell.getRows
For I = 0 To rader.getCount() - 1 Step 2
   rad = rader.getByIndex(I)
   rad.BackColor = &HFF00FF
Next

Enkeltrad

Hver rad støtter com.sun.star.text.TextTableRow service og tilbyr følgende:

  • BackColor (Long): bakgrunnsfarge.
  • Height (Long): høyde.
  • IsAutoHeight (Boolean): om høyde skal autotilpasses.
  • VertOrient (const): vertikal justering (com.sun.star.text.VertOrientation)

Celler

Hver celle har et unikt navn. Cellen "øverst, til venstre" heter vanligvis A1, der A angir kolonne og 1 er rad. Altså har neste kolonne navnet B. En tabell har metoden getCellByName(n). Eksemplet under setter verdien i tabellens celler:

Cursor = ThisComponent.Text.createTextCursor()
tabell = ThisComponent.createInstance("com.sun.star.text.TextTable")
tabell.initialize(5, 4)
ThisComonent.Text.insertTextContent(Cursor, Table, False)
rader = tabell.getRows
kolonner = tabell.getColumns
For rad = 1 To rader.getCount()
   For kol = 1 To kolonner.getCount()
      celleNavn = Chr(Asc("A") - 1 + kol) & rad
      celle = tabell.getCellByName(celleNavn)
      celle.String = "rad: " & CStr(rad) + ", kolonne: " & CStr(kol)
   Next
Next

En celle ligner en vanlig tekst og tilbyr blant annet createTextCursor(). Utseendet i cellen endres som vanlig tekst. I eksemplet under høyre-justeres alle celler med tall.

tabellListe = ThisComponent.getTextTables()
For I = 0 to tabellListe.count - 1
   tabell = tabellListe(I)
   celleNavn = tabell.getCellNames()
   For J = 0 to UBound(celleNavn)
      celle = tabell.getCellByName( celleNavn(J) )
      If IsNumeric( celle.String ) Then
         celleCursor = celle.createTextCursor()
         celleCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
      End If
   Next
Next

Innrammet tekst

Innrammet tekst er også et flytende objekt, som tabeller og bilder, og behandles likt med disse. Den tilbyr com.sun.star.text.BaseFrameProperties og har derved egenskaper som:

  • BackColor (Long): bakgrunnsfarge.
  • BottomMargin (Long): bunnmark.
  • LeftMargin (Long): venstremark.
  • RightMargin (Long): høyremark.
  • TopMargin (Long): toppmarg.
  • Height (Long): høyde.
  • Width (Long): bredde.
  • HoriOrient (const): horisontal justering com.sun.star.text.HoriOrientation).
  • VertOrient (const): vertikal justering (com.sun.star.text.VertOrientation).

I eksemplet under lages en slik ramme og stikkes inn.

Cursor = ThisComponent.Text.createTextCursor()
Cursor.gotoNextWord(False)
Frame = ThisComponent.createInstance("com.sun.star.text.TextFrame")
 
Frame.Width = 3000
Frame.Height = 1000
Frame.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
Frame.TopMargin = 0
Frame.BottomMargin = 0
Frame.LeftMargin = 0
Frame.RightMargin = 0
Frame.BorderDistance = 0
Frame.HoriOrient = com.sun.star.text.HoriOrientation.NONE
Frame.VertOrient = com.sun.star.text.VertOrientation.LINE_TOP
 
Doc.Text.insertTextContent(Cursor, Frame, False)

Merk vekselvirkningen mellom AnchorType (fra TextContent) og VertOrient (fra BaseFrameProperties). Forankringen er AS_CHARACTER så teksten settes inn midt i strømmen av tegn (karakterer). Derfor kan den f.eks. bli flyttet til neste linje hvis der blir linjeskift. Med vertikal justering satt til LINE_TOP blir rammens topp sidestilt med tegnenes topp.

Innholdet i rammen kan endres ved å lage set en cursor:

Doc = ThisComponent
Cursor = Doc.Text.createTextCursor()
Frame = Doc.createInstance("com.sun.star.text.TextFrame")
Frame.Width = 3000
Frame.Height = 1000
Doc.Text.insertTextContent(Cursor, Frame, False)
FrameCursor = Frame.createTextCursor()
FrameCursor.charWeight = com.sun.star.awt.FontWeight.BOLD
FrameCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.CENTER
FrameCursor.String = "This is a small Test!"

Tekstfelt

Nok et flytende objekt er spesielle felt som kan settes inn etter behov. De kan inneholde dato, sidenummer, forfatter og annet.

Et datofelt settes inn som under:

DateTimeField = Doc.createInstance("com.sun.star.text.textfield.DateTime")
DateTimeField.IsFixed = False
DateTimeField.IsDate = True
Doc.Text.insertTextContent(Cursor, DateTimeField, False)

En liste med alle dokumentets felt kan gjennomgås som under:

feltListe = ThisComponent.getTextFields.createEnumeration
While feltListe.hasMoreElements()
   felt = TextFieldEnum.nextElement()
   If felt.supportsService("com.sun.star.text.textfield.DateTime") Then
      MsgBox "Date/time"
   ElseIf felt.supportsService("com.sun.star.text.textfield.Annotation") Then
      MsgBox "Annotation"
   End If
Wend

Gjennomgangen skjer med en iterator og sjekker tekstfeltet for type.

Nummerfelt støtter NumberingType (const) som i com.sun.star.style.NumberingType):

Under settes slike inn i et dokument:

Doc = ThisComponent
PageNumber = Doc.createInstance("com.sun.star.text.textfield.PageNumber")
PageNumber.NumberingType = com.sun.star.style.NumberingType.ARABIC
PageStyles = Doc.StyleFamilies.getByName("PageStyles")
StdPage = PageStyles("Default")
StdPage.FooterIsOn = True
FooterCursor = StdPage.FooterTextLeft.Text.createTextCursor()
StdPage.FooterTextLeft.Text.insertTextContent(FooterCursor, PageNumber, False)

Først lages et tekstfelt for sidenummer. Så letes "footer" frem (mer om slike bunntekster annet sted), det ligger i en av stilene, og tekstfeltet settes inn der.

Annotering (anmerkninger) vises som et lite gult symbol som kan beklikkes (com.sun.star.text.textfield.Annotation). Egenskaper er:

  • Author (String): Forfatter.
  • Content (String): Tekst.
  • Date (Date): Tidspunkt.

Dato og tid er et felt (com.sun.star.text.textfield.DateTime) med*IsFixed (Boolean)</tt>: hvorvidt verdien skal endres hver gang dokumentet åpnes

  • IsDate (Boolean): hvorvidt feltet skal vise dato (eller tid)
  • DateTimeValue (struct): innhold (com.sun.star.util.DateTime)
  • NumberFormat(const): visingsformat.

Kapitelnavn tilbyr et com.sun.star.text.textfield.Chapter og har egenskapene

  • ChapterFormat(const): hvordan navn og nummer skal vises (com.sun.star.text.ChapterFormat)
  • Level (Integer): hvilket kapitelnivå som skal vises (0 er høyeste)

Bokmerker

Den siste typen fremmedobjekt er bokmerker(com.sun.star.text.Bookmark). Behandling blir veldig likt de foregående.

Bookmark = ThisComponent.createInstance("com.sun.star.text.Bookmark")
Bookmark.Name = "mine bokmerker"
Doc.Text.insertTextContent(Cursor, Bookmark, True)

Tekstens bokmerker ligger i den navne- og indeksbaserte samlingen Bookmarks. T I eksemplet letes et navngitt bokmerker frem og en tekst innsettes.

Bookmark = ThisDocument.Bookmarks.getByName("mine bokmerker")
Cursor = ThisDocument.Text.createTextCursorByRange(Bookmark.Anchor)
Cursor.String = "Here is the bookmark"


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools