Skip to content

Instantly share code, notes, and snippets.

@crabtw
Last active December 15, 2015 18:29
Show Gist options
  • Select an option

  • Save crabtw/5303930 to your computer and use it in GitHub Desktop.

Select an option

Save crabtw/5303930 to your computer and use it in GitHub Desktop.
require 'write_xlsx'
x = [[
['aaa', 'In Progress', '2013/4/15', 'High'],
['456', 'Done, New'],
['789', 'Done, New'],
]]
wb = WriteXLSX.new('report.xlsx')
ws = wb.add_worksheet
strike = wb.add_format :font_strikeout => true
red = wb.add_format :color => 'red'
fmt = wb.add_format(
:font => 'Times New Roman',
:align => 'center',
:valign => 'vcenter',
:border => 1
)
x.each_with_index do |job, row|
task, *subtasks = job
desc = ["\n"]
subtasks.each_with_index do |st, n|
name, stat = st
desc << strike if stat =~ /done/i
desc << n + 1
desc << ". "
desc << red if stat =~ /new/i
desc << name
desc << "\n"
end
name, status, eta, prio = task
[row + 1, name, status, '', eta, prio].each_with_index do |cell, col|
ws.write row, col, cell, fmt
end
ws.write_rich_string row, 3, *desc, fmt
end
wb.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment