Created
March 26, 2019 04:05
-
-
Save kieran/0b2835874b806b42195915ee72d754d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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