Skip to content

Instantly share code, notes, and snippets.

@kieran
Created March 26, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kieran/0b2835874b806b42195915ee72d754d3 to your computer and use it in GitHub Desktop.
Save kieran/0b2835874b806b42195915ee72d754d3 to your computer and use it in GitHub Desktop.
#
# XLS helpers
#
def xls_header
<<~EOF
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table>
EOF
end
def xls_footer
<<~EOF
</Table>
</Worksheet>
</Workbook>
EOF
end
def xls_start_row
"\n <Row>"
end
def xls_end_row
"\n </Row>"
end
def xls_cell(data)
"\n <Cell><Data ss:Type=\"#{xls_type(data)}\">#{CGI.escapeHTML(data.to_s)}</Data></Cell>"
end
def xls_type(data)
if /\A\d[\d.]*\z/ =~ data
'Number'
else
'String'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment