osheet 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +16 -15
- data/README.rdoc +1 -1
- data/Rakefile +25 -0
- data/bench/profiler.rb +6 -0
- data/bench/profiler_1000.xls +17015 -0
- data/bench/profiler_runner.rb +39 -0
- data/examples/basic.rb +5 -1
- data/examples/basic.xls +1 -0
- data/examples/basic_with_templates.rb +4 -1
- data/examples/basic_with_templates.xls +93 -0
- data/examples/formats.rb +5 -1
- data/examples/formats.xls +768 -0
- data/examples/formula.rb +7 -3
- data/examples/formula.xls +36 -0
- data/examples/styles.rb +5 -1
- data/examples/styles.xls +343 -0
- data/examples/trivial.rb +5 -1
- data/examples/trivial.xls +18 -0
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/xmlss_writer/base.rb +27 -30
- data/lib/osheet/xmlss_writer/elements.rb +28 -42
- data/lib/osheet/xmlss_writer/styles.rb +59 -28
- data/osheet.gemspec +4 -4
- data/test/helper.rb +9 -0
- data/test/xmlss_writer/base_test.rb +14 -12
- data/test/xmlss_writer/elements_test.rb +110 -111
- data/test/xmlss_writer/styles_test.rb +202 -98
- metadata +23 -14
data/examples/formula.rb
CHANGED
@@ -9,6 +9,8 @@ require 'osheet'
|
|
9
9
|
|
10
10
|
# this will dump the above data to a single-sheet workbook w/ no styles
|
11
11
|
|
12
|
+
puts "building examples/formula.rb ..."
|
13
|
+
|
12
14
|
Osheet::Workbook.new {
|
13
15
|
title "formula example"
|
14
16
|
worksheet {
|
@@ -27,13 +29,15 @@ Osheet::Workbook.new {
|
|
27
29
|
row {
|
28
30
|
cell { data 3 }
|
29
31
|
cell { data 4 }
|
30
|
-
cell {
|
32
|
+
cell {
|
31
33
|
# you can still refer to cells in other sheets through the name of the sheet and !
|
32
34
|
# this is also a relative reference, ie. =Formula!A1+B2
|
33
35
|
formula "=Formula!RC[-2]+RC[-1]"
|
34
36
|
# 6 will change into 5 when formula gets recalculated
|
35
37
|
data 6
|
36
|
-
}
|
38
|
+
}
|
37
39
|
}
|
38
40
|
}
|
39
|
-
}.to_file('examples/formula.xls')
|
41
|
+
}.to_file('examples/formula.xls', :pp => 2)
|
42
|
+
|
43
|
+
puts "open examples/formula.xls"
|
@@ -0,0 +1,36 @@
|
|
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="Formula">
|
7
|
+
<Table>
|
8
|
+
<Row>
|
9
|
+
<Cell>
|
10
|
+
<Data ss:Type="Number">1</Data>
|
11
|
+
</Cell>
|
12
|
+
<Cell>
|
13
|
+
<Data ss:Type="Number">2</Data>
|
14
|
+
</Cell>
|
15
|
+
<Cell ss:Formula="=R1C1+R1C2">
|
16
|
+
<Data ss:Type="String"></Data>
|
17
|
+
</Cell>
|
18
|
+
</Row>
|
19
|
+
</Table>
|
20
|
+
</Worksheet>
|
21
|
+
<Worksheet ss:Name="Refers to previous sheet">
|
22
|
+
<Table>
|
23
|
+
<Row>
|
24
|
+
<Cell>
|
25
|
+
<Data ss:Type="Number">3</Data>
|
26
|
+
</Cell>
|
27
|
+
<Cell>
|
28
|
+
<Data ss:Type="Number">4</Data>
|
29
|
+
</Cell>
|
30
|
+
<Cell ss:Formula="=Formula!RC[-2]+RC[-1]">
|
31
|
+
<Data ss:Type="Number">6</Data>
|
32
|
+
</Cell>
|
33
|
+
</Row>
|
34
|
+
</Table>
|
35
|
+
</Worksheet>
|
36
|
+
</Workbook>
|
data/examples/styles.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'osheet'
|
8
8
|
|
9
|
+
puts "building examples/styles.rb ..."
|
10
|
+
|
9
11
|
Osheet::Workbook.new {
|
10
12
|
title "styles"
|
11
13
|
template(:cell, :styled) { |style, attribute|
|
@@ -248,4 +250,6 @@ Osheet::Workbook.new {
|
|
248
250
|
|
249
251
|
|
250
252
|
|
251
|
-
}.to_file('examples/styles.xls', :
|
253
|
+
}.to_file('examples/styles.xls', :pp => 2)
|
254
|
+
|
255
|
+
puts "open examples/styles.xls"
|
data/examples/styles.xls
ADDED
@@ -0,0 +1,343 @@
|
|
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
|
+
<Style ss:ID=".align.rotA">
|
5
|
+
<Alignment ss:Rotate="90" />
|
6
|
+
<NumberFormat />
|
7
|
+
</Style>
|
8
|
+
<Style ss:ID=".align.rotB">
|
9
|
+
<Alignment ss:Rotate="-90" />
|
10
|
+
<NumberFormat />
|
11
|
+
</Style>
|
12
|
+
<Style ss:ID=".align.rotC">
|
13
|
+
<Alignment ss:Rotate="45" />
|
14
|
+
<NumberFormat />
|
15
|
+
</Style>
|
16
|
+
<Style ss:ID=".align.top">
|
17
|
+
<Alignment ss:Vertical="Top" />
|
18
|
+
<NumberFormat />
|
19
|
+
</Style>
|
20
|
+
<Style ss:ID=".align.middle">
|
21
|
+
<Alignment ss:Vertical="Center" />
|
22
|
+
<NumberFormat />
|
23
|
+
</Style>
|
24
|
+
<Style ss:ID=".align.bottom">
|
25
|
+
<Alignment ss:Vertical="Bottom" />
|
26
|
+
<NumberFormat />
|
27
|
+
</Style>
|
28
|
+
<Style ss:ID=".align.wrap">
|
29
|
+
<Alignment ss:WrapText="1" />
|
30
|
+
<NumberFormat />
|
31
|
+
</Style>
|
32
|
+
<Style ss:ID=".align.left">
|
33
|
+
<Alignment ss:Horizontal="Left" />
|
34
|
+
<NumberFormat />
|
35
|
+
</Style>
|
36
|
+
<Style ss:ID=".align.center">
|
37
|
+
<Alignment ss:Horizontal="Center" />
|
38
|
+
<NumberFormat />
|
39
|
+
</Style>
|
40
|
+
<Style ss:ID=".align.right">
|
41
|
+
<Alignment ss:Horizontal="Right" />
|
42
|
+
<NumberFormat />
|
43
|
+
</Style>
|
44
|
+
<Style ss:ID=".font.underline">
|
45
|
+
<Font ss:Underline="Single" />
|
46
|
+
<NumberFormat />
|
47
|
+
</Style>
|
48
|
+
<Style ss:ID=".font.double_underline">
|
49
|
+
<Font ss:Underline="Double" />
|
50
|
+
<NumberFormat />
|
51
|
+
</Style>
|
52
|
+
<Style ss:ID=".font.accounting_underline">
|
53
|
+
<Font ss:Underline="SingleAccounting" />
|
54
|
+
<NumberFormat />
|
55
|
+
</Style>
|
56
|
+
<Style ss:ID=".font.double_accounting_underline">
|
57
|
+
<Font ss:Underline="DoubleAccounting" />
|
58
|
+
<NumberFormat />
|
59
|
+
</Style>
|
60
|
+
<Style ss:ID=".font.subscript">
|
61
|
+
<Font ss:VerticalAlign="Subscript" />
|
62
|
+
<NumberFormat />
|
63
|
+
</Style>
|
64
|
+
<Style ss:ID=".font.superscript">
|
65
|
+
<Font ss:VerticalAlign="Superscript" />
|
66
|
+
<NumberFormat />
|
67
|
+
</Style>
|
68
|
+
<Style ss:ID=".font.strikethrough">
|
69
|
+
<Font ss:StrikeThrough="1" />
|
70
|
+
<NumberFormat />
|
71
|
+
</Style>
|
72
|
+
<Style ss:ID=".font.shadow">
|
73
|
+
<Font ss:Shadow="1" />
|
74
|
+
<NumberFormat />
|
75
|
+
</Style>
|
76
|
+
<Style ss:ID=".font.bold">
|
77
|
+
<Font ss:Bold="1" />
|
78
|
+
<NumberFormat />
|
79
|
+
</Style>
|
80
|
+
<Style ss:ID=".font.italic">
|
81
|
+
<Font ss:Italic="1" />
|
82
|
+
<NumberFormat />
|
83
|
+
</Style>
|
84
|
+
<Style ss:ID=".font.sizeA">
|
85
|
+
<Font ss:Size="6" />
|
86
|
+
<NumberFormat />
|
87
|
+
</Style>
|
88
|
+
<Style ss:ID=".font.sizeB">
|
89
|
+
<Font ss:Size="14" />
|
90
|
+
<NumberFormat />
|
91
|
+
</Style>
|
92
|
+
<Style ss:ID=".font.colorA">
|
93
|
+
<Font ss:Color="#FF0000" />
|
94
|
+
<NumberFormat />
|
95
|
+
</Style>
|
96
|
+
<Style ss:ID=".font.colorB">
|
97
|
+
<Font ss:Color="#00FF00" />
|
98
|
+
<NumberFormat />
|
99
|
+
</Style>
|
100
|
+
<Style ss:ID=".font.nameA">
|
101
|
+
<Font ss:FontName="Courier" />
|
102
|
+
<NumberFormat />
|
103
|
+
</Style>
|
104
|
+
<Style ss:ID=".font.nameB">
|
105
|
+
<Font ss:FontName="Times New Roman" />
|
106
|
+
<NumberFormat />
|
107
|
+
</Style>
|
108
|
+
<Style ss:ID=".bg.color">
|
109
|
+
<Font ss:Color="#FFFFFF" />
|
110
|
+
<Interior ss:Color="#FF0000" ss:Pattern="Solid" />
|
111
|
+
<NumberFormat />
|
112
|
+
</Style>
|
113
|
+
<Style ss:ID=".bg.pattern">
|
114
|
+
<Interior ss:Pattern="HorzStripe" />
|
115
|
+
<NumberFormat />
|
116
|
+
</Style>
|
117
|
+
<Style ss:ID=".bg.pattern.color">
|
118
|
+
<Font ss:Color="#FFFFFF" />
|
119
|
+
<Interior ss:Color="#FF0000" ss:Pattern="HorzStripe" ss:PatternColor="#000000" />
|
120
|
+
<NumberFormat />
|
121
|
+
</Style>
|
122
|
+
<Style ss:ID=".border.top.color.weight.style">
|
123
|
+
<Borders>
|
124
|
+
<Border ss:Color="#FF0000" ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="0" />
|
125
|
+
</Borders>
|
126
|
+
<NumberFormat />
|
127
|
+
</Style>
|
128
|
+
<Style ss:ID=".border.right.color.weight.style">
|
129
|
+
<Borders>
|
130
|
+
<Border ss:Color="#00FF00" ss:LineStyle="Dash" ss:Position="Right" ss:Weight="1" />
|
131
|
+
</Borders>
|
132
|
+
<NumberFormat />
|
133
|
+
</Style>
|
134
|
+
<Style ss:ID=".border.bottom.color.weight.style">
|
135
|
+
<Borders>
|
136
|
+
<Border ss:Color="#0000FF" ss:LineStyle="Dot" ss:Position="Bottom" ss:Weight="2" />
|
137
|
+
</Borders>
|
138
|
+
<NumberFormat />
|
139
|
+
</Style>
|
140
|
+
<Style ss:ID=".border.left.color.weight.style">
|
141
|
+
<Borders>
|
142
|
+
<Border ss:Color="#FFFF00" ss:LineStyle="DashDot" ss:Position="Left" ss:Weight="3" />
|
143
|
+
</Borders>
|
144
|
+
<NumberFormat />
|
145
|
+
</Style>
|
146
|
+
<Style ss:ID=".border.all">
|
147
|
+
<Borders>
|
148
|
+
<Border ss:Color="#00FFFF" ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="3" />
|
149
|
+
<Border ss:Color="#00FFFF" ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="3" />
|
150
|
+
<Border ss:Color="#00FFFF" ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="3" />
|
151
|
+
<Border ss:Color="#00FFFF" ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="3" />
|
152
|
+
</Borders>
|
153
|
+
<NumberFormat />
|
154
|
+
</Style>
|
155
|
+
</Styles>
|
156
|
+
<Worksheet ss:Name="align">
|
157
|
+
<Table>
|
158
|
+
<Column ss:Width="100" />
|
159
|
+
<Column ss:Width="100" />
|
160
|
+
<Column ss:Width="100" />
|
161
|
+
<Column ss:Width="100" />
|
162
|
+
<Row ss:Height="50">
|
163
|
+
<Cell ss:StyleID=".align.rotA">
|
164
|
+
<Data ss:Type="String">rotA</Data>
|
165
|
+
</Cell>
|
166
|
+
<Cell ss:StyleID=".align.rotB">
|
167
|
+
<Data ss:Type="String">rotB</Data>
|
168
|
+
</Cell>
|
169
|
+
<Cell ss:StyleID=".align.rotC">
|
170
|
+
<Data ss:Type="String">rotC</Data>
|
171
|
+
</Cell>
|
172
|
+
</Row>
|
173
|
+
<Row ss:Height="50">
|
174
|
+
<Cell ss:StyleID=".align.top">
|
175
|
+
<Data ss:Type="String">top</Data>
|
176
|
+
</Cell>
|
177
|
+
<Cell ss:StyleID=".align.middle">
|
178
|
+
<Data ss:Type="String">middle</Data>
|
179
|
+
</Cell>
|
180
|
+
<Cell ss:StyleID=".align.bottom">
|
181
|
+
<Data ss:Type="String">bottom</Data>
|
182
|
+
</Cell>
|
183
|
+
</Row>
|
184
|
+
<Row ss:Height="50">
|
185
|
+
<Cell ss:StyleID=".align.wrap">
|
186
|
+
<Data ss:Type="String">wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap </Data>
|
187
|
+
</Cell>
|
188
|
+
</Row>
|
189
|
+
<Row ss:Height="50">
|
190
|
+
<Cell ss:StyleID=".align.left">
|
191
|
+
<Data ss:Type="String">left</Data>
|
192
|
+
</Cell>
|
193
|
+
<Cell ss:StyleID=".align.center">
|
194
|
+
<Data ss:Type="String">center</Data>
|
195
|
+
</Cell>
|
196
|
+
<Cell ss:StyleID=".align.right">
|
197
|
+
<Data ss:Type="String">right</Data>
|
198
|
+
</Cell>
|
199
|
+
</Row>
|
200
|
+
</Table>
|
201
|
+
</Worksheet>
|
202
|
+
<Worksheet ss:Name="font">
|
203
|
+
<Table>
|
204
|
+
<Column ss:Width="100" />
|
205
|
+
<Column ss:Width="100" />
|
206
|
+
<Column ss:Width="100" />
|
207
|
+
<Column ss:Width="100" />
|
208
|
+
<Column ss:Width="100" />
|
209
|
+
<Column ss:Width="100" />
|
210
|
+
<Row>
|
211
|
+
<Cell ss:StyleID=".font.underline">
|
212
|
+
<Data ss:Type="String">underline</Data>
|
213
|
+
</Cell>
|
214
|
+
<Cell ss:StyleID=".font.double_underline">
|
215
|
+
<Data ss:Type="String">double_underline</Data>
|
216
|
+
</Cell>
|
217
|
+
<Cell ss:StyleID=".font.accounting_underline">
|
218
|
+
<Data ss:Type="String">accounting_underline</Data>
|
219
|
+
</Cell>
|
220
|
+
<Cell ss:StyleID=".font.double_accounting_underline">
|
221
|
+
<Data ss:Type="String">double_accounting_underline</Data>
|
222
|
+
</Cell>
|
223
|
+
</Row>
|
224
|
+
<Row>
|
225
|
+
<Cell ss:StyleID=".font.subscript">
|
226
|
+
<Data ss:Type="String">subscript</Data>
|
227
|
+
</Cell>
|
228
|
+
<Cell ss:StyleID=".font.superscript">
|
229
|
+
<Data ss:Type="String">superscript</Data>
|
230
|
+
</Cell>
|
231
|
+
<Cell ss:StyleID=".font.strikethrough">
|
232
|
+
<Data ss:Type="String">strikethrough</Data>
|
233
|
+
</Cell>
|
234
|
+
<Cell ss:StyleID=".font.shadow">
|
235
|
+
<Data ss:Type="String">shadow</Data>
|
236
|
+
</Cell>
|
237
|
+
</Row>
|
238
|
+
<Row>
|
239
|
+
<Cell ss:StyleID=".font.bold">
|
240
|
+
<Data ss:Type="String">bold</Data>
|
241
|
+
</Cell>
|
242
|
+
<Cell ss:StyleID=".font.italic">
|
243
|
+
<Data ss:Type="String">italic</Data>
|
244
|
+
</Cell>
|
245
|
+
</Row>
|
246
|
+
<Row>
|
247
|
+
<Cell ss:StyleID=".font.sizeA">
|
248
|
+
<Data ss:Type="String">sizeA</Data>
|
249
|
+
</Cell>
|
250
|
+
<Cell ss:StyleID=".font.sizeB">
|
251
|
+
<Data ss:Type="String">sizeB</Data>
|
252
|
+
</Cell>
|
253
|
+
</Row>
|
254
|
+
<Row>
|
255
|
+
<Cell ss:StyleID=".font.colorA">
|
256
|
+
<Data ss:Type="String">colorA</Data>
|
257
|
+
</Cell>
|
258
|
+
<Cell ss:StyleID=".font.colorB">
|
259
|
+
<Data ss:Type="String">colorB</Data>
|
260
|
+
</Cell>
|
261
|
+
</Row>
|
262
|
+
<Row>
|
263
|
+
<Cell ss:StyleID=".font.nameA">
|
264
|
+
<Data ss:Type="String">nameA</Data>
|
265
|
+
</Cell>
|
266
|
+
<Cell ss:StyleID=".font.nameB">
|
267
|
+
<Data ss:Type="String">nameB</Data>
|
268
|
+
</Cell>
|
269
|
+
</Row>
|
270
|
+
</Table>
|
271
|
+
</Worksheet>
|
272
|
+
<Worksheet ss:Name="bg">
|
273
|
+
<Table>
|
274
|
+
<Column ss:Width="100" />
|
275
|
+
<Row ss:Height="50">
|
276
|
+
<Cell ss:StyleID=".bg.color">
|
277
|
+
<Data ss:Type="String">COLOR</Data>
|
278
|
+
</Cell>
|
279
|
+
</Row>
|
280
|
+
<Row ss:Height="50">
|
281
|
+
<Cell ss:StyleID=".bg.pattern">
|
282
|
+
<Data ss:Type="String">PATTERN</Data>
|
283
|
+
</Cell>
|
284
|
+
</Row>
|
285
|
+
<Row ss:Height="50">
|
286
|
+
<Cell ss:StyleID=".bg.pattern.color">
|
287
|
+
<Data ss:Type="String">PATTERN COLOR</Data>
|
288
|
+
</Cell>
|
289
|
+
</Row>
|
290
|
+
</Table>
|
291
|
+
</Worksheet>
|
292
|
+
<Worksheet ss:Name="border">
|
293
|
+
<Table>
|
294
|
+
<Column ss:Width="20" />
|
295
|
+
<Column ss:Width="200" />
|
296
|
+
<Row></Row>
|
297
|
+
<Row ss:Height="50">
|
298
|
+
<Cell>
|
299
|
+
<Data ss:Type="String"></Data>
|
300
|
+
</Cell>
|
301
|
+
<Cell ss:StyleID=".border.top.color.weight.style">
|
302
|
+
<Data ss:Type="String">top red hairline continuous</Data>
|
303
|
+
</Cell>
|
304
|
+
</Row>
|
305
|
+
<Row></Row>
|
306
|
+
<Row ss:Height="50">
|
307
|
+
<Cell>
|
308
|
+
<Data ss:Type="String"></Data>
|
309
|
+
</Cell>
|
310
|
+
<Cell ss:StyleID=".border.right.color.weight.style">
|
311
|
+
<Data ss:Type="String">right green thin dash</Data>
|
312
|
+
</Cell>
|
313
|
+
</Row>
|
314
|
+
<Row></Row>
|
315
|
+
<Row ss:Height="50">
|
316
|
+
<Cell>
|
317
|
+
<Data ss:Type="String"></Data>
|
318
|
+
</Cell>
|
319
|
+
<Cell ss:StyleID=".border.bottom.color.weight.style">
|
320
|
+
<Data ss:Type="String">bottom blue medium dat</Data>
|
321
|
+
</Cell>
|
322
|
+
</Row>
|
323
|
+
<Row></Row>
|
324
|
+
<Row ss:Height="50">
|
325
|
+
<Cell>
|
326
|
+
<Data ss:Type="String"></Data>
|
327
|
+
</Cell>
|
328
|
+
<Cell ss:StyleID=".border.left.color.weight.style">
|
329
|
+
<Data ss:Type="String">left yellow thick dast_dot</Data>
|
330
|
+
</Cell>
|
331
|
+
</Row>
|
332
|
+
<Row></Row>
|
333
|
+
<Row ss:Height="50">
|
334
|
+
<Cell>
|
335
|
+
<Data ss:Type="String"></Data>
|
336
|
+
</Cell>
|
337
|
+
<Cell ss:StyleID=".border.all">
|
338
|
+
<Data ss:Type="String">all aqua</Data>
|
339
|
+
</Cell>
|
340
|
+
</Row>
|
341
|
+
</Table>
|
342
|
+
</Worksheet>
|
343
|
+
</Workbook>
|
data/examples/trivial.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'osheet'
|
8
8
|
|
9
|
+
puts "building examples/trivial.rb ..."
|
10
|
+
|
9
11
|
Osheet::Workbook.new {
|
10
12
|
title "basic"
|
11
13
|
worksheet {
|
@@ -18,4 +20,6 @@ Osheet::Workbook.new {
|
|
18
20
|
}
|
19
21
|
}
|
20
22
|
}
|
21
|
-
}.to_file('examples/trivial.xls', :
|
23
|
+
}.to_file('examples/trivial.xls', :pp => 2)
|
24
|
+
|
25
|
+
puts "open examples/trivial.xls"
|
@@ -0,0 +1,18 @@
|
|
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
|
+
<Style ss:ID="..currency_dollar_2_comma_black">
|
5
|
+
<NumberFormat ss:Format=""$"#,##0.00" />
|
6
|
+
</Style>
|
7
|
+
</Styles>
|
8
|
+
<Worksheet ss:Name="one dollar">
|
9
|
+
<Table>
|
10
|
+
<Column />
|
11
|
+
<Row>
|
12
|
+
<Cell ss:StyleID="..currency_dollar_2_comma_black">
|
13
|
+
<Data ss:Type="Number">1</Data>
|
14
|
+
</Cell>
|
15
|
+
</Row>
|
16
|
+
</Table>
|
17
|
+
</Worksheet>
|
18
|
+
</Workbook>
|
data/lib/osheet/version.rb
CHANGED
@@ -9,44 +9,41 @@ module Osheet::XmlssWriter
|
|
9
9
|
include Elements
|
10
10
|
include Styles
|
11
11
|
|
12
|
-
attr_reader :
|
12
|
+
attr_reader :used_xstyles
|
13
13
|
|
14
14
|
def initialize(opts={})
|
15
|
-
@
|
16
|
-
|
17
|
-
|
15
|
+
@used_xstyles = []
|
16
|
+
self.oworkbook = if opts.has_key?(:workbook)
|
17
|
+
opts[:workbook]
|
18
|
+
else
|
19
|
+
::Osheet::Workbook.new
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
|
22
|
-
raise ArgumentError, "'#{oworkbook.inspect}' is not an Osheet::Workbook"
|
23
|
-
end
|
24
|
-
# if oworkbook && oworkbook.worksheets.collect{|ws| ws.name}.include?(name_value)
|
25
|
-
# # puts "ERRORR!!!!!!!!!!!!!!"
|
26
|
-
# # puts "names: #{names.inspect}"
|
27
|
-
# # puts "name value: #{name_value}"
|
28
|
-
# raise ArgumentError, "the sheet name '#{name_value}' is already in use. enter a sheet name that is not used by another sheet"
|
29
|
-
# end
|
30
|
-
# # puts "names: #{names.inspect}"
|
31
|
-
# # puts "name value: #{name_value}"
|
32
|
-
# # name_value
|
33
|
-
|
34
|
-
@ostyles = oworkbook.styles
|
35
|
-
@workbook = ::Xmlss::Workbook.new({
|
36
|
-
:worksheets => worksheets(oworkbook.worksheets)
|
37
|
-
})
|
23
|
+
def to_data(xmlss_output_opts={})
|
24
|
+
self.xworkbook(xmlss_output_opts).to_s
|
38
25
|
end
|
39
26
|
|
40
|
-
def
|
41
|
-
|
42
|
-
@workbook.to_xml(*options)
|
27
|
+
def to_file(file_path, xmlss_output_opts={})
|
28
|
+
self.xworkbook(xmlss_output_opts).to_file(file_path)
|
43
29
|
end
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
def oworkbook=(value)
|
35
|
+
unless value.kind_of?(::Osheet::Workbook)
|
36
|
+
raise ArgumentError, "'#{value.inspect}' is not an Osheet::Workbook"
|
37
|
+
end
|
38
|
+
@oworkbook = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def xworkbook(xmlss_output_opts={})
|
42
|
+
@used_xstyles = []
|
43
|
+
::Xmlss::Workbook.new(:output => xmlss_output_opts).tap do |xwkbk|
|
44
|
+
@oworkbook.worksheets.each { |sheet| worksheet(xwkbk, sheet) }
|
45
|
+
end
|
49
46
|
end
|
50
47
|
|
51
48
|
end
|
52
|
-
end
|
49
|
+
end
|
@@ -2,69 +2,55 @@ module Osheet::XmlssWriter::Elements
|
|
2
2
|
|
3
3
|
protected
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
5
|
+
def worksheet(xworkbook, oworksheet)
|
6
|
+
xworkbook.worksheet(oworksheet.attributes[:name]) do
|
7
|
+
oworksheet.columns.each { |ocolumn| column(xworkbook, ocolumn) }
|
8
|
+
oworksheet.rows.each { |orow| row(xworkbook, orow) }
|
8
9
|
end
|
9
10
|
end
|
10
|
-
def worksheet(oworksheet)
|
11
|
-
::Xmlss::Worksheet.new(oworksheet.attributes[:name], {
|
12
|
-
:table => table(oworksheet)
|
13
|
-
})
|
14
|
-
end
|
15
|
-
def table(oworksheet)
|
16
|
-
::Xmlss::Table.new({
|
17
|
-
:columns => columns(oworksheet.columns),
|
18
|
-
:rows => rows(oworksheet.rows)
|
19
|
-
})
|
20
|
-
end
|
21
11
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
def column(ocolumn)
|
28
|
-
::Xmlss::Column.new({
|
29
|
-
:style_id => style_id(ocolumn.attributes[:style_class]),
|
12
|
+
def column(xworkbook, ocolumn)
|
13
|
+
xworkbook.column({
|
14
|
+
:style_id => style_id(xworkbook, ocolumn.attributes[:style_class]),
|
30
15
|
:width => ocolumn.attributes[:width],
|
31
16
|
:auto_fit_width => ocolumn.attributes[:autofit],
|
32
17
|
:hidden => ocolumn.attributes[:hidden]
|
33
18
|
})
|
34
19
|
end
|
35
20
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
def row(orow)
|
40
|
-
::Xmlss::Row.new({
|
41
|
-
:style_id => style_id(orow.attributes[:style_class]),
|
21
|
+
def row(xworkbook, orow)
|
22
|
+
xworkbook.row({
|
23
|
+
:style_id => style_id(xworkbook, orow.attributes[:style_class]),
|
42
24
|
:height => orow.attributes[:height],
|
43
25
|
:auto_fit_height => orow.attributes[:autofit],
|
44
|
-
:hidden => orow.attributes[:hidden]
|
45
|
-
|
46
|
-
|
26
|
+
:hidden => orow.attributes[:hidden]
|
27
|
+
}) do
|
28
|
+
orow.cells.each { |ocell| cell(xworkbook, ocell) }
|
29
|
+
end
|
47
30
|
end
|
48
31
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
def cell(ocell)
|
53
|
-
::Xmlss::Cell.new({
|
54
|
-
:style_id => style_id(ocell.attributes[:style_class], ocell.attributes[:format]),
|
32
|
+
def cell(xworkbook, ocell)
|
33
|
+
xworkbook.cell({
|
34
|
+
:style_id => style_id(xworkbook, ocell.attributes[:style_class], ocell.attributes[:format]),
|
55
35
|
:href => ocell.attributes[:href],
|
56
36
|
:index => ocell.attributes[:index],
|
57
37
|
:merge_across => cell_merge(ocell.attributes[:colspan]),
|
58
38
|
:merge_down => cell_merge(ocell.attributes[:rowspan]),
|
59
|
-
:data => data(ocell.attributes[:data]),
|
60
39
|
:formula => ocell.attributes[:formula]
|
61
|
-
})
|
40
|
+
}) do
|
41
|
+
data(xworkbook, ocell.attributes[:data])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def data(xworkbook, odata)
|
46
|
+
xworkbook.data(odata)
|
62
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# convert osheet col/row span value to xmlss merge value
|
63
52
|
def cell_merge(span)
|
64
53
|
span.kind_of?(::Fixnum) && span > 1 ? span-1 : 0
|
65
54
|
end
|
66
|
-
def data(ocell_data)
|
67
|
-
::Xmlss::Data.new(ocell_data)
|
68
|
-
end
|
69
55
|
|
70
56
|
end
|