Sha256: f93ae2588098b0efc17ce282af47ee18ee219f1b6ca5199f869f609af2dc4ff8

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

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

require 'rubygems'
require 'osheet/xmlss'

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

puts "building examples/basic_with_templats.rb ..."

Osheet::Workbook.new(Osheet::XmlssWriter.new(:pp => 2)) {
  title "basic"

  template(:column, :data) { |field, index|
    width 80
    meta(
      :label => field.to_s,
      :index => index
    )
  }

  template(:row, :title) {
    cell {
      colspan columns.count
      data worksheet.name
    }
  }

  template(:row, :empty) {
    cell {
      colspan columns.count
      data ''
    }
  }

  template(:row, :header) {
    columns.each do |column|
      cell {
        data column.meta[:label]
      }
    end
  }

  template(:row, :data) { |name, stats|
    cell {
      data name
    }
    stats.each do |stat|
      cell {
        data stat
      }
    end
  }

  worksheet {
    name "Stats: #{fields.join(', ')}"

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

    row :title
    row :empty
    row :header

    data.each do |name, stats|
      row :data, name, stats
    end
  }
}.to_file('examples/basic_with_templates.xls')

puts "open examples/basic_with_templates.xls"

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
osheet-xmlss-1.0.1 examples/basic_with_templates.rb
osheet-xmlss-1.0.0 examples/basic_with_templates.rb
osheet-xmlss-1.0.0.rc.3 examples/basic_with_templates.rb
osheet-xmlss-1.0.0.rc.2 examples/basic_with_templates.rb
osheet-xmlss-1.0.0.rc.1 examples/basic_with_templates.rb