Skip to content

Instantly share code, notes, and snippets.

@milligramme
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save milligramme/bf736637378c719cd23a to your computer and use it in GitHub Desktop.

Select an option

Save milligramme/bf736637378c719cd23a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require "spreadsheet"
xls = Spreadsheet::Workbook.new
sheet = xls.create_worksheet :name => "spreadsheet.gem color sample"
colors = [
:aqua,
:black,
:blue,
:cyan,
:brown,
:fuchsia,
:gray,
:grey,
:green,
:lime,
:magenta,
:navy,
:orange,
:purple,
:red,
:silver,
:white,
:yellow,
:xls_color_0,
:xls_color_1,
:xls_color_2,
:xls_color_3,
:xls_color_4,
:xls_color_5,
:xls_color_6,
:xls_color_7,
:xls_color_8,
:xls_color_9,
:xls_color_10,
:xls_color_11,
:xls_color_12,
:xls_color_13,
:xls_color_14,
:xls_color_15,
:xls_color_16,
:xls_color_17,
:xls_color_18,
:xls_color_19,
:xls_color_20,
:xls_color_21,
:xls_color_22,
:xls_color_23,
:xls_color_24,
:xls_color_25,
:xls_color_26,
:xls_color_27,
:xls_color_28,
:xls_color_29,
:xls_color_30,
:xls_color_31,
:xls_color_32,
:xls_color_33,
:xls_color_34,
:xls_color_35,
:xls_color_36,
:xls_color_37,
:xls_color_38,
:xls_color_39,
:xls_color_40,
:xls_color_41,
:xls_color_42,
:xls_color_43,
:xls_color_44,
:xls_color_45,
:xls_color_46,
:xls_color_47,
:xls_color_48,
:xls_color_49,
:xls_color_50,
:xls_color_51,
:xls_color_52,
:xls_color_53,
:xls_color_54,
:xls_color_55
]
format = {
border: :thin,
border_color: :black,
color: :black,
weight: :bold,
size: 12
}
colors.each_with_index do |r, i|
sheet[i, 0] = r.to_s
sheet[i, 1] = r.to_s
sheet.row(i).set_format 0, Spreadsheet::Format.new(
format.merge({
pattern: 1,
pattern_fg_color: r
})
)
sheet.row(i).set_format 1, Spreadsheet::Format.new(
format.merge({
pattern: 1,
pattern_fg_color: r,
color: :white
})
)
sheet.row(i).height = 24
[30,30].each_with_index do |v, j|
sheet.column(j).width = v
end
end
xls_out_path = File.join File.dirname(__FILE__), "#{File.basename(__FILE__, '.*')}.xls"
xls.write(xls_out_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment