xlsx 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ Copyright (C) 2010-2011 Brian Buchanan. All rights reserved.
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ # Copyright (C) 2009-2011 Brian Buchanan. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ # Copyright (C) 2009-2011 Brian Buchanan. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ # Copyright (C) 2009-2011 Brian Buchanan. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ # Copyright (C) 2009-2011 Brian Buchanan. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
@@ -45,6 +45,7 @@ module XLSX
45
45
  def write(filename=nil)
46
46
  @strings_count = 0
47
47
  @strings = []
48
+ @strings_idx = {}
48
49
 
49
50
  filename ||= @filename
50
51
  File.unlink(filename) if File.exists?(filename)
@@ -63,12 +64,19 @@ module XLSX
63
64
 
64
65
  zipfile.get_output_stream("xl/sharedStrings.xml") { |f| write_shared_strings(f) }
65
66
  end
67
+
68
+ @strings_count = nil
69
+ @strings = nil
70
+ @strings_idx = nil
71
+
72
+ true
66
73
  end
67
74
 
68
75
  private
69
76
  def write_content_types(f)
70
77
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
71
- x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8'
78
+ x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
79
+ x << "\r\n"
72
80
  x.Types :xmlns => XMLNS_CONTENT_TYPES do |types|
73
81
  types.Override :PartName => '/docProps/app.xml', :ContentType => CT_EXTPROP
74
82
  1.upto(@sheets.size) do |sheet_no|
@@ -78,18 +86,21 @@ module XLSX
78
86
  types.Override :PartName => '/docProps/core.xml', :ContentType => CT_COREPROP
79
87
  types.Default :Extension => 'xml', :ContentType => 'application/xml'
80
88
  types.Override :PartName => '/xl/styles.xml', :ContentType => CT_SS_STYLES
89
+ #types.Override :PartName => '/xl/theme/theme1.xml', :ContentType => CT_THEME
81
90
  types.Override :PartName => '/xl/sharedStrings.xml', :ContentType => CT_SS_SHAREDSTRINGS
82
91
  types.Default :Extension => 'rels', :ContentType => CT_RELATIONSHIPS
92
+ #types.Default :Extension => 'jpeg, :ContentType => CT_JPEG
83
93
  end
84
94
  end
85
95
 
86
96
  def write_root_rels(f)
87
97
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
88
98
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
99
+ x << "\r\n"
89
100
  x.Relationships :xmlns => XMLNS_RELATIONSHIPS do |rels|
90
- rels.Relationship :Id => 'rId3', :Type => REL_TYPE_EXTPROP, :Target => 'docProps/app.xml'
91
101
  rels.Relationship :Id => 'rId1', :Type => REL_TYPE_OFFICEDOC, :Target => 'xl/workbook.xml'
92
102
  rels.Relationship :Id => 'rId2', :Type => REL_TYPE_COREPROP, :Target => 'docProps/core.xml'
103
+ rels.Relationship :Id => 'rId3', :Type => REL_TYPE_EXTPROP, :Target => 'docProps/app.xml'
93
104
  end
94
105
  end
95
106
 
@@ -98,6 +109,7 @@ module XLSX
98
109
 
99
110
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
100
111
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
112
+ x << "\r\n"
101
113
  x.cp :coreProperties, 'xmlns:cp' => XMLNS_COREPROP, 'xmlns:dc' => XMLNS_DC,
102
114
  'xmlns:dcterms' => XMLNS_DCTERMS, 'xmlns:dcmitype' => XMLNS_DCMITYPE,
103
115
  'xmlns:xsi' => XMLNS_XSI do |cp|
@@ -113,6 +125,7 @@ module XLSX
113
125
  def write_app_properties(f)
114
126
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
115
127
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
128
+ x << "\r\n"
116
129
  x.Properties 'xmlns' => XMLNS_EXTPROP, 'xmlns:vt' => XMLNS_VT do |prop|
117
130
  prop.Application 'Microsoft Macintosh Excel'
118
131
  prop.DocSecurity '0'
@@ -145,6 +158,7 @@ module XLSX
145
158
  def write_workbook_rels(f)
146
159
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
147
160
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
161
+ x << "\r\n"
148
162
  x.Relationships :xmlns => XMLNS_RELATIONSHIPS do |rels|
149
163
  id = 1
150
164
  1.upto(@sheets.size) do |sheet_no|
@@ -153,8 +167,6 @@ module XLSX
153
167
  end
154
168
  rels.Relationship :Id => "rId#{id}", :Type => REL_TYPE_STYLES, :Target => 'styles.xml'
155
169
  id += 1
156
- rels.Relationship :Id => "rId#{id}", :Type => REL_TYPE_CONNECTIONS, :Target => 'connections.xml'
157
- id += 1
158
170
  rels.Relationship :Id => "rId#{id}", :Type => REL_TYPE_SHAREDSTRINGS, :Target => 'sharedStrings.xml'
159
171
  end
160
172
  end
@@ -162,11 +174,12 @@ module XLSX
162
174
  def write_workbook(f)
163
175
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
164
176
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
177
+ x << "\r\n"
165
178
  x.workbook :xmlns => XMLNS_SSXML_MAIN, 'xmlns:r' => XMLNS_OD_RELATIONSHIPS do |wb|
166
179
  wb.fileVersion :appName => 'xl', :lastEdited => '4', :lowestEdited => '4', :rupBuild => '4505'
167
180
  wb.workbookPr :date1904 => '1', :showInkAnnotation => '0', :autoCompressPictures => '0'
168
181
  wb.bookViews do |bv|
169
- bv.workbookView :tabRatio => '500', :xWindow => '-20', :yWindow => '-20', :windowWidth => '47120', :windowHeight => '30680', :activeTab => '1'
182
+ bv.workbookView :xWindow => '-20', :yWindow => '-20', :windowWidth => '47120', :windowHeight => '30680', :tabRatio => '500', :activeTab => '1'
170
183
  end
171
184
  x.sheets do |sheets|
172
185
  1.upto(@sheets.count) do |sheet_no|
@@ -185,27 +198,29 @@ module XLSX
185
198
  end
186
199
 
187
200
  def write_worksheet(sheet, f)
188
- min_col = sheet.rows.map { |r| r.min_col }.min + 1
189
- max_col = sheet.rows.map { |r| r.max_col }.max + 1
201
+ min_col = sheet.min_col + 1
202
+ max_col = sheet.max_col + 1
190
203
  spans = "#{min_col}:#{max_col}"
191
- dimension = "#{XLSX::Cell.cell_name(sheet.min_row + 1, min_col)}:#{XLSX::Cell.cell_name(sheet.max_row + 1, max_col)}"
204
+ top_left = "#{XLSX::Cell.cell_name(sheet.min_row, min_col - 1)}"
205
+ bottom_right = "#{XLSX::Cell.cell_name(sheet.max_row, max_col - 1)}"
206
+ dimension = "#{top_left}:#{bottom_right}"
192
207
 
193
208
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
194
209
  x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
195
- f.write("\n")
196
- x.worksheet 'xmlns:mc' => XMLNS_MARKUP_COMPATIBILITY,
197
- 'mc:PreserveAttributes' => 'mv:*',
198
- 'mc:Ignorable' => 'mv',
210
+ x << "\r\n"
211
+ x.worksheet 'xmlns' => XMLNS_SSXML_MAIN,
199
212
  'xmlns:r' => XMLNS_OD_RELATIONSHIPS,
213
+ 'xmlns:mc' => XMLNS_MARKUP_COMPATIBILITY,
200
214
  'xmlns:mv' => XMLNS_MAC_VML,
201
- 'xmlns' => XMLNS_SSXML_MAIN do |ws|
215
+ 'mc:Ignorable' => 'mv',
216
+ 'mc:PreserveAttributes' => 'mv:*' do |ws|
202
217
  ws.dimension :ref => dimension
203
218
  ws.sheetViews do |sviews|
204
219
  sviews.sheetView :workbookViewId => '0' do |sv|
205
- sv.selection :activeCell => 'A1', :sqref => 'A1'
220
+ sv.selection :activeCell => top_left, :sqref => top_left
206
221
  end
207
222
  end
208
- ws.sheetFormatPr :defaultRowHeight => '13', :baseColWidth => '10'
223
+ ws.sheetFormatPr :baseColWidth => '10', :defaultRowHeight => '13'
209
224
  ws.sheetData do |sd|
210
225
  sheet.rows.each do |row|
211
226
  cells = row.to_a
@@ -219,9 +234,19 @@ module XLSX
219
234
  when Numeric
220
235
  c.v(value.to_s)
221
236
  else
222
- @strings << value.to_s
237
+ str = value.to_s
238
+ if @strings_idx[str]
239
+ c.v(@strings_idx[str])
240
+ else
241
+ # Duplicate the value before freezing it, if necessary.
242
+ str = str.dup if value.is_a?(String)
243
+
244
+ str.freeze
245
+ @strings_idx[str] = @strings.size.to_s
246
+ c.v(@strings.size.to_s)
247
+ @strings << str
248
+ end
223
249
  @strings_count += 1
224
- c.v((@strings.size - 1).to_s)
225
250
  end
226
251
  end
227
252
  end
@@ -230,15 +255,15 @@ module XLSX
230
255
  end
231
256
  ws.sheetCalcPr :fullCalcOnLoad => '1'
232
257
  ws.phoneticPr :fontId => '1', :type => 'noConversion'
233
- ws.pageMargins :left => '0.75', :bottom => '1', :header => '0.5', :footer => '0.5', :right => '0.75', :top => '1'
234
- ws.pageSetup :horizontalDpi => '4294967292', :orientation => 'portrait', :verticalDpi => '4294967292'
258
+ ws.pageMargins :left => '0.75', :right => '0.75', :top => '1', :bottom => '1', :header => '0.5', :footer => '0.5'
235
259
  end
236
260
  end
237
261
 
238
262
  def write_shared_strings(f)
239
263
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
240
- x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8'
241
- x.sst :count => @strings_count, :uniqueCount => @strings.size, :xmlns => XMLNS_SSXML_MAIN do |sst|
264
+ x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
265
+ x << "\r\n"
266
+ x.sst :xmlns => XMLNS_SSXML_MAIN, :count => @strings_count, :uniqueCount => @strings.size do |sst|
242
267
  @strings.each do |string|
243
268
  sst.si do |si|
244
269
  si.t string
@@ -251,7 +276,8 @@ module XLSX
251
276
 
252
277
  def write_styles(f)
253
278
  x = Builder::XmlMarkup.new(:target => f, :indent => 0)
254
- x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8'
279
+ x.instruct! 'xml', :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes'
280
+ x << "\r\n"
255
281
  x.styleSheet :xmlns => XMLNS_SSXML_MAIN do |ss|
256
282
  ss.fonts :count => '2' do |fonts|
257
283
  fonts.font do |font|
@@ -277,10 +303,10 @@ module XLSX
277
303
  end
278
304
  end
279
305
  ss.cellStyleXfs :count => 1 do |cs|
280
- cs.xf :fontId => '0', :numFmtId => '0', :borderId => '0', :fillId => '0'
306
+ cs.xf :numFmtId => '0', :fontId => '0', :fillId => '0', :borderId => '0'
281
307
  end
282
308
  ss.cellXfs :count => 1 do |cs|
283
- cs.xf :fontId => '0', :numFmtId => '0', :borderId => '0', :xfId => '0', :fillId => '0'
309
+ cs.xf :numFmtId => '0', :fontId => '0', :fillId => '0', :borderId => '0', :xfId => '0'
284
310
  end
285
311
  ss.cellStyles :count => 1 do |cs|
286
312
  cs.cellStyle :name => 'Normal', :xfId => '0', :builtinId => '0'
@@ -313,6 +339,7 @@ module XLSX
313
339
  CT_SS_STYLES = 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'
314
340
  CT_SS_SHAREDSTRINGS = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'
315
341
  CT_RELATIONSHIPS = 'application/vnd.openxmlformats-package.relationships+xml'
342
+ CT_JPEG = 'image/jpeg'
316
343
 
317
344
  REL_TYPE_EXTPROP = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties'
318
345
  REL_TYPE_OFFICEDOC = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument'
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Brian Buchanan. All rights reserved.
1
+ # Copyright (C) 2009-2011 Brian Buchanan. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
@@ -34,6 +34,14 @@ module XLSX
34
34
  @max_row = 0
35
35
  end
36
36
 
37
+ def min_col
38
+ rows.map { |r| r.min_col }.min
39
+ end
40
+
41
+ def max_col
42
+ rows.map { |r| r.max_col }.max
43
+ end
44
+
37
45
  def row(row_number)
38
46
  @rows[row_number]
39
47
  end
metadata CHANGED
@@ -1,61 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xlsx
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- version: "0.2"
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ prerelease:
9
6
  platform: ruby
10
- authors:
7
+ authors:
11
8
  - Brian Buchanan
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
-
16
- date: 2010-10-18 00:00:00 -07:00
17
- default_executable:
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: builder
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153669420 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 1
30
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 2.1.2
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rubyzip
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153669420
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubyzip
27
+ requirement: &2153668780 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- - 9
45
- - 1
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
46
32
  version: 0.9.1
47
33
  type: :runtime
48
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *2153668780
49
36
  description: XLSX is a Ruby library for writing simple XLSX-format Excel documents.
50
37
  email: bwb@holo.org
51
38
  executables: []
52
-
53
39
  extensions: []
54
-
55
- extra_rdoc_files:
40
+ extra_rdoc_files:
56
41
  - README
57
42
  - LICENSE
58
- files:
43
+ files:
59
44
  - README
60
45
  - LICENSE
61
46
  - lib/xlsx.rb
@@ -63,38 +48,30 @@ files:
63
48
  - lib/xlsx/worksheet.rb
64
49
  - lib/xlsx/row.rb
65
50
  - lib/xlsx/cell.rb
66
- has_rdoc: true
67
51
  homepage: http://github.com/bwbuchanan/xlsx
68
52
  licenses: []
69
-
70
53
  post_install_message:
71
- rdoc_options:
54
+ rdoc_options:
72
55
  - --inline-source
73
56
  - --charset=UTF-8
74
- require_paths:
57
+ require_paths:
75
58
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
59
+ required_ruby_version: !ruby/object:Gem::Requirement
77
60
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
- version: "0"
84
- required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
66
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- segments:
90
- - 0
91
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
92
71
  requirements: []
93
-
94
72
  rubyforge_project:
95
- rubygems_version: 1.3.7
73
+ rubygems_version: 1.8.5
96
74
  signing_key:
97
75
  specification_version: 2
98
76
  summary: XLSX is a Ruby library for writing simple XLSX-format Excel documents.
99
77
  test_files: []
100
-