Class: Pangrid::ExcelXSLX
Constant Summary collapse
- STYLES =
styles
{ :black => {:bg_color => "00"}, :white => { :bg_color => "FF", :fg_color => "00", :alignment => { :horizontal=> :right }, :border => Axlsx::STYLE_THIN_BORDER } }
- SUPERSCRIPTS =
cobble a cell number together out of unicode superscript chars
%w(⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹)
Constants inherited from Plugin
Plugin::FAILED, Plugin::MISSING_DEPS, Plugin::REGISTRY
Instance Method Summary collapse
Methods inherited from Plugin
class_to_name, get, inherited, list_all, load_all, load_plugin
Methods included from PluginUtils
Instance Method Details
#format_number(n) ⇒ Object
27 28 29 |
# File 'lib/pangrid/plugins/excel.rb', line 27 def format_number(n) n.to_s.split(//).map {|c| SUPERSCRIPTS[c.to_i]}.join("").rjust(3) end |
#write(xw) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pangrid/plugins/excel.rb', line 31 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 |