MySQL Forums
Forum List  »  Newbie

Re: Export mySQL to Excel
Posted by: Jay Alverson
Date: November 01, 2008 02:18PM

Headers are simple just adjust for ADO's zero-based .field subscripts and Excel's need for 1-based column subscripts...



' login to the test db and select all records, then place headers + data into Excel...
dim MySQLConn, sqlstr, MySQLRS
Set MySQLConn = CreateObject("ADODB.Connection")
MySQLConn.open = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=test;UID=Winbatch;PWD=WBTPassword;OPTION=35;"
sqlstr = "SELECT * FROM testtable;"
Set MySQLRS = CreateObject("ADODB.Recordset")
MySQLRS.open sqlstr, MySQLConn, 1,4,1

dim Excel
Set Excel = CreateObject("Excel.Application")
Excel.visible = True
Excel.Workbooks.Add
dim i
' .Cells(column, row) convention, by ADO recordset uses 0-based versus excel's
' 1-based subscripts...
for i = 0 to MySQLRS.fields.count-1
Excel.Workbooks(1).Worksheets(1).Cells(i+1, 1).value = MySQLRS.fields(i).name
next

Excel.Workbooks(1).Worksheets(1).Range("A2").CopyFromRecordset MySQLRS


MySQLConn.close() ' close the connection
Set MySQLConn = Nothing




>

Thanks, Jay

Options: ReplyQuote


Subject
Written By
Posted
October 31, 2008 03:48AM
October 31, 2008 08:13AM
November 19, 2008 10:58AM
November 19, 2008 12:16PM
November 19, 2008 12:40PM
November 19, 2008 03:38PM
November 20, 2008 04:07PM
November 20, 2008 04:22PM
December 02, 2008 04:47PM
December 02, 2008 09:19PM
December 03, 2008 10:00AM
December 03, 2008 11:13AM
December 14, 2008 10:19PM
October 31, 2008 08:35AM
November 01, 2008 05:01AM
November 01, 2008 07:39AM
Re: Export mySQL to Excel
November 01, 2008 02:18PM
November 02, 2008 12:09AM
November 02, 2008 07:00AM
November 02, 2008 08:59AM
November 02, 2008 10:57AM
November 02, 2008 12:44PM
November 03, 2008 09:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.