osheet-xmlss 1.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/Gemfile +9 -0
- data/LICENSE +22 -0
- data/README.md +131 -0
- data/Rakefile +49 -0
- data/bench/bench_runner.rb +91 -0
- data/bench/profiler.rb +6 -0
- data/bench/profiler_1000.xls +17015 -0
- data/bench/profiler_runner.rb +40 -0
- data/examples/basic.rb +77 -0
- data/examples/basic.xls +2 -0
- data/examples/basic_with_templates.rb +87 -0
- data/examples/basic_with_templates.xls +93 -0
- data/examples/formats.rb +370 -0
- data/examples/formats.xls +768 -0
- data/examples/formula.rb +42 -0
- data/examples/formula.xls +36 -0
- data/examples/styles.rb +255 -0
- data/examples/styles.xls +343 -0
- data/examples/trivial.rb +25 -0
- data/examples/trivial.xls +18 -0
- data/lib/osheet/xmlss/style_cache.rb +63 -0
- data/lib/osheet/xmlss/style_settings.rb +148 -0
- data/lib/osheet/xmlss/version.rb +4 -0
- data/lib/osheet/xmlss.rb +7 -0
- data/lib/osheet/xmlss_writer.rb +143 -0
- data/osheet-xmlss.gemspec +24 -0
- data/test/helper.rb +17 -0
- data/test/irb.rb +9 -0
- data/test/xmlss/api_test.rb +139 -0
- data/test/xmlss/style_cache_test.rb +65 -0
- data/test/xmlss/style_settings_test.rb +263 -0
- data/test/xmlss/styles_test.rb +340 -0
- data/test/xmlss_writer_test.rb +92 -0
- metadata +157 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ruby-prof'
|
2
|
+
require 'osheet/xmlss'
|
3
|
+
|
4
|
+
class OsheetXmlssProfilerRunner
|
5
|
+
|
6
|
+
attr_reader :result
|
7
|
+
|
8
|
+
def initialize(n)
|
9
|
+
|
10
|
+
RubyProf.measure_mode = RubyProf::MEMORY
|
11
|
+
@result = RubyProf.profile do
|
12
|
+
Osheet::Workbook.new {
|
13
|
+
title "basic"
|
14
|
+
worksheet {
|
15
|
+
name "one dollar"
|
16
|
+
5.times { column }
|
17
|
+
|
18
|
+
1000.times do
|
19
|
+
row {
|
20
|
+
[1, "text", 123.45, "0001267", "$45.23"].each do |data_value|
|
21
|
+
cell { data data_value }
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
}
|
26
|
+
}.to_file('./bench/profiler_1000.xls', :pp => 2)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def print_flat(outstream, opts={})
|
32
|
+
RubyProf::FlatPrinter.new(@result).print(outstream, opts)
|
33
|
+
#RubyProf::GraphPrinter.new(@result).print(outstream, opts)
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_graph(outstream, opts={})
|
37
|
+
RubyProf::GraphPrinter.new(@result).print(outstream, opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# To run:
|
2
|
+
# $ bundle install
|
3
|
+
# $ bundle exec ruby examples/basic.rb
|
4
|
+
# $ open examples/basic.xls
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'osheet/xmlss'
|
8
|
+
|
9
|
+
fields = ['Sex', 'Age', 'Height', 'Weight']
|
10
|
+
data = {
|
11
|
+
'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
|
12
|
+
'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
|
13
|
+
'Sally' => ['F', 29, "5'3\"", '132 lbs.']
|
14
|
+
}
|
15
|
+
|
16
|
+
# this will dump the above data to a single-sheet workbook w/ no styles
|
17
|
+
|
18
|
+
puts "building examples/basic.rb ..."
|
19
|
+
|
20
|
+
Osheet::Workbook.new(Osheet::XmlssWriter.new) {
|
21
|
+
title "basic"
|
22
|
+
worksheet {
|
23
|
+
name "Stats: #{fields.join(', ')}"
|
24
|
+
|
25
|
+
column {
|
26
|
+
width 200
|
27
|
+
meta(
|
28
|
+
:label => "Name"
|
29
|
+
)
|
30
|
+
}
|
31
|
+
fields.each_with_index do |f, i|
|
32
|
+
column {
|
33
|
+
width 80
|
34
|
+
meta(
|
35
|
+
:label => f.to_s,
|
36
|
+
:index => i
|
37
|
+
)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
row { # title row
|
42
|
+
cell {
|
43
|
+
colspan columns.count
|
44
|
+
data worksheet.name
|
45
|
+
}
|
46
|
+
}
|
47
|
+
row { # empty row
|
48
|
+
cell {
|
49
|
+
colspan columns.count
|
50
|
+
data ''
|
51
|
+
}
|
52
|
+
}
|
53
|
+
row { # header row
|
54
|
+
columns.each do |column|
|
55
|
+
cell {
|
56
|
+
data column.meta[:label]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
data.each do |name, stats|
|
62
|
+
row { # data row
|
63
|
+
cell {
|
64
|
+
data name
|
65
|
+
}
|
66
|
+
stats.each do |stat|
|
67
|
+
cell {
|
68
|
+
data stat
|
69
|
+
}
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
}
|
74
|
+
}.to_file('examples/basic.xls')
|
75
|
+
|
76
|
+
puts "open examples/basic.xls"
|
77
|
+
|
data/examples/basic.xls
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"><Styles></Styles><Worksheet ss:Name="Stats Sex, Age, Height, Weight"><Table><Column ss:Width="200" /><Column ss:Width="80" /><Column ss:Width="80" /><Column ss:Width="80" /><Column ss:Width="80" /><Row><Cell ss:MergeAcross="4"><Data ss:Type="String">Stats: Sex, Age, Height, Weight</Data></Cell></Row><Row><Cell ss:MergeAcross="4"><Data ss:Type="String"></Data></Cell></Row><Row><Cell><Data ss:Type="String">Name</Data></Cell><Cell><Data ss:Type="String">Sex</Data></Cell><Cell><Data ss:Type="String">Age</Data></Cell><Cell><Data ss:Type="String">Height</Data></Cell><Cell><Data ss:Type="String">Weight</Data></Cell></Row><Row><Cell><Data ss:Type="String">Sally</Data></Cell><Cell><Data ss:Type="String">F</Data></Cell><Cell><Data ss:Type="Number">29</Data></Cell><Cell><Data ss:Type="String">5'3"</Data></Cell><Cell><Data ss:Type="String">132 lbs.</Data></Cell></Row><Row><Cell><Data ss:Type="String">Dick</Data></Cell><Cell><Data ss:Type="String">M</Data></Cell><Cell><Data ss:Type="Number">33</Data></Cell><Cell><Data ss:Type="String">6'5"</Data></Cell><Cell><Data ss:Type="String">243 lbs.</Data></Cell></Row><Row><Cell><Data ss:Type="String">Tom</Data></Cell><Cell><Data ss:Type="String">M</Data></Cell><Cell><Data ss:Type="Number">52</Data></Cell><Cell><Data ss:Type="String">6'2"</Data></Cell><Cell><Data ss:Type="String">220 lbs.</Data></Cell></Row></Table></Worksheet></Workbook>
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# To run:
|
2
|
+
# $ bundle install
|
3
|
+
# $ bundle exec ruby examples/basic_with_templates.rb
|
4
|
+
# $ open examples/basic_with_templates.xls
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'osheet/xmlss'
|
8
|
+
|
9
|
+
fields = ['Sex', 'Age', 'Height', 'Weight']
|
10
|
+
data = {
|
11
|
+
'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
|
12
|
+
'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
|
13
|
+
'Sally' => ['F', 29, "5'3\"", '132 lbs.']
|
14
|
+
}
|
15
|
+
|
16
|
+
# this will dump the above data to a single-sheet workbook w/ no styles
|
17
|
+
|
18
|
+
puts "building examples/basic_with_templats.rb ..."
|
19
|
+
|
20
|
+
Osheet::Workbook.new(Osheet::XmlssWriter.new(:pp => 2)) {
|
21
|
+
title "basic"
|
22
|
+
|
23
|
+
template(:column, :data) { |field, index|
|
24
|
+
width 80
|
25
|
+
meta(
|
26
|
+
:label => field.to_s,
|
27
|
+
:index => index
|
28
|
+
)
|
29
|
+
}
|
30
|
+
|
31
|
+
template(:row, :title) {
|
32
|
+
cell {
|
33
|
+
colspan columns.count
|
34
|
+
data worksheet.name
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
template(:row, :empty) {
|
39
|
+
cell {
|
40
|
+
colspan columns.count
|
41
|
+
data ''
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
template(:row, :header) {
|
46
|
+
columns.each do |column|
|
47
|
+
cell {
|
48
|
+
data column.meta[:label]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
}
|
52
|
+
|
53
|
+
template(:row, :data) { |name, stats|
|
54
|
+
cell {
|
55
|
+
data name
|
56
|
+
}
|
57
|
+
stats.each do |stat|
|
58
|
+
cell {
|
59
|
+
data stat
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
|
64
|
+
worksheet {
|
65
|
+
name "Stats: #{fields.join(', ')}"
|
66
|
+
|
67
|
+
column {
|
68
|
+
width 200
|
69
|
+
meta(
|
70
|
+
:label => "Name"
|
71
|
+
)
|
72
|
+
}
|
73
|
+
fields.each_with_index do |f, i|
|
74
|
+
column :data, f, i
|
75
|
+
end
|
76
|
+
|
77
|
+
row :title
|
78
|
+
row :empty
|
79
|
+
row :header
|
80
|
+
|
81
|
+
data.each do |name, stats|
|
82
|
+
row :data, name, stats
|
83
|
+
end
|
84
|
+
}
|
85
|
+
}.to_file('examples/basic_with_templates.xls')
|
86
|
+
|
87
|
+
puts "open examples/basic_with_templates.xls"
|
@@ -0,0 +1,93 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
3
|
+
<Styles>
|
4
|
+
|
5
|
+
</Styles>
|
6
|
+
<Worksheet ss:Name="Stats Sex, Age, Height, Weight">
|
7
|
+
<Table>
|
8
|
+
<Column ss:Width="200" />
|
9
|
+
<Column ss:Width="80" />
|
10
|
+
<Column ss:Width="80" />
|
11
|
+
<Column ss:Width="80" />
|
12
|
+
<Column ss:Width="80" />
|
13
|
+
<Row>
|
14
|
+
<Cell ss:MergeAcross="4">
|
15
|
+
<Data ss:Type="String">Stats: Sex, Age, Height, Weight</Data>
|
16
|
+
</Cell>
|
17
|
+
</Row>
|
18
|
+
<Row>
|
19
|
+
<Cell ss:MergeAcross="4">
|
20
|
+
<Data ss:Type="String"></Data>
|
21
|
+
</Cell>
|
22
|
+
</Row>
|
23
|
+
<Row>
|
24
|
+
<Cell>
|
25
|
+
<Data ss:Type="String">Name</Data>
|
26
|
+
</Cell>
|
27
|
+
<Cell>
|
28
|
+
<Data ss:Type="String">Sex</Data>
|
29
|
+
</Cell>
|
30
|
+
<Cell>
|
31
|
+
<Data ss:Type="String">Age</Data>
|
32
|
+
</Cell>
|
33
|
+
<Cell>
|
34
|
+
<Data ss:Type="String">Height</Data>
|
35
|
+
</Cell>
|
36
|
+
<Cell>
|
37
|
+
<Data ss:Type="String">Weight</Data>
|
38
|
+
</Cell>
|
39
|
+
</Row>
|
40
|
+
<Row>
|
41
|
+
<Cell>
|
42
|
+
<Data ss:Type="String">Sally</Data>
|
43
|
+
</Cell>
|
44
|
+
<Cell>
|
45
|
+
<Data ss:Type="String">F</Data>
|
46
|
+
</Cell>
|
47
|
+
<Cell>
|
48
|
+
<Data ss:Type="Number">29</Data>
|
49
|
+
</Cell>
|
50
|
+
<Cell>
|
51
|
+
<Data ss:Type="String">5'3"</Data>
|
52
|
+
</Cell>
|
53
|
+
<Cell>
|
54
|
+
<Data ss:Type="String">132 lbs.</Data>
|
55
|
+
</Cell>
|
56
|
+
</Row>
|
57
|
+
<Row>
|
58
|
+
<Cell>
|
59
|
+
<Data ss:Type="String">Dick</Data>
|
60
|
+
</Cell>
|
61
|
+
<Cell>
|
62
|
+
<Data ss:Type="String">M</Data>
|
63
|
+
</Cell>
|
64
|
+
<Cell>
|
65
|
+
<Data ss:Type="Number">33</Data>
|
66
|
+
</Cell>
|
67
|
+
<Cell>
|
68
|
+
<Data ss:Type="String">6'5"</Data>
|
69
|
+
</Cell>
|
70
|
+
<Cell>
|
71
|
+
<Data ss:Type="String">243 lbs.</Data>
|
72
|
+
</Cell>
|
73
|
+
</Row>
|
74
|
+
<Row>
|
75
|
+
<Cell>
|
76
|
+
<Data ss:Type="String">Tom</Data>
|
77
|
+
</Cell>
|
78
|
+
<Cell>
|
79
|
+
<Data ss:Type="String">M</Data>
|
80
|
+
</Cell>
|
81
|
+
<Cell>
|
82
|
+
<Data ss:Type="Number">52</Data>
|
83
|
+
</Cell>
|
84
|
+
<Cell>
|
85
|
+
<Data ss:Type="String">6'2"</Data>
|
86
|
+
</Cell>
|
87
|
+
<Cell>
|
88
|
+
<Data ss:Type="String">220 lbs.</Data>
|
89
|
+
</Cell>
|
90
|
+
</Row>
|
91
|
+
</Table>
|
92
|
+
</Worksheet>
|
93
|
+
</Workbook>
|
data/examples/formats.rb
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
# To run:
|
2
|
+
# $ bundle install
|
3
|
+
# $ bundle exec ruby examples/formats.rb
|
4
|
+
# $ open examples/formats.xls
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'osheet/xmlss'
|
8
|
+
|
9
|
+
puts "building examples/formats.rb ..."
|
10
|
+
|
11
|
+
Osheet::Workbook.new(Osheet::XmlssWriter.new(:pp => 2)) {
|
12
|
+
title "formats"
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
# number format examples
|
17
|
+
worksheet {
|
18
|
+
name "number"
|
19
|
+
|
20
|
+
column {
|
21
|
+
width 250
|
22
|
+
meta(:label => 'Format')
|
23
|
+
}
|
24
|
+
[1000, -20000].each do |n|
|
25
|
+
column {
|
26
|
+
width 125
|
27
|
+
meta(:label => n.to_s, :value => n)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# header row
|
32
|
+
row {
|
33
|
+
columns.each do |col|
|
34
|
+
cell{ data col.meta[:label] }
|
35
|
+
end
|
36
|
+
}
|
37
|
+
|
38
|
+
# data rows
|
39
|
+
[
|
40
|
+
{},
|
41
|
+
{
|
42
|
+
:decimal_places => 1,
|
43
|
+
:negative_numbers => :red
|
44
|
+
},
|
45
|
+
{
|
46
|
+
:decimal_places => 2,
|
47
|
+
:comma_separator => true,
|
48
|
+
:negative_numbers => :black_parenth
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:decimal_places => 8,
|
52
|
+
:comma_separator => true,
|
53
|
+
:negative_numbers => :red_parenth
|
54
|
+
}
|
55
|
+
].each do |opts|
|
56
|
+
row {
|
57
|
+
cell {
|
58
|
+
data Osheet::Format.new(:number, opts).key
|
59
|
+
}
|
60
|
+
columns[1..-1].each do |col|
|
61
|
+
cell {
|
62
|
+
data col.meta[:value]
|
63
|
+
format :number, opts
|
64
|
+
}
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
# currency/accounting format examples
|
72
|
+
worksheet {
|
73
|
+
name "currency, accounting"
|
74
|
+
|
75
|
+
column {
|
76
|
+
width 250
|
77
|
+
meta(:label => 'Format')
|
78
|
+
}
|
79
|
+
[1000, -20000].each do |n|
|
80
|
+
column {
|
81
|
+
width 125
|
82
|
+
meta(:label => n.to_s, :value => n)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
# header row
|
87
|
+
row {
|
88
|
+
columns.each do |col|
|
89
|
+
cell{ data col.meta[:label] }
|
90
|
+
end
|
91
|
+
}
|
92
|
+
|
93
|
+
data_opts = [
|
94
|
+
{},
|
95
|
+
{
|
96
|
+
:symbol => :euro,
|
97
|
+
:decimal_places => 0,
|
98
|
+
:negative_numbers => :red
|
99
|
+
},
|
100
|
+
{
|
101
|
+
:decimal_places => 1,
|
102
|
+
:comma_separator => false,
|
103
|
+
:negative_numbers => :black_parenth
|
104
|
+
},
|
105
|
+
{
|
106
|
+
:decimal_places => 8,
|
107
|
+
:comma_separator => true,
|
108
|
+
:negative_numbers => :red_parenth
|
109
|
+
}
|
110
|
+
]
|
111
|
+
|
112
|
+
# currency data rows
|
113
|
+
data_opts.each do |opts|
|
114
|
+
row {
|
115
|
+
cell {
|
116
|
+
data Osheet::Format.new(:currency, opts).key
|
117
|
+
}
|
118
|
+
columns[1..-1].each do |col|
|
119
|
+
cell {
|
120
|
+
data col.meta[:value]
|
121
|
+
format :currency, opts
|
122
|
+
}
|
123
|
+
end
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
# accounting data rows
|
128
|
+
data_opts.each do |opts|
|
129
|
+
row {
|
130
|
+
cell {
|
131
|
+
data Osheet::Format.new(:accounting, opts).key
|
132
|
+
}
|
133
|
+
columns[1..-1].each do |col|
|
134
|
+
cell {
|
135
|
+
data col.meta[:value]
|
136
|
+
format :accounting, opts
|
137
|
+
}
|
138
|
+
end
|
139
|
+
}
|
140
|
+
end
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# percentage format examples
|
146
|
+
worksheet {
|
147
|
+
name "percentage, scientific"
|
148
|
+
|
149
|
+
column {
|
150
|
+
width 250
|
151
|
+
meta(:label => 'Format')
|
152
|
+
}
|
153
|
+
[1000, -20000].each do |n|
|
154
|
+
column {
|
155
|
+
width 125
|
156
|
+
meta(:label => n.to_s, :value => n)
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
# header row
|
161
|
+
row {
|
162
|
+
columns.each do |col|
|
163
|
+
cell{ data col.meta[:label] }
|
164
|
+
end
|
165
|
+
}
|
166
|
+
|
167
|
+
data_opts = [
|
168
|
+
{},
|
169
|
+
{
|
170
|
+
:decimal_places => 0,
|
171
|
+
:negative_numbers => :red
|
172
|
+
},
|
173
|
+
{
|
174
|
+
:decimal_places => 1,
|
175
|
+
:comma_separator => false,
|
176
|
+
:negative_numbers => :black_parenth
|
177
|
+
},
|
178
|
+
{
|
179
|
+
:decimal_places => 8,
|
180
|
+
:comma_separator => true,
|
181
|
+
:negative_numbers => :red_parenth
|
182
|
+
}
|
183
|
+
]
|
184
|
+
|
185
|
+
# percentage data rows
|
186
|
+
data_opts.each do |opts|
|
187
|
+
row {
|
188
|
+
cell {
|
189
|
+
data Osheet::Format.new(:percentage, opts).key
|
190
|
+
}
|
191
|
+
columns[1..-1].each do |col|
|
192
|
+
cell {
|
193
|
+
data col.meta[:value]
|
194
|
+
format :percentage, opts
|
195
|
+
}
|
196
|
+
end
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
# scientific data rows
|
201
|
+
data_opts.each do |opts|
|
202
|
+
row {
|
203
|
+
cell {
|
204
|
+
data Osheet::Format.new(:scientific, opts).key
|
205
|
+
}
|
206
|
+
columns[1..-1].each do |col|
|
207
|
+
cell {
|
208
|
+
data col.meta[:value]
|
209
|
+
format :scientific, opts
|
210
|
+
}
|
211
|
+
end
|
212
|
+
}
|
213
|
+
end
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
# fraction format examples
|
219
|
+
worksheet {
|
220
|
+
name "fractions"
|
221
|
+
|
222
|
+
column {
|
223
|
+
width 250
|
224
|
+
meta(:label => 'Format')
|
225
|
+
}
|
226
|
+
column {
|
227
|
+
width 125
|
228
|
+
meta(:label => 'Fraction Example')
|
229
|
+
}
|
230
|
+
|
231
|
+
# header row
|
232
|
+
row {
|
233
|
+
columns.each do |col|
|
234
|
+
cell{ data col.meta[:label] }
|
235
|
+
end
|
236
|
+
}
|
237
|
+
|
238
|
+
# fraction data rows
|
239
|
+
data_opts = {
|
240
|
+
:one_digit => 0.5,
|
241
|
+
:two_digits => 0.0125,
|
242
|
+
:three_digits => 0.01,
|
243
|
+
:halves => 0.5,
|
244
|
+
:quarters => 0.25,
|
245
|
+
:eighths => 0.125,
|
246
|
+
:sixteenths => 0.0625,
|
247
|
+
:tenths => 0.1,
|
248
|
+
:hundredths => 0.01
|
249
|
+
}
|
250
|
+
data_opts.each do |k,v|
|
251
|
+
row {
|
252
|
+
cell {
|
253
|
+
data Osheet::Format.new(:fraction, :type => k).key
|
254
|
+
}
|
255
|
+
cell {
|
256
|
+
data v
|
257
|
+
format :fraction, :type => k
|
258
|
+
}
|
259
|
+
}
|
260
|
+
end
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
# text format examples
|
266
|
+
worksheet {
|
267
|
+
name "text, special, custom"
|
268
|
+
|
269
|
+
column {
|
270
|
+
width 250
|
271
|
+
meta(:label => 'Format')
|
272
|
+
}
|
273
|
+
column {
|
274
|
+
width 125
|
275
|
+
meta(:label => 'Result')
|
276
|
+
}
|
277
|
+
|
278
|
+
# header row
|
279
|
+
row {
|
280
|
+
columns.each do |col|
|
281
|
+
cell{ data col.meta[:label] }
|
282
|
+
end
|
283
|
+
}
|
284
|
+
|
285
|
+
# text data row
|
286
|
+
row {
|
287
|
+
cell {
|
288
|
+
data Osheet::Format.new(:text).key
|
289
|
+
}
|
290
|
+
cell {
|
291
|
+
data "001122 blah blah"
|
292
|
+
format :text
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
# special data rows
|
297
|
+
{
|
298
|
+
:zip_code => 12345,
|
299
|
+
:zip_code_plus_4 => 123456789,
|
300
|
+
:phone_number => 5551112222,
|
301
|
+
:social_security_number => 333224444
|
302
|
+
}.each do |k,v|
|
303
|
+
row {
|
304
|
+
cell {
|
305
|
+
data Osheet::Format.new(:special, :type => k).key
|
306
|
+
}
|
307
|
+
cell {
|
308
|
+
data v
|
309
|
+
format :special, :type => k
|
310
|
+
}
|
311
|
+
}
|
312
|
+
end
|
313
|
+
|
314
|
+
# custom data row
|
315
|
+
row {
|
316
|
+
cell {
|
317
|
+
data Osheet::Format.new(:custom, '@').key
|
318
|
+
}
|
319
|
+
cell {
|
320
|
+
data "001122 blah blah"
|
321
|
+
format :custom, '@'
|
322
|
+
}
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
# datetime format examples
|
329
|
+
worksheet {
|
330
|
+
name "date, time"
|
331
|
+
|
332
|
+
column {
|
333
|
+
width 250
|
334
|
+
meta(:label => 'Format')
|
335
|
+
}
|
336
|
+
column {
|
337
|
+
width 125
|
338
|
+
meta(:label => 'Datetime')
|
339
|
+
}
|
340
|
+
|
341
|
+
# header row
|
342
|
+
row {
|
343
|
+
columns.each do |col|
|
344
|
+
cell{ data col.meta[:label] }
|
345
|
+
end
|
346
|
+
}
|
347
|
+
|
348
|
+
# datetime data row
|
349
|
+
[ 'm','d','y', 'mm', 'dd', 'yy', 'yyyy',
|
350
|
+
'mm/dd/yy', 'mm/dd/yyyy', 'mmmm', 'mmmmm', 'mmmmm',
|
351
|
+
'h','m','s', 'hh', 'mm', 'ss',
|
352
|
+
'h:mm:ss', 'h:mm:ss.0', 'hh:mm:ss AM/PM'
|
353
|
+
].each do |s|
|
354
|
+
row {
|
355
|
+
cell {
|
356
|
+
data Osheet::Format.new(:datetime, s).key
|
357
|
+
}
|
358
|
+
cell {
|
359
|
+
data Date.today
|
360
|
+
format :datetime, s
|
361
|
+
}
|
362
|
+
}
|
363
|
+
end
|
364
|
+
}
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
}.to_file('examples/formats.xls')
|
369
|
+
|
370
|
+
puts "open examples/formats.xls"
|