美文网首页
Ruby表格操作之-spreadsheet

Ruby表格操作之-spreadsheet

作者: 肖旭晖 | 来源:发表于2020-02-10 16:20 被阅读0次
    1. 安装SpreadSheet插件
    gem  install spreadsheet
    
    1. 检查是否安装 gem list spreadsheet
    gem list spreadsheet 
    

    这里显示安装的版本,表示安装成功

    3.编写代码

    #encoding:utf-8
    require "spreadsheet/excel"
    #设置表格的编码为utf-8
    Spreadsheet.client_encoding="utf-8"
    #创建表格对象
    book=Spreadsheet::Workbook.new
    puts book
    #创建工作表
    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 "#{Dir.pwd}/../../public/test1.xls"
    book.write "/Users/yashino/Documents/RubyTable/test1.xls"
    
    # /Users/yashino/Documents/RubyTable
    

    https://www.jianshu.com/p/9e1e1db83f6d

    gem install creek

    gem install rubyXL

    ruby下的excel库
    http://www.bubuko.com/infodetail-3220100.html

    相关文章

      网友评论

          本文标题:Ruby表格操作之-spreadsheet

          本文链接:https://www.haomeiwen.com/subject/zugaxhtx.html