Browse Source

Selecting the sheet in xlsx actually works now.

dev
Andy Meneely 12 years ago
parent
commit
d4daeb5625
  1. 2
      lib/squib/api/data.rb
  2. 7
      samples/excel.rb
  3. BIN
      samples/sample.xlsx

2
lib/squib/api/data.rb

@ -9,7 +9,7 @@ module Squib
def xlsx(file: 'deck.xlsx', sheet: 0) def xlsx(file: 'deck.xlsx', sheet: 0)
s = Roo::Excelx.new(file) s = Roo::Excelx.new(file)
s.default_sheet = s.sheets.first s.default_sheet = s.sheets[sheet]
data = {} data = {}
s.first_column.upto(s.last_column) do |col| s.first_column.upto(s.last_column) do |col|
header = s.cell(s.first_row,col).to_s header = s.cell(s.first_row,col).to_s

7
samples/excel.rb

@ -4,12 +4,17 @@ require 'squib'
Squib::Deck.new(width: 825, height: 1125, cards: 3) do Squib::Deck.new(width: 825, height: 1125, cards: 3) do
background color: :white background color: :white
data = xlsx file: 'sample.xlsx', sheet: 0 # Takes the first sheet by default
# Outputs a hash of arrays with the header names as keys
data = xlsx file: 'sample.xlsx'
text str: data['Name'], x: 250, y: 55, font: 'Arial 54' text str: data['Name'], x: 250, y: 55, font: 'Arial 54'
text str: data['Level'], x: 65, y: 65, font: 'Arial 72' text str: data['Level'], x: 65, y: 65, font: 'Arial 72'
text str: data['Description'], x: 65, y: 600, font: 'Arial 36' text str: data['Description'], x: 65, y: 600, font: 'Arial 36'
# You can also specify the sheet, starting at 0
data = xlsx file: 'sample.xlsx', sheet: 2
save format: :png, prefix: 'sample_excel_' save format: :png, prefix: 'sample_excel_'
end end

BIN
samples/sample.xlsx

Binary file not shown.
Loading…
Cancel
Save