Created
October 16, 2013 19:32
-
-
Save zaid/7013447 to your computer and use it in GitHub Desktop.
A small script which generates a file that does not show any columns when opened with Microsoft Excel 2010 unless you highlight all and select the unhide option.
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
title = "Some report" | |
selected_columns = %w(one two three four five) | |
Axlsx::Package.new do |package| | |
package.workbook do |workbook| | |
# Disabling this will improve performance for very large documents | |
workbook.use_autowidth = false | |
workbook.add_worksheet(:name => 'Data') do |sheet| | |
unless title.blank? | |
title_format = sheet.styles.add_style({:b => true, :sz => 18}) | |
sheet.add_row([title], :style => title_format) | |
sheet.add_row | |
end | |
# => Create the headers from the selected columns | |
header_format = sheet.styles.add_style({:b => true, :alignment => {:horizontal => :center}, :bg_color => "FFDFDEDF"}) | |
headers = selected_columns.select { |column| !column.blank? }.map { |column| column.gsub('-', ' ').titleize } | |
sheet.add_row(headers, :style => header_format) | |
row_format = sheet.styles.add_style({:alignment => {:horizontal => :left}}) | |
sheet.add_row([1, 2, 3, 4, 5], :style => row_format) | |
end | |
end | |
package.serialize("Test_file.xlsx") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment