I am using the following macro to copy my OOBase table to Calc. However, only the last entry shows up in the spreadsheet. Could you please help me fix the code so that all 90+ entries are copied to Calc? Many thanks in advance!
Code: Select all
Sub drukuj_spis
Dim DatabaseContext as Object
Dim Datasource As Object
Dim Connecticus As Object
Dim Stm as Object
Dim Resultset as object
'Establish connection to Cities DB
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
Datasource = DatabaseContext.getByName("Kartoteki")
Connection = Datasource.GetConnection("","")
'Perform query
Stm = Connection.createStatement()
Resultset = Stm.executeQuery("SELECT * FROM Table1")
Dim sheet as Object
Dim cell as Object
Dim A as Integer
sheet = thisComponent.currentSelection.getSpreadsheet()
If Not IsNull(ResultSet) Then
A = 0
While ResultSet.next
cell = sheet.getCellByPosition( 0, 1 )
cell.String = ResultSet.GetString(1)
cell = sheet.getCellByPosition( 1, 1 )
cell.String = ResultSet.GetString(2)
cell = sheet.getCellByPosition( 2, 1 )
cell.String = ResultSet.GetString(3)
cell = sheet.getCellByPosition( 3, 1 )
cell.String = ResultSet.GetString(4)
cell = sheet.getCellByPosition( 4, 1 )
cell.String = ResultSet.GetString(5)
cell = sheet.getCellByPosition( 5, 1 )
cell.String = ResultSet.GetString(6)
cell = sheet.getCellByPosition( 6, 1 )
cell.String = ResultSet.GetString(7)
cell = sheet.getCellByPosition( 7, 1 )
cell.String = ResultSet.GetString(8)
cell = sheet.getCellByPosition( 8, 1 )
cell.String = ResultSet.GetString(9)
cell = sheet.getCellByPosition( 9, 1 )
cell.String = ResultSet.GetString(10)
cell = sheet.getCellByPosition( 10, 1 )
cell.String = ResultSet.GetString(11)
A = A + 1
Wend
End If
End Sub