rubyXL 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +34 -0
  3. data/LICENSE.txt +20 -0
  4. data/README +0 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/.DS_Store +0 -0
  9. data/lib/Hash.rb +60 -0
  10. data/lib/cell.rb +360 -0
  11. data/lib/color.rb +14 -0
  12. data/lib/parser.rb +413 -0
  13. data/lib/private_class.rb +182 -0
  14. data/lib/rubyXL.rb +9 -0
  15. data/lib/test.html +1 -0
  16. data/lib/tests/test.rb +110 -0
  17. data/lib/tests/test10.rb +16 -0
  18. data/lib/tests/test2.rb +118 -0
  19. data/lib/tests/test3.rb +76 -0
  20. data/lib/tests/test4.rb +92 -0
  21. data/lib/tests/test5.rb +90 -0
  22. data/lib/tests/test6.rb +50 -0
  23. data/lib/tests/test7.rb +48 -0
  24. data/lib/tests/test8.rb +12 -0
  25. data/lib/tests/test9.rb +60 -0
  26. data/lib/workbook.rb +336 -0
  27. data/lib/worksheet.rb +1245 -0
  28. data/lib/writer/app_writer.rb +62 -0
  29. data/lib/writer/calc_chain_writer.rb +33 -0
  30. data/lib/writer/content_types_writer.rb +77 -0
  31. data/lib/writer/core_writer.rb +51 -0
  32. data/lib/writer/root_rels_writer.rb +25 -0
  33. data/lib/writer/shared_strings_writer.rb +44 -0
  34. data/lib/writer/styles_writer.rb +376 -0
  35. data/lib/writer/theme_writer.rb +346 -0
  36. data/lib/writer/workbook_rels_writer.rb +59 -0
  37. data/lib/writer/workbook_writer.rb +77 -0
  38. data/lib/writer/worksheet_writer.rb +208 -0
  39. data/lib/zip.rb +20 -0
  40. data/pkg/rubyXL-1.0.4.gem +0 -0
  41. data/rubyXL.gemspec +106 -0
  42. data/spec/lib/cell_spec.rb +359 -0
  43. data/spec/lib/color_spec.rb +14 -0
  44. data/spec/lib/hash_spec.rb +28 -0
  45. data/spec/lib/parser_spec.rb +49 -0
  46. data/spec/lib/workbook_spec.rb +51 -0
  47. data/spec/lib/worksheet_spec.rb +1650 -0
  48. metadata +222 -0
@@ -0,0 +1,346 @@
1
+ # require File.expand_path(File.join(File.dirname(__FILE__),'workbook'))
2
+ # require File.expand_path(File.join(File.dirname(__FILE__),'worksheet'))
3
+ # require File.expand_path(File.join(File.dirname(__FILE__),'cell'))
4
+ # require File.expand_path(File.join(File.dirname(__FILE__),'color'))
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+
8
+ module RubyXL
9
+ module Writer
10
+ class ThemeWriter
11
+ attr_accessor :dirpath, :filepath, :workbook
12
+
13
+ def initialize(dirpath, wb)
14
+ @dirpath = dirpath
15
+ @workbook = wb
16
+ @filepath = dirpath + '/xl/theme/theme1.xml'
17
+ end
18
+
19
+ def write()
20
+
21
+ contents = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
+
23
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
24
+ <a:themeElements>
25
+ <a:clrScheme name="Office">
26
+ <a:dk1>
27
+ <a:sysClr val="windowText" lastClr="000000"/>
28
+ </a:dk1>
29
+ <a:lt1>
30
+ <a:sysClr val="window" lastClr="FFFFFF"/>
31
+ </a:lt1>
32
+ <a:dk2>
33
+ <a:srgbClr val="1F497D"/>
34
+ </a:dk2>
35
+ <a:lt2>
36
+ <a:srgbClr val="EEECE1"/>
37
+ </a:lt2>
38
+ <a:accent1>
39
+ <a:srgbClr val="4F81BD"/>
40
+ </a:accent1>
41
+ <a:accent2>
42
+ <a:srgbClr val="C0504D"/>
43
+ </a:accent2>
44
+ <a:accent3>
45
+ <a:srgbClr val="9BBB59"/>
46
+ </a:accent3>
47
+ <a:accent4>
48
+ <a:srgbClr val="8064A2"/>
49
+ </a:accent4>
50
+ <a:accent5>
51
+ <a:srgbClr val="4BACC6"/>
52
+ </a:accent5>
53
+ <a:accent6>
54
+ <a:srgbClr val="F79646"/>
55
+ </a:accent6>
56
+ <a:hlink>
57
+ <a:srgbClr val="0000FF"/>
58
+ </a:hlink>
59
+ <a:folHlink>
60
+ <a:srgbClr val="800080"/>
61
+ </a:folHlink>
62
+ </a:clrScheme>
63
+ <a:fontScheme name="Office">
64
+ <a:majorFont>
65
+ <a:latin typeface="Cambria"/>
66
+ <a:ea typeface=""/>
67
+ <a:cs typeface=""/>
68
+ <a:font script="Jpan" typeface="MS Pゴシック"/>
69
+ <a:font script="Hang" typeface="맑은 고딕"/>
70
+ <a:font script="Hans" typeface="宋体"/>
71
+ <a:font script="Hant" typeface="新細明體"/>
72
+ <a:font script="Arab" typeface="Times New Roman"/>
73
+ <a:font script="Hebr" typeface="Times New Roman"/>
74
+ <a:font script="Thai" typeface="Tahoma"/>
75
+ <a:font script="Ethi" typeface="Nyala"/>
76
+ <a:font script="Beng" typeface="Vrinda"/>
77
+ <a:font script="Gujr" typeface="Shruti"/>
78
+ <a:font script="Khmr" typeface="MoolBoran"/>
79
+ <a:font script="Knda" typeface="Tunga"/>
80
+ <a:font script="Guru" typeface="Raavi"/>
81
+ <a:font script="Cans" typeface="Euphemia"/>
82
+ <a:font script="Cher" typeface="Plantagenet Cherokee"/>
83
+ <a:font script="Yiii" typeface="Microsoft Yi Baiti"/>
84
+ <a:font script="Tibt" typeface="Microsoft Himalaya"/>
85
+ <a:font script="Thaa" typeface="MV Boli"/>
86
+ <a:font script="Deva" typeface="Mangal"/>
87
+ <a:font script="Telu" typeface="Gautami"/>
88
+ <a:font script="Taml" typeface="Latha"/>
89
+ <a:font script="Syrc" typeface="Estrangelo Edessa"/>
90
+ <a:font script="Orya" typeface="Kalinga"/>
91
+ <a:font script="Mlym" typeface="Kartika"/>
92
+ <a:font script="Laoo" typeface="DokChampa"/>
93
+ <a:font script="Sinh" typeface="Iskoola Pota"/>
94
+ <a:font script="Mong" typeface="Mongolian Baiti"/>
95
+ <a:font script="Viet" typeface="Times New Roman"/>
96
+ <a:font script="Uigh" typeface="Microsoft Uighur"/>
97
+ </a:majorFont>
98
+ <a:minorFont>
99
+ <a:latin typeface="Calibri"/>
100
+ <a:ea typeface=""/>
101
+ <a:cs typeface=""/>
102
+ <a:font script="Jpan" typeface="MS Pゴシック"/>
103
+ <a:font script="Hang" typeface="맑은 고딕"/>
104
+ <a:font script="Hans" typeface="宋体"/>
105
+ <a:font script="Hant" typeface="新細明體"/>
106
+ <a:font script="Arab" typeface="Arial"/>
107
+ <a:font script="Hebr" typeface="Arial"/>
108
+ <a:font script="Thai" typeface="Tahoma"/>
109
+ <a:font script="Ethi" typeface="Nyala"/>
110
+ <a:font script="Beng" typeface="Vrinda"/>
111
+ <a:font script="Gujr" typeface="Shruti"/>
112
+ <a:font script="Khmr" typeface="DaunPenh"/>
113
+ <a:font script="Knda" typeface="Tunga"/>
114
+ <a:font script="Guru" typeface="Raavi"/>
115
+ <a:font script="Cans" typeface="Euphemia"/>
116
+ <a:font script="Cher" typeface="Plantagenet Cherokee"/>
117
+ <a:font script="Yiii" typeface="Microsoft Yi Baiti"/>
118
+ <a:font script="Tibt" typeface="Microsoft Himalaya"/>
119
+ <a:font script="Thaa" typeface="MV Boli"/>
120
+ <a:font script="Deva" typeface="Mangal"/>
121
+ <a:font script="Telu" typeface="Gautami"/>
122
+ <a:font script="Taml" typeface="Latha"/>
123
+ <a:font script="Syrc" typeface="Estrangelo Edessa"/>
124
+ <a:font script="Orya" typeface="Kalinga"/>
125
+ <a:font script="Mlym" typeface="Kartika"/>
126
+ <a:font script="Laoo" typeface="DokChampa"/>
127
+ <a:font script="Sinh" typeface="Iskoola Pota"/>
128
+ <a:font script="Mong" typeface="Mongolian Baiti"/>
129
+ <a:font script="Viet" typeface="Arial"/>
130
+ <a:font script="Uigh" typeface="Microsoft Uighur"/>
131
+ </a:minorFont>
132
+ </a:fontScheme>
133
+ <a:fmtScheme name="Office">
134
+ <a:fillStyleLst>
135
+ <a:solidFill>
136
+ <a:schemeClr val="phClr"/>
137
+ </a:solidFill>
138
+ <a:gradFill rotWithShape="1">
139
+ <a:gsLst>
140
+ <a:gs pos="0">
141
+ <a:schemeClr val="phClr">
142
+ <a:tint val="50000"/>
143
+ <a:satMod val="300000"/>
144
+ </a:schemeClr>
145
+ </a:gs>
146
+ <a:gs pos="35000">
147
+ <a:schemeClr val="phClr">
148
+ <a:tint val="37000"/>
149
+ <a:satMod val="300000"/>
150
+ </a:schemeClr>
151
+ </a:gs>
152
+ <a:gs pos="100000">
153
+ <a:schemeClr val="phClr">
154
+ <a:tint val="15000"/>
155
+ <a:satMod val="350000"/>
156
+ </a:schemeClr>
157
+ </a:gs>
158
+ </a:gsLst>
159
+ <a:lin ang="16200000" scaled="1"/>
160
+ </a:gradFill>
161
+ <a:gradFill rotWithShape="1">
162
+ <a:gsLst>
163
+ <a:gs pos="0">
164
+ <a:schemeClr val="phClr">
165
+ <a:tint val="100000"/>
166
+ <a:shade val="100000"/>
167
+ <a:satMod val="130000"/>
168
+ </a:schemeClr>
169
+ </a:gs>
170
+ <a:gs pos="100000">
171
+ <a:schemeClr val="phClr">
172
+ <a:tint val="50000"/>
173
+ <a:shade val="100000"/>
174
+ <a:satMod val="350000"/>
175
+ </a:schemeClr>
176
+ </a:gs>
177
+ </a:gsLst>
178
+ <a:lin ang="16200000" scaled="0"/>
179
+ </a:gradFill>
180
+ </a:fillStyleLst>
181
+ <a:lnStyleLst>
182
+ <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">
183
+ <a:solidFill>
184
+ <a:schemeClr val="phClr">
185
+ <a:shade val="95000"/>
186
+ <a:satMod val="105000"/>
187
+ </a:schemeClr>
188
+ </a:solidFill>
189
+ <a:prstDash val="solid"/>
190
+ </a:ln>
191
+ <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">
192
+ <a:solidFill>
193
+ <a:schemeClr val="phClr"/>
194
+ </a:solidFill>
195
+ <a:prstDash val="solid"/>
196
+ </a:ln>
197
+ <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">
198
+ <a:solidFill>
199
+ <a:schemeClr val="phClr"/>
200
+ </a:solidFill>
201
+ <a:prstDash val="solid"/>
202
+ </a:ln>
203
+ </a:lnStyleLst>
204
+ <a:effectStyleLst>
205
+ <a:effectStyle>
206
+ <a:effectLst>
207
+ <a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0">
208
+ <a:srgbClr val="000000">
209
+ <a:alpha val="38000"/>
210
+ </a:srgbClr>
211
+ </a:outerShdw>
212
+ </a:effectLst>
213
+ </a:effectStyle>
214
+ <a:effectStyle>
215
+ <a:effectLst>
216
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
217
+ <a:srgbClr val="000000">
218
+ <a:alpha val="35000"/>
219
+ </a:srgbClr>
220
+ </a:outerShdw>
221
+ </a:effectLst>
222
+ </a:effectStyle>
223
+ <a:effectStyle>
224
+ <a:effectLst>
225
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
226
+ <a:srgbClr val="000000">
227
+ <a:alpha val="35000"/>
228
+ </a:srgbClr>
229
+ </a:outerShdw>
230
+ </a:effectLst>
231
+ <a:scene3d>
232
+ <a:camera prst="orthographicFront">
233
+ <a:rot lat="0" lon="0" rev="0"/>
234
+ </a:camera>
235
+ <a:lightRig rig="threePt" dir="t">
236
+ <a:rot lat="0" lon="0" rev="1200000"/>
237
+ </a:lightRig>
238
+ </a:scene3d>
239
+ <a:sp3d>
240
+ <a:bevelT w="63500" h="25400"/>
241
+ </a:sp3d>
242
+ </a:effectStyle>
243
+ </a:effectStyleLst>
244
+ <a:bgFillStyleLst>
245
+ <a:solidFill>
246
+ <a:schemeClr val="phClr"/>
247
+ </a:solidFill>
248
+ <a:gradFill rotWithShape="1">
249
+ <a:gsLst>
250
+ <a:gs pos="0">
251
+ <a:schemeClr val="phClr">
252
+ <a:tint val="40000"/>
253
+ <a:satMod val="350000"/>
254
+ </a:schemeClr>
255
+ </a:gs>
256
+ <a:gs pos="40000">
257
+ <a:schemeClr val="phClr">
258
+ <a:tint val="45000"/>
259
+ <a:shade val="99000"/>
260
+ <a:satMod val="350000"/>
261
+ </a:schemeClr>
262
+ </a:gs>
263
+ <a:gs pos="100000">
264
+ <a:schemeClr val="phClr">
265
+ <a:shade val="20000"/>
266
+ <a:satMod val="255000"/>
267
+ </a:schemeClr>
268
+ </a:gs>
269
+ </a:gsLst>
270
+ <a:path path="circle">
271
+ <a:fillToRect l="50000" t="-80000" r="50000" b="180000"/>
272
+ </a:path>
273
+ </a:gradFill>
274
+ <a:gradFill rotWithShape="1">
275
+ <a:gsLst>
276
+ <a:gs pos="0">
277
+ <a:schemeClr val="phClr">
278
+ <a:tint val="80000"/>
279
+ <a:satMod val="300000"/>
280
+ </a:schemeClr>
281
+ </a:gs>
282
+ <a:gs pos="100000">
283
+ <a:schemeClr val="phClr">
284
+ <a:shade val="30000"/>
285
+ <a:satMod val="200000"/>
286
+ </a:schemeClr>
287
+ </a:gs>
288
+ </a:gsLst>
289
+ <a:path path="circle">
290
+ <a:fillToRect l="50000" t="50000" r="50000" b="50000"/>
291
+ </a:path>
292
+ </a:gradFill>
293
+ </a:bgFillStyleLst>
294
+ </a:fmtScheme>
295
+ </a:themeElements>
296
+ <a:objectDefaults>
297
+ <a:spDef>
298
+ <a:spPr/>
299
+ <a:bodyPr/>
300
+ <a:lstStyle/>
301
+ <a:style>
302
+ <a:lnRef idx="1">
303
+ <a:schemeClr val="accent1"/>
304
+ </a:lnRef>
305
+ <a:fillRef idx="3">
306
+ <a:schemeClr val="accent1"/>
307
+ </a:fillRef>
308
+ <a:effectRef idx="2">
309
+ <a:schemeClr val="accent1"/>
310
+ </a:effectRef>
311
+ <a:fontRef idx="minor">
312
+ <a:schemeClr val="lt1"/>
313
+ </a:fontRef>
314
+ </a:style>
315
+ </a:spDef>
316
+ <a:lnDef>
317
+ <a:spPr/>
318
+ <a:bodyPr/>
319
+ <a:lstStyle/>
320
+ <a:style>
321
+ <a:lnRef idx="2">
322
+ <a:schemeClr val="accent1"/>
323
+ </a:lnRef>
324
+ <a:fillRef idx="0">
325
+ <a:schemeClr val="accent1"/>
326
+ </a:fillRef>
327
+ <a:effectRef idx="1">
328
+ <a:schemeClr val="accent1"/>
329
+ </a:effectRef>
330
+ <a:fontRef idx="minor">
331
+ <a:schemeClr val="tx1"/>
332
+ </a:fontRef>
333
+ </a:style>
334
+ </a:lnDef>
335
+ </a:objectDefaults>
336
+ <a:extraClrSchemeLst/>
337
+ </a:theme>'
338
+
339
+ # file = File.new(@filepath, 'w+')
340
+ # file.write(contents)
341
+ # file.close
342
+ contents
343
+ end
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,59 @@
1
+ # require File.expand_path(File.join(File.dirname(__FILE__),'workbook'))
2
+ # require File.expand_path(File.join(File.dirname(__FILE__),'worksheet'))
3
+ # require File.expand_path(File.join(File.dirname(__FILE__),'cell'))
4
+ # require File.expand_path(File.join(File.dirname(__FILE__),'color'))
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+
8
+ module RubyXL
9
+ module Writer
10
+ class WorkbookRelsWriter
11
+ attr_accessor :dirpath, :filepath, :workbook
12
+
13
+ def initialize(dirpath, wb)
14
+ @dirpath = dirpath
15
+ @workbook = wb
16
+ end
17
+
18
+ #all attributes out of order
19
+ def write()
20
+ builder = Nokogiri::XML::Builder.new do |xml|
21
+ xml.Relationships('xmlns'=>'http://schemas.openxmlformats.org/package/2006/relationships') {
22
+ i = 1
23
+ @workbook.worksheets.each do |sheet|
24
+ xml.Relationship('Id'=>'rId'+i.to_s,
25
+ 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
26
+ 'Target'=>'worksheets/sheet'+i.to_s+'.xml')
27
+ i += 1
28
+ end
29
+ unless @workbook.external_links.nil?
30
+ 1.upto(@workbook.external_links.size-1) do |link|
31
+ xml.Relationship('Id'=>'rId'+i.to_s,
32
+ 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink",
33
+ 'Target'=>"externalLinks/externalLink#{link}.xml"
34
+ )
35
+ i+=1
36
+ end
37
+ end
38
+ xml.Relationship('Id'=>'rId'+i.to_s,
39
+ 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
40
+ 'Target'=>'theme/theme1.xml')
41
+ i += 1
42
+ xml.Relationship('Id'=>'rId'+i.to_s,
43
+ 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
44
+ 'Target'=>'styles.xml')
45
+ i+=1
46
+ xml.Relationship('Id'=>'rId'+i.to_s,
47
+ 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
48
+ 'Target'=>'sharedStrings.xml')
49
+ }
50
+ end
51
+ contents = builder.to_xml
52
+ contents = contents.gsub(/\n/,'')
53
+ contents = contents.gsub(/>(\s)+</,'><')
54
+ contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
55
+ contents
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,77 @@
1
+ # require File.expand_path(File.join(File.dirname(__FILE__),'workbook'))
2
+ # require File.expand_path(File.join(File.dirname(__FILE__),'worksheet'))
3
+ # require File.expand_path(File.join(File.dirname(__FILE__),'cell'))
4
+ # require File.expand_path(File.join(File.dirname(__FILE__),'color'))
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+
8
+ module RubyXL
9
+ module Writer
10
+ class WorkbookWriter
11
+ attr_accessor :dirpath, :filepath, :workbook
12
+
13
+ def initialize(dirpath, wb)
14
+ @dirpath = dirpath
15
+ @workbook = wb
16
+ @filepath = dirpath + '/xl/workbook.xml'
17
+ end
18
+
19
+ def write()
20
+ builder = Nokogiri::XML::Builder.new do |xml|
21
+ xml.workbook('xmlns'=>"http://schemas.openxmlformats.org/spreadsheetml/2006/main",
22
+ 'xmlns:r'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships") {
23
+ #attributes out of order here
24
+ xml.fileVersion('appName'=>'xl', 'lastEdited'=>'4','lowestEdited'=>'4','rupBuild'=>'4505')
25
+ #TODO following line - date 1904? check if mac only
26
+ xml.workbookPr('date1904'=>@workbook.date1904.to_s, 'showInkAnnotation'=>'0', 'autoCompressPictures'=>'0')
27
+ xml.bookViews {
28
+ #attributes out of order here
29
+ xml.workbookView('xWindow'=>'-20', 'yWindow'=>'-20',
30
+ 'windowWidth'=>'21600','windowHeight'=>'13340','tabRatio'=>'500')
31
+ }
32
+ index = 0
33
+ xml.sheets {
34
+ @workbook.worksheets.each_with_index do |sheet,i|
35
+ xml.sheet('name'=>sheet.sheet_name, 'sheetId'=>(i+1).to_s(),
36
+ 'r:id'=>'rId'+(i+1).to_s())
37
+ index = i+1
38
+ end
39
+ }
40
+ unless @workbook.external_links.nil?
41
+ xml.externalReferences {
42
+ index.upto(@workbook.external_links.size-1) do |id|
43
+ xml.externalReference('r:id'=>"rId#{id+index}")
44
+ end
45
+ }
46
+ end
47
+ # unless @workbook.definedNames.nil?
48
+ # xml.definedNames {
49
+ # @workbook.definedNames.each do |name|
50
+ # xml.definedName('name'=>name[:attributes][:name]) {
51
+ # # name[:]
52
+ # }
53
+ # end
54
+ # }
55
+ # end
56
+
57
+ #TODO see if this changes with formulas
58
+ #attributes out of order here
59
+ xml.calcPr('calcId'=>'130407', 'concurrentCalc'=>'0')
60
+ xml.extLst {
61
+ xml.ext('xmlns:mx'=>"http://schemas.microsoft.com/office/mac/excel/2008/main",
62
+ 'uri'=>"http://schemas.microsoft.com/office/mac/excel/2008/main") {
63
+ xml['mx'].ArchID('Flags'=>'2')
64
+ }
65
+ }
66
+ }
67
+ end
68
+ contents = builder.to_xml
69
+ contents = contents.gsub(/\n/,'')
70
+ contents = contents.gsub(/>(\s)+</,'><')
71
+ contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
72
+
73
+ contents
74
+ end
75
+ end
76
+ end
77
+ end