#encoding:utf-8 require "spreadsheet/excel" Spreadsheet.client_encoding="utf-8" book=Spreadsheet::Workbook.new sheet1=book.create_worksheet :name => "test1" sheet1.row(0)[0]="姓名" sheet1.row(0)[1]="爱好" sheet1.row(0)[2]="国家" 5.times do |i| sheet1.row(i+1)[0]="张山#{i}" sheet1.row(i+1)[1]="爱好#{i}" sheet1.row(i+1)[2]="国家#{i}" end #在指定路径下面创建test1.xls表格,并写book对象 book.write "test1.xls"