Question

I would like to query my DB and take the results and export them into either a .txt, .cvs or .xls

The mysql database is not hosted on my local machine

here is my code to access the DB and return the results in on the screen:

 #!/usr/bin/ruby
 require 'mysql'
 require 'watir'
 require "win32ole"

 excel = WIN32OLE::new('excel.Application')
 workbook = excel.Workbooks.Add
 worksheet = workbook.Worksheets(1)

 mysql = Mysql.init()
 mysql.connect(host='hostname', user='username', passwd='pwd', db='DBname')

 results = mysql.query("Select * FROM table") 
 results.each{|row|; puts row;}
 mysql.close()

 worksheet.SaveAs("C:\\Scripts\\DB_Test\\Test.xlsx") 
 workbook.Close

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top