xlsx 0.1 → 0.3

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/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
data/lib/xlsx/cell.rb CHANGED
@@ -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
@@ -44,10 +44,10 @@ module XLSX
44
44
  col_name = ''
45
45
  else
46
46
  c = col_number / 26
47
- col_name = (?A + c - 1).chr
47
+ col_name = (?A.ord + c - 1).chr
48
48
  col_number = col_number % 26
49
49
  end
50
- col_name += (?A + col_number).chr
50
+ col_name += (?A.ord + col_number).chr
51
51
  "#{col_name}#{row_number + 1}"
52
52
  end
53
53
  end
data/lib/xlsx/row.rb CHANGED
@@ -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
data/lib/xlsx/workbook.rb CHANGED
@@ -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
data/lib/xlsx.rb CHANGED
@@ -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
metadata CHANGED
@@ -1,47 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xlsx
3
- version: !ruby/object:Gem::Version
4
- version: "0.1"
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Brian Buchanan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-10-21 00:00:00 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: builder
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
16
+ requirement: &2153669420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 2.1.2
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: rubyzip
27
22
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
23
+ prerelease: false
24
+ version_requirements: *2153669420
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubyzip
27
+ requirement: &2153668780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
33
32
  version: 0.9.1
34
- version:
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2153668780
35
36
  description: XLSX is a Ruby library for writing simple XLSX-format Excel documents.
36
37
  email: bwb@holo.org
37
38
  executables: []
38
-
39
39
  extensions: []
40
-
41
- extra_rdoc_files:
40
+ extra_rdoc_files:
42
41
  - README
43
42
  - LICENSE
44
- files:
43
+ files:
45
44
  - README
46
45
  - LICENSE
47
46
  - lib/xlsx.rb
@@ -49,34 +48,30 @@ files:
49
48
  - lib/xlsx/worksheet.rb
50
49
  - lib/xlsx/row.rb
51
50
  - lib/xlsx/cell.rb
52
- has_rdoc: true
53
51
  homepage: http://github.com/bwbuchanan/xlsx
54
52
  licenses: []
55
-
56
53
  post_install_message:
57
- rdoc_options:
54
+ rdoc_options:
58
55
  - --inline-source
59
56
  - --charset=UTF-8
60
- require_paths:
57
+ require_paths:
61
58
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- version:
68
- required_rubygems_version: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: "0"
73
- version:
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
74
71
  requirements: []
75
-
76
72
  rubyforge_project:
77
- rubygems_version: 1.3.5
73
+ rubygems_version: 1.8.5
78
74
  signing_key:
79
75
  specification_version: 2
80
76
  summary: XLSX is a Ruby library for writing simple XLSX-format Excel documents.
81
77
  test_files: []
82
-