class Pangrid::ExcelXSLX
Constants
- DESCRIPTION
- STYLES
styles
- SUPERSCRIPTS
cobble a cell number together out of unicode superscript chars
Public Instance Methods
format_number(n)
click to toggle source
# File lib/pangrid/plugins/excel.rb, line 30 def format_number(n) n.to_s.split(//).map {|c| SUPERSCRIPTS[c.to_i]}.join("").rjust(3) end
write(xw)
click to toggle source
# File lib/pangrid/plugins/excel.rb, line 34 def write(xw) xw.number rows = xw.to_array(:black => " ", :null => " ") {|c| format_number(c.number) + " " + # We can insert the entire word for rebuses c.solution } styles = xw.to_array(:black => :black, :null => :white) { :white } p = Axlsx::Package.new wb = p.workbook # styles wb.styles do |s| xstyles = {} STYLES.map {|k, v| xstyles[k] = s.add_style v} wb.add_worksheet(:name => "Crossword") do |sheet| rowstyles = styles.map {|r| r.map {|c| xstyles[c]} } rows.zip(rowstyles).each {|r, s| sheet.add_row r, :style => s } end end out = p.to_stream(true) check("Spreadsheet did not validate") { out } out.read end