| View previous topic :: View next topic |
| Author |
Message |
washington General User

Joined: 14 Jul 2003 Posts: 13 Location: Duisburg, Germany
|
Posted: Tue Aug 12, 2003 11:00 pm Post subject: Fill table in textdocument |
|
|
Hello,
how can I fill a table in a textdocument with data from database ?
Thanks.
Greetings
Carsten |
|
| Back to top |
|
 |
openmind OOo Enthusiast


Joined: 28 Jun 2003 Posts: 106 Location: Switzerland
|
|
| Back to top |
|
 |
washington General User

Joined: 14 Jul 2003 Posts: 13 Location: Duisburg, Germany
|
Posted: Wed Aug 13, 2003 3:59 am Post subject: Fill table in textdocument |
|
|
Dear friend,
I don't want to create an own table.
I got a finished template (textdocument with a table), and now should I fill these template with data.
At this position
| Code: | | oTextTable.getCellByPosition(1,0).String = oDBResult.getString( 1 ) |
I got the com.sun.star.lang.IndexOutOfBoundsException. |
|
| Back to top |
|
 |
Mario M Guest
|
Posted: Wed Aug 13, 2003 4:06 am Post subject: show us more code |
|
|
show us more code
we love code
COOOODEEEEE |
|
| Back to top |
|
 |
washington General User

Joined: 14 Jul 2003 Posts: 13 Location: Duisburg, Germany
|
Posted: Wed Aug 13, 2003 4:52 am Post subject: Fill table in textdocument |
|
|
You love code, you got code (essence of program):
| Code: | Global oDesktop As Object
Global oDocument As Object
Global oText As Object
Global oDialog as Object
Dim Statement As Object
Dim ResultSet As Object
Dim Doc As Object
Sub FillDocument
Dim sheet as Object
Dim cell as Object
REM *** Open database connection ***
DataSource = DatabaseContext.getByName("regendb")
If Not DataSource.IsPasswordRequired Then
Connection = DataSource.GetConnection("","")
Else
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
Connection = DataSource.ConnectWithCompletion(InteractionHandler)
End If
REM *** Access to database ***
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("select FIRST 30 fb_id, name1, strasse, plz, ort,_
lage from sicadi.a_druckanschrift where fb_id = " & oListBox.getSelectedItem())
REM *** Open template with text, bookmarks and table ***
oDesktop = createUnoService("com.sun.star.frame.Desktop")
sUrl = "file:///C:/Erinnerung_Wuppertal.stw" '"private:factory/swriter"
oDocument = _
oDesktop.loadComponentFromURL(sUrl,"_blank",0,mNoArgs)
REM *** Fill document with life ***
If Not IsNull(ResultSet) Then
While (ResultSet.next)
For i = 1 To 1 'Step -1
REM *** Activ document ***
Doc = StarDesktop.CurrentComponent
REM *** Attempt to fill table
oText = Doc.Text
' get a text cursor
oTextCursor = oText.createTextCursor()
oTextCursor.gotoStart( FALSE )
sMySQLString = ResultSet.getString(i)
oTextTable = Doc.createInstance( "com.sun.star.text.TextTable" )
oTextTable.initialize( 2,2 )
oText.insertString( oTextCursor, oDBResult.getString( 2 ) , FALSE )
oText.insertTextContent( oTextCursor, oTextTable, FALSE)
oTextTable.getCellByPosition(1,0).String = oDBResult.getString( 1 )
oTextTable.getCellByPosition(1,1).String = oDBResult.getString( 2 )
REM *** Fill Bookmark
Bookmark = Doc.Bookmarks.getByName("FB_ID1")
Cursor = Doc.Text.createTextCursorByRange(Bookmark.Anchor)
Cursor.String = sMySQLString
Next i
Wend
End If
End Sub |
|
|
| Back to top |
|
 |
Mario M General User


Joined: 13 Aug 2003 Posts: 10 Location: Dresden, Germany
|
Posted: Wed Aug 13, 2003 5:24 am Post subject: Re: Fill table in textdocument |
|
|
well actually Im not firm in this Basic language thing but where does the var 'oDBResult' come from? I cant find any allocation in your code... and the other rhing is: dont u have to qoute the fieldnames in the sql-query? like:
| Code: | | select FIRST 30 "fb_id", "name1", "strasse", "plz, ort,_lage" from "sicadi.a_druckanschrift" where "fb_id" = |
in delphi and java you have to - well surely u have to escape the quotationmarks (\)
as I said I dont know much about Basic - just some hints... |
|
| Back to top |
|
 |
openmind OOo Enthusiast


Joined: 28 Jun 2003 Posts: 106 Location: Switzerland
|
|
| Back to top |
|
 |
|