MySQL Forums
Forum List  »  Newbie

Re: Export mySQL to Excel
Posted by: Jay Alverson
Date: October 31, 2008 08:13AM

I think so, there are two methods: (that I'm familiar with)

1) export MySQL data using the OUTFILE, then import into Excel using a QUERYTABLE to read in the data.

2) use ADO to open a recordset from MySQL and then use Excel's .CopyFromRecordset() to place the data directly into Excel.

I think #2 is probably the way you want to go, especially if you know how to use the Excel object model.

If you go into the Excel VBA Help file look at the CopyFromRecordset Method:

Copies the contents of an ADO or DAO Recordset object onto a worksheet, beginning at the upper-left corner of the specified range. If the Recordset object contains fields with OLE objects in them, this method fails.

Example
This example copies the field names from a DAO Recordset object into the first row of a worksheet and formats the names as bold. The example then copies the recordset onto the worksheet, beginning at cell A2.

For iCols = 0 to rs.Fields.Count - 1
ws.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
Next
ws.Range(ws.Cells(1, 1), _
ws.Cells(1, rs.Fields.Count)).Font.Bold = True
ws.Range("A2").CopyFromRecordset rs


You can setup a DSN-less connection to MySQL using ADO, it's pretty simple. I can probably put together an example later today using VBSCript which should be pretty close to what you need.


>

Thanks, Jay

Options: ReplyQuote


Subject
Written By
Posted
October 31, 2008 03:48AM
Re: Export mySQL to Excel
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
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.