zoukankan      html  css  js  c++  java
  • ruby导出exl方式

    class Demo
    print "hello world"
    
    require "spreadsheet"  
    #设置表格的编码为utf-8  
    Spreadsheet.client_encoding="utf-8"  
    #创建表格对象  
    book=Spreadsheet::Workbook.new  
    
    #创建工作表  
    sheet1=book.create_worksheet :name => "test1"  
    
    #定义一个样式
    format=Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 20
    
    #修改样式
    #sheet1.row(0).set_format(0,format)  #第一行第一列单元格设置样式
    sheet1.row(0).set_format(1,format)   #第一行第二列单元格设置样式
    #sheet1.row(1).set_format(0,format)  #第一行第二列单元格设置样式
    
    #sheet1.row(1).default_format=format  #第一行所有单元格设置样式
    
    #在表格第一行设置分类
    sheet1.row(0)[0]="姓名" 
    sheet1.row(0)[1]="爱好" 
    sheet1.row(0)[2]="国家"  
    5.times do |i|  
        #sheet1.row(i).set_format(0,format)  #前5行的 第一列全部设置样式
        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"
    
    print "#{Dir.pwd}"  #当前文件夹的路径
    
    end

    运行方式
    cmd进入文件位置 ruby demo.rb
    首先要安装插件
    Spreadsheet
    ruby install spreadsheet



    class Demoprint "hello world"
    require "spreadsheet"  #设置表格的编码为utf-8  Spreadsheet.client_encoding="utf-8"  #创建表格对象  book=Spreadsheet::Workbook.new  
    #创建工作表  sheet1=book.create_worksheet :name => "test1"  
    #定义一个样式format=Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 20
    #修改样式#sheet1.row(0).set_format(0,format)  #第一行第一列单元格设置样式sheet1.row(0).set_format(1,format)   #第一行第二列单元格设置样式#sheet1.row(1).set_format(0,format)  #第一行第二列单元格设置样式
    #sheet1.row(1).default_format=format  #第一行所有单元格设置样式
    #在表格第一行设置分类sheet1.row(0)[0]="姓名" sheet1.row(0)[1]="爱好" sheet1.row(0)[2]="国家"  5.times do |i|      #sheet1.row(i).set_format(0,format)  #前5行的 第一列全部设置样式    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"
    print "#{Dir.pwd}"  #当前文件夹的路径
    end

  • 相关阅读:
    uCOS的软件定时器、uCOS时钟节拍和滴答定时器的关系
    学习ucosii要用到的几本书
    freertos知识点笔记——队列、二值信号量、计数信号量
    《嵌入式软件设计基础——基于ARM Cortex—M3》读书笔记
    大小端测试C实现
    static 的三个作用
    基于IAR6或者IAR7建立STM32开发工程(通过实际测试,使用IAR6.30.4)
    STM32中stm32f0xx_flash.icf文件的作用详解!(不错的!)
    CRC点滴
    int *a[] 与(int *)a【5】的区别
  • 原文地址:https://www.cnblogs.com/lmg-jie/p/7735855.html
Copyright © 2011-2022 走看看