listen360-rubyXL 1.2.10.1

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