Jump to content

Write Mysql Output to Excel Spread Sheet


Recommended Posts

I am running a mysql query that pulls down dates and department. I would like to output this into a excel file how ever I can't seem to get each rows to separate. I would like to have Departments in one row and Dates in another row. Thanks in advance. ;)

Example of output: 04/26/201404/26/201404/26/201404/26/201404/26/201404/26/201404/26/201404/26/201404/26/2014

Func ComputerModel()
$SQLInstance5 = _MySQLConnect($UserName, $Password, $Database, $MySQLServerName)
$Model = ""
$Model2 = ""
$NametoFind3 = GUICtrlRead($Userid) ;This pulls from the gui
$RemoteFormatString4 = "SELECT * FROM accountinfo WHERE fields_15 BETWEEN '04/26/2014' AND '04/31/2014';"
$SQLCode5 = StringFormat($RemoteFormatString4, $NametoFind3)
$TableContents5 = _Query($SQLInstance5, $SQLCode5)
With $TableContents5
  While Not .EOF
   $Model &= .Fields("fields_15").value
  $Model2 &= .Fields("Department").value
   .MoveNext
  WEnd
EndWith
;Write Excel
    Local $oExcel = _ExcelBookNew()
Local $aArray[5][2] = [[$Model, 1],[$Model2, 2],["big_daddy", 3],["DaleHolm", 4],["GaryFrost", 5]] ;0-Base Array
    _ExcelWriteSheetFromArray($oExcel, $aArray, 1, 1, 0, 0) ;0-Base Array parameters
_MySQLEnd($SQLInstance5)
EndFunc   ;==>ComputerModel
Edited by JamesDover
Link to comment
Share on other sites

This is what is wrong:

While Not .EOF
   $Model &= .Fields("fields_15").value
   $Model2 &= .Fields("Department").value
   .MoveNext
  WEnd

Instead if it try:

Dim $Model[1][2]
  $i=0
  While Not .EOF
   $Model[$i][0] = .Fields("fields_15").value
   $Model[$i][1] = .Fields("Department").value
   .MoveNext
   $i = $i+1
   Redim $Model[$i+1][2]
  WEnd
_arraydisplay($Model)
Edited by Juvigy
Link to comment
Share on other sites

That worked great thanks. I now have a problem with the mysql date query. The format of the database is mm-dd-yyyy not the default YYYY-MM-DD format. So when it filters it. It puts the same year togather but this will be a question for mysql.

James

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...