export mysql results to file using Ruby
-
12-11-2019 - |
문제
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
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow