Ruby Excel 文件操作之添加 Sheet

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'win32ole'

excel = WIN32OLE.new("excel.application")
excel['Visible'] = true
workbook = excel.Workbooks.Add(1)
worksheet= workbook.Worksheets("Sheet1")
worksheet.name="Ruby Greetings"
worksheet.Cells(1, 1)['Value']='Hello Ruby Fans'
worksheet.Cells(1, 1).Font['Bold']=true
worksheet.Cells(1, 1).font['size']=18

for name in ['dog', 'cat', 'rabbit', 'bird']
   worksheet = workbook.Worksheets.Add
   worksheet.name=name
   for row in 2..6
      for col in 2..10
         worksheet.Cells(row, col)['Value']="(#{row}, #{col})"
      end
   end
   for col in 2..10
        worksheet.Columns(col).AutoFit
   end
end