-
Notifications
You must be signed in to change notification settings - Fork 44
/
kitchen_sink_test.rb
110 lines (95 loc) · 2.85 KB
/
kitchen_sink_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require "test_helper"
class KitchenSinkTest < ActiveSupport::TestCase
def setup
@options = {
headers: [
['Latest Posts'],
['Title','Category','Author','Posted on','Posted At','Earnings']
],
data: 50.times.map{|i| [i, "foobar-#{i}", 5.4*i, true, Date.today, Time.now]},
header_style: {background_color: "000000", color: "FFFFFF", align: :center, font_size: 12, bold: true},
row_style: {background_color: nil, color: "000000", align: :left, font_size: 12},
sheet_name: 'Kitchen Sink',
freeze_headers: true,
}
end
def teardown
end
def test_xlsx
opts = @options.merge({
column_styles: [
{columns: 0, styles: {bold: true}},
{columns: (1..3), styles: {color: "444444"}},
{columns: [4], include_header: false, styles: {italic: true}}
],
range_styles: [
{range: "B2:C4", styles: {background_color: "CCCCCC"}},
{range: {rows: 1, columns: :all}, styles: {bold: true}},
{range: {rows: (20..25), columns: (1..4)}, styles: {italic: true}},
{range: {rows: :all, columns: (3..4)}, styles: {color: "999999"}}
],
conditional_row_styles: [
{
if: Proc.new{|row_data, row_index|
row_index == 0 || row_data[0].to_i == 2
},
styles: {font_size: 18}
},
{
unless: Proc.new{|row_data, row_index|
row_index <= 10 || row_data[0].to_i == 15
},
styles: {align: :right}
},
],
borders: [
{range: "B2:C4"},
{range: "D6:D7", border_styles: {style: :dashDot, color: "333333"}},
{range: {rows: (2..11), columns: :all}, border_styles: {edges: [:top,:bottom]}},
{range: {rows: 3, columns: 4}, border_styles: {edges: [:top,:bottom]}}
],
merges: [
{range: "A1:C1"},
{range: {rows: 2, columns: :all}},
{range: {rows: (3..4), columns: (0..3)}}
],
column_types: [
:integer,
:string,
:float,
:boolean,
:date,
:time,
nil,
],
})
# Using Array Data
file_data = SpreadsheetArchitect.to_xlsx(opts)
File.open(VERSIONED_BASE_PATH.join("kitchen_sink.xlsx"),'w+b') do |f|
f.write file_data
end
end
def test_ods
opts = @options.merge({
headers: [
['Latest Posts'],
['Title','Category','Author','Boolean','Posted on','Posted At']
],
data: 50.times.map{|i| [i, "foobar-#{i}", (5.4*i), true, Date.today, Time.now]},
column_types: [
:string,
:float,
:float,
:boolean,
:date,
:time,
nil
],
})
# Using Array Data
file_data = SpreadsheetArchitect.to_ods(opts)
File.open(VERSIONED_BASE_PATH.join("kitchen_sink.ods"),'w+b') do |f|
f.write file_data
end
end
end