Monday

Create SQL INSERT from Excel file (ruby script)

import excel file into SQL.
first row is column names.


require 'win32ole'
xl = WIN32OLE.connect('Excel.Application')
wb = xl.ActiveWorkbook
wb.Worksheets.each do |ws|
data = ws.UsedRange.Value
if data!=nil
field_names = data.shift
flds=field_names.join(',')
data.each do |row|
row.collect! { |f| f = "'" + f.to_s + "'" }
puts ("INSERT INTO [#{ws.Name}] (#{flds}) VALUES \
( #{row.join(',')} );")

end
end
end

As alternative there is app that can convert Excel into SQL witn CREATE TABLE and INSERT statements

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...