Page 1 of 1

[Solved] Resultset to Calc

Posted: Tue Oct 20, 2009 9:15 am
by Rajagopalanta
Hi All,

This forum is really good, and I'm really learning a lot and saving lot of time.

I got rows of data from a database into a ResultSet. Now, what is the quickest way to display it in Calc... I used loop through every row and column to display it in calc... But its taking more time, even when the data gets slightly bigger. I need to display it quickly.

Here is my earlier code :

Code: Select all

i = 2
	r = 1

	Do While Result.next()
		for i = 1 to totalcols
 			'  Result set in 1 based index and columns are 0 based
			output_qcsheet.getcellbyposition(i-1,r).setString(Result.getString(i))  
		next i
		r = r +1
	Loop
I use oStatement.ExecuteQuery() to get the Resultset.

Re: Resultset to Calc

Posted: Tue Oct 20, 2009 10:24 am
by Villeroy
Let Calc do the job. Create an import range and define its import descriptor. This one does more than you want, but you get the idea: [Calc] Import by parameters in cells.
You don't need to know the final size of the import range This one creates a single-cell range which expands when filled with import data:

Code: Select all

area = ThisComponent.Sheets.getByName("ImportSheet").getCellRangByName("A4")
ThisComponent.DatabaseRanges.addNewByName("MyImport",area)
Then create the import descriptor as an array of property values. It is possible to specify an SQL-statement, a query name or table name. The import range is refreshable. If you want to remove the link keeping the data, simply remove the database range (only the named thing not the range itself).

Re: Resultset to Calc

Posted: Wed Oct 28, 2009 4:45 pm
by Rajagopalanta
Thanks villeroy, this looks promising.

But, Its is going over my head... I will take sometime later to look into it deeper.

- Raja

Re: [SOLVED] Resultset to Calc

Posted: Wed Oct 28, 2009 5:23 pm
by Villeroy
You should understand the application before hacking on it: [Tutorial] Using registered datasources in Calc