表格的读取

2015-06-30 0 390
表格的读取
# from table to CSV
require 'odbc'
require 'dbi'
filename = "./file.csv"
writeFile = File.open(filename,"w")
dbh = DBI.connect('DBI:ODBC:data_source_name', 'username', 'password')
sth = dbh.prepare("SELECT * FROM table WITH UR")
sth.execute
writeFile.puts sth.column_names.join(" ; ") #puts names on the top of each row
while row=sth.fetch do
	writeFile.puts row.join(" ; ") #puts lines from table
end
sth.finish
dbh.disconnect
writeFile.close

# from csv to excel
require 'win32ole'
xl = WIN32OLE.new('excel.application')
xl.workbooks.open(File.expand_path(filename))
xl.visible = true

遇见资源网 ruby 表格的读取 http://www.ox520.com/16416.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务