Add some more sheets : Excel « Windows Platform « Ruby






Add some more sheets


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

 








Related examples in the same category

1.Using WIN32OLE with Excel
2.Create a chart in Excel
3.Create a chart and rotate it
4.Set cell value and read it back