Sha256: 4339f922d7d1ea8b65aaf17db5defa3ef20984c8bccbc145c651871f50cb0f27

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

# To run:
# $ bundle install
# $ bundle exec ruby examples/basic.rb
# $ open examples/basic.xls

require 'rubygems'
require 'osheet'

fields = ['Sex', 'Age', 'Height', 'Weight']
data = {
  'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
  'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
  'Sally' => ['F', 29, "5'3\"", '132 lbs.']
}

# this will dump the above data to a single-sheet workbook w/ no styles


Osheet::Workbook.new {
  title "basic"
  worksheet {
    name "Stats: #{fields.join(', ')}"

    column {
      width 200
      meta(
        :label => "Name"
      )
    }
    fields.each_with_index do |f, i|
      column {
        width 80
        meta(
          :label => f.to_s,
          :index => i
        )
      }
    end

    row {     # title row
      cell {
        colspan columns.count
        data worksheet.name
      }
    }
    row {     # empty row
      cell {
        colspan columns.count
        data ''
      }
    }
    row {     # header row
      columns.each do |column|
        cell {
          data column.meta[:label]
        }
      end
    }

    data.each do |name, stats|
      row {   # data row
        cell {
          data name
        }
        stats.each do |stat|
          cell {
            data stat
          }
        end
      }
    end
  }
}.to_file('examples/basic.xls')

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
osheet-0.9.2 examples/basic.rb
osheet-0.9.1 examples/basic.rb
osheet-0.9.0 examples/basic.rb
osheet-0.8.0 examples/basic.rb
osheet-0.7.0 examples/basic.rb
osheet-0.6.0 examples/basic.rb
osheet-0.5.0 examples/basic.rb
osheet-0.4.0 examples/basic.rb
osheet-0.3.0 examples/basic.rb
osheet-0.2.0 examples/basic.rb