excel的简单操作

ruby操作EXCEL的简单示例

require 'win32ole'

excel = WIN32OLE.new("excel.application")

workbook = excel.Workbooks.Open('D:/test1.xls')

worksheet = workbook.Worksheets("test1")

worksheet.Select

row = worksheet.usedrange.rows.count

column = worksheet.usedrange.columns.count

worksheet.usedrange.each{|cell|

puts cell.value

}

for i in 1..row do

for j in 1..column do

puts worksheet.usedrange.cells(i,j).value

end

end

workbook.close

excel.Quit

你可能感兴趣的:(excel的简单操作)