[Solved] Resultset to Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Rajagopalanta
Posts: 31
Joined: Tue Jan 27, 2009 4:23 pm

[Solved] Resultset to Calc

Post 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.
Last edited by Rajagopalanta on Wed Oct 28, 2009 4:46 pm, edited 1 time in total.
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Resultset to Calc

Post 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).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Rajagopalanta
Posts: 31
Joined: Tue Jan 27, 2009 4:23 pm

Re: Resultset to Calc

Post 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
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [SOLVED] Resultset to Calc

Post by Villeroy »

You should understand the application before hacking on it: [Tutorial] Using registered datasources in Calc
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply