axlsx 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Axlsx: Office Open XML Spreadsheet Generation
2
2
  ====================================
3
3
  [![Build Status](https://secure.travis-ci.org/randym/axlsx.png)](http://travis-ci.org/randym/axlsx/)
4
+
5
+ If you are using axlsx for comercial purposes, or just want to show your
6
+ appreciation for the gem, please don't hesitate to make a donation.
7
+
4
8
  [![Click here to lend your support to: axlsx and make a donation at www.pledgie.com !](http://www.pledgie.com/campaigns/17814.png?skin_name=chrome)](http://www.pledgie.com/campaigns/17814)
5
9
 
6
10
  **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
@@ -17,7 +21,7 @@ Axlsx: Office Open XML Spreadsheet Generation
17
21
 
18
22
  **License**: MIT License
19
23
 
20
- **Latest Version**: 1.2.2
24
+ **Latest Version**: 1.2.3
21
25
 
22
26
  **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
23
27
 
@@ -25,7 +29,7 @@ Axlsx: Office Open XML Spreadsheet Generation
25
29
 
26
30
  **Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
27
31
 
28
- **Release Date**: August 27th 2012
32
+ **Release Date**: September 8th 2012
29
33
 
30
34
  If you are working in rails, or with active record see:
31
35
  * http://github.com/randym/acts_as_xlsx
@@ -145,6 +149,11 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
145
149
 
146
150
  #Change log
147
151
  ---------
152
+ - **September.8.12**: 1.2.3
153
+ - enhance exponential float/bigdecimal values rendering as strings intead
154
+ of 'numbers' in excel.
155
+ - added support for :none option on chart axis labels
156
+ - added support for paper_size option on worksheet.page_setup
148
157
  - **August.27.12**: 1.2.2
149
158
  - minor patch for auto-filters
150
159
  - minor documentation improvements.
@@ -24,6 +24,8 @@ end
24
24
  chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob'
25
25
  chart.d_lbls.show_val = true
26
26
  chart.d_lbls.show_cat_name = true
27
+ chart.catAxis.tick_lbl_pos = :none
28
+
27
29
  end
28
30
  end
29
31
 
@@ -38,6 +40,8 @@ end
38
40
  chart.catAxis.label_rotation = 45
39
41
  chart.d_lbls.d_lbl_pos = :outEnd
40
42
  chart.d_lbls.show_val = true
43
+
44
+ chart.catAxis.tick_lbl_pos = :none
41
45
  end
42
46
  end
43
47
 
Binary file
Binary file
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'axlsx'
3
+ xls = Axlsx::Package.new
4
+ wb = xls.workbook
5
+ wb.add_worksheet do |ws|
6
+ # Excel does not currently follow the specification and will ignore paper_width and paper_height so if you need
7
+ # to for a paper size, be sure to set :paper_size
8
+ ws.page_setup.set :paper_width => "210mm", :paper_size => 10, :paper_height => "297mm", :orientation => :landscape
9
+ ws.add_row %w(AXLSX is cool)
10
+ end
11
+ xls.serialize "page_setup.xlsx"
Binary file
@@ -0,0 +1 @@
1
+ ,,,,,
@@ -0,0 +1,10 @@
1
+ require 'axlsx'
2
+
3
+ package = Axlsx::Package.new
4
+ package.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
5
+ sheet.add_row ["First Column", "Second", "Third"]
6
+ sheet.add_row [1, 2, 3]
7
+ end
8
+ package.serialize 'basics.xlsx'
9
+
10
+
@@ -0,0 +1,14 @@
1
+ require 'axlsx'
2
+ package = Axlsx::Package.new
3
+ workbook = package.workbook
4
+
5
+ workbook.add_worksheet(:name => "Image with Hyperlink") do |sheet|
6
+ img = File.expand_path('../image1.jpeg', __FILE__)
7
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
8
+ image.width=720
9
+ image.height=666
10
+ image.hyperlink.tooltip = "Labeled Link"
11
+ image.start_at 2, 2
12
+ end
13
+ end
14
+
@@ -0,0 +1,19 @@
1
+ require 'axlsx'
2
+ package = Axlsx::Package.new
3
+ workbook = package.workbook
4
+
5
+ workbook.styles do |s|
6
+
7
+ black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
8
+ blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
9
+
10
+ wb.add_worksheet(:name => "Styles") do |sheet|
11
+
12
+ # Applies the black_cell style to the first and third cell, and the blue_cell style to the second.
13
+ sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
14
+
15
+ # Applies the thin border to all three cells
16
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
17
+ end
18
+ end
19
+
@@ -102,7 +102,7 @@ module Axlsx
102
102
 
103
103
  # the position of the tick labels
104
104
  # must be one of [:nextTo, :high, :low1]
105
- def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low], v; @tick_lbl_pos = v; end
105
+ def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v; @tick_lbl_pos = v; end
106
106
  alias :tickLblPos= :tick_lbl_pos=
107
107
 
108
108
  # The number format format code for this axis
@@ -242,7 +242,6 @@ module Axlsx
242
242
  # @private
243
243
  def content_types
244
244
  c_types = base_content_types
245
-
246
245
  workbook.drawings.each do |drawing|
247
246
  c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
248
247
  :ContentType => DRAWING_CT)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
3
  # The current version
4
- VERSION="1.2.2"
4
+ VERSION="1.2.3"
5
5
  end
@@ -380,7 +380,7 @@ module Axlsx
380
380
  :boolean
381
381
  elsif v.to_s.match(/\A[+-]?\d+?\Z/) #numeric
382
382
  :integer
383
- elsif v.to_s.match(/\A[+-]?\d+\.\d+?\Z/) #float
383
+ elsif v.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/) #float
384
384
  :float
385
385
  else
386
386
  :string
@@ -20,11 +20,11 @@ module Axlsx
20
20
  # * useFirstPageNumber
21
21
  # * usePrinterDefaults
22
22
  # * verticalDpi
23
-
23
+
24
24
  # Number of vertical pages to fit on.
25
25
  # @note PageSetup#fit_to is the recomended way to manage page fitting as only specifying one of fit_to_width/fit_to_height will result in the counterpart
26
26
  # being set to 1.
27
- # @return [Integer]
27
+ # @return [Integer]
28
28
  attr_reader :fit_to_height
29
29
 
30
30
  # Number of horizontal pages to fit on.
@@ -36,7 +36,7 @@ module Axlsx
36
36
  # Orientation of the page (:default, :landscape, :portrait)
37
37
  # @return [Symbol]
38
38
  attr_reader :orientation
39
-
39
+
40
40
  # Height of paper (string containing a number followed by a unit identifier: "297mm", "11in")
41
41
  # @return [String]
42
42
  attr_reader :paper_height
@@ -44,11 +44,138 @@ module Axlsx
44
44
  # Width of paper (string containing a number followed by a unit identifier: "210mm", "8.5in")
45
45
  # @return [String]
46
46
  attr_reader :paper_width
47
-
47
+
48
48
  # Print scaling (percent value, given as integer ranging from 10 to 400)
49
49
  # @return [Integer]
50
50
  attr_reader :scale
51
51
 
52
+ # The paper size to use in printing
53
+ #1 = Letter paper (8.5 in. by 11 in.)
54
+ #2 = Letter small paper (8.5 in. by 11 in.)
55
+ #3 = Tabloid paper (11 in. by 17 in.)
56
+ #4 = Ledger paper (17 in. by 11 in.)
57
+ #5 = Legal paper (8.5 in. by 14 in.)
58
+ #6 = Statement paper (5.5 in. by 8.5 in.)
59
+ #7 = Executive paper (7.25 in. by 10.5 in.)
60
+ #8 = A3 paper (297 mm by 420 mm)
61
+ #9 = A4 paper (210 mm by 297 mm)
62
+ #10 = A4 small paper (210 mm by 297 mm)
63
+ #11 = A5 paper (148 mm by 210 mm)
64
+ #12 = B4 paper (250 mm by 353 mm)
65
+ #13 = B5 paper (176 mm by 250 mm)
66
+ #14 = Folio paper (8.5 in. by 13 in.)
67
+ #15 = Quarto paper (215 mm by 275 mm)
68
+ #16 = Standard paper (10 in. by 14 in.)
69
+ #17 = Standard paper (11 in. by 17 in.)
70
+ #18 = Note paper (8.5 in. by 11 in.)
71
+ #19 = #9 envelope (3.875 in. by 8.875 in.)
72
+ #20 = #10 envelope (4.125 in. by 9.5 in.)
73
+ #21 = #11 envelope (4.5 in. by 10.375 in.)
74
+ #22 = #12 envelope (4.75 in. by 11 in.)
75
+ #23 = #14 envelope (5 in. by 11.5 in.) 24 = C paper (17 in. by 22 in.)
76
+ #25 = D paper (22 in. by 34 in.)
77
+ #26 = E paper (34 in. by 44 in.)
78
+ #27 = DL envelope (110 mm by 220 mm)
79
+ #28 = C5 envelope (162 mm by 229 mm)
80
+ #29 = C3 envelope (324 mm by 458 mm)
81
+ #30 = C4 envelope (229 mm by 324 mm)
82
+ #31 = C6 envelope (114 mm by 162 mm)
83
+ #32 = C65 envelope (114 mm by 229 mm)
84
+ #33 = B4 envelope (250 mm by 353 mm)
85
+ #34 = B5 envelope (176 mm by 250 mm)
86
+ #35 = B6 envelope (176 mm by 125 mm)
87
+ #36 = Italy envelope (110 mm by 230 mm)
88
+ #37 = Monarch envelope (3.875 in. by 7.5 in.). 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
89
+ #39 = US standard fanfold (14.875 in. by 11 in.)
90
+ #40 = German standard fanfold (8.5 in. by 12 in.)
91
+ #41 = German legal fanfold (8.5 in. by 13 in.)
92
+ #42 = ISO B4 (250 mm by 353 mm)
93
+ #43 = Japanese double postcard (200 mm by 148 mm)
94
+ #44 = Standard paper (9 in. by 11 in.)
95
+ #45 = Standard paper (10 in. by 11 in.)
96
+ #46 = Standard paper (15 in. by 11 in.)
97
+ #47 = Invite envelope (220 mm by 220 mm)
98
+ #50 = Letter extra paper (9.275 in. by 12 in.)
99
+ #51 = Legal extra paper (9.275 in. by 15 in.)
100
+ #52 = Tabloid extra paper (11.69 in. by 18 in.)
101
+ #53 = A4 extra paper (236 mm by 322 mm)
102
+ #54 = Letter transverse paper (8.275 in. by 11 in.)
103
+ #55 = A4 transverse paper (210 mm by 297 mm)
104
+ #56 = Letter extra transverse paper (9.275 in. by 12 in.)
105
+ #57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
106
+ #58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
107
+ #59 = Letter plus paper (8.5 in. by 12.69 in.)
108
+ #60 = A4 plus paper (210 mm by 330 mm)
109
+ #61 = A5 transverse paper (148 mm by 210 mm)
110
+ #62 = JIS B5 transverse paper (182 mm by 257 mm)
111
+ #63 = A3 extra paper (322 mm by 445 mm)
112
+ #64 = A5 extra paper (174 mm by 235 mm)
113
+ #65 = ISO B5 extra paper (201 mm by 276 mm)
114
+ #66 = A2 paper (420 mm by 594 mm)
115
+ #67 = A3 transverse paper (297 mm by 420 mm)
116
+ #68 = A3 extra transverse paper (322 mm by 445 mm)
117
+ #69 = Japanese Double Postcard (200 mm x 148 mm)
118
+ #70 = A6 (105 mm x 148 mm
119
+ #71 = Japanese Envelope Kaku #2
120
+ #72 = Japanese Envelope Kaku #3
121
+ #73 = Japanese Envelope Chou #3
122
+ #74 = Japanese Envelope Chou #4
123
+ #75 = Letter Rotated (11in x 8 1/2 11 in)
124
+ #76 = A3 Rotated (420 mm x 297 mm)
125
+ #77 = A4 Rotated (297 mm x 210 mm)
126
+ #78 = A5 Rotated (210 mm x 148 mm)
127
+ #79 = B4 (JIS) Rotated (364 mm x 257 mm)
128
+ #80 = B5 (JIS) Rotated (257 mm x 182 mm)
129
+ #81 = Japanese Postcard Rotated (148 mm x 100 mm)
130
+ #82 = Double Japanese Postcard Rotated (148 mm x 200 mm)
131
+ #83 = A6 Rotated (148 mm x 105 mm)
132
+ #84 = Japanese Envelope Kaku #2 Rotated
133
+ #85 = Japanese Envelope Kaku #3 Rotated
134
+ #86 = Japanese Envelope Chou #3 Rotated
135
+ #87 = Japanese Envelope Chou #4 Rotated
136
+ #88 = B6 (JIS) (128 mm x 182 mm)
137
+ #89 = B6 (JIS) Rotated (182 mm x 128 mm)
138
+ #90 = (12 in x 11 in)
139
+ #91 = Japanese Envelope You #4
140
+ #92 = Japanese Envelope You #4 Rotated
141
+ #93 = PRC 16K (146 mm x 215 mm)
142
+ #94 = PRC 32K (97 mm x 151 mm)
143
+ #95 = PRC 32K(Big) (97 mm x 151 mm)
144
+ #96 = PRC Envelope #1 (102 mm x 165 mm)
145
+ #97 = PRC Envelope #2 (102 mm x 176 mm)
146
+ #98 = PRC Envelope #3 (125 mm x 176 mm)
147
+ #99 = PRC Envelope #4 (110 mm x 208 mm)
148
+ #100 = PRC Envelope #5 (110 mm x 220 mm)
149
+ #101 = PRC Envelope #6 (120 mm x 230 mm)
150
+ #102 = PRC Envelope #7 (160 mm x 230 mm)
151
+ #103 = PRC Envelope #8 (120 mm x 309 mm)
152
+ #104 = PRC Envelope #9 (229 mm x 324 mm)
153
+ #105 = PRC Envelope #10 (324 mm x 458 mm)
154
+ #106 = PRC 16K Rotated
155
+ #107 = PRC 32K Rotated
156
+ #108 = PRC 32K(Big) Rotated
157
+ #109 = PRC Envelope #1 Rotated (165 mm x 102 mm)
158
+ #110 = PRC Envelope #2 Rotated (176 mm x 102 mm)
159
+ #111 = PRC Envelope #3 Rotated (176 mm x 125 mm)
160
+ #112 = PRC Envelope #4 Rotated (208 mm x 110 mm)
161
+ #113 = PRC Envelope #5 Rotated (220 mm x 110 mm)
162
+ #114 = PRC Envelope #6 Rotated (230 mm x 120 mm)
163
+ #115 = PRC Envelope #7 Rotated (230 mm x 160 mm)
164
+ #116 = PRC Envelope #8 Rotated (309 mm x 120 mm)
165
+ #117 = PRC Envelope #9 Rotated (324 mm x 229 mm)
166
+ #118 = PRC Envelope #10 Rotated (458 mm x 324 mm)
167
+ # @return [Integer]
168
+ attr_reader :paper_size
169
+
170
+
171
+ # Sets the paper size for printing.
172
+ # @see PageSetup#paper_size
173
+ # @return integer
174
+ def paper_size=(size)
175
+ RestrictionValidator.validate 'paper_size', (1..118), size
176
+ @paper_size = size
177
+ end
178
+
52
179
  # Creates a new PageSetup object
53
180
  # @option options [Integer] fit_to_height Number of vertical pages to fit on
54
181
  # @option options [Integer] fit_to_width Number of horizontal pages to fit on
@@ -56,6 +183,7 @@ module Axlsx
56
183
  # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in")
57
184
  # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in")
58
185
  # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400)
186
+ # @option options [Integer] paper_size - the size of paper to use
59
187
  def initialize(options = {})
60
188
  set(options)
61
189
  end
@@ -80,7 +208,7 @@ module Axlsx
80
208
  def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
81
209
  # @see scale
82
210
  def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
83
-
211
+
84
212
  # convenience method to achieve sanity when setting fit_to_width and fit_to_height
85
213
  # as they both default to 1 if only their counterpart is specified.
86
214
  # @note This method will overwrite any value you explicitly set via the fit_to_height or fit_to_width methods.
@@ -97,8 +225,8 @@ module Axlsx
97
225
  # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.
98
226
  # @return [Boolean]
99
227
  def fit_to_page?
100
- # is there some better what to express this?
101
- (fit_to_width != nil || fit_to_height != nil)
228
+ # is there some better what to express this?
229
+ (fit_to_width != nil || fit_to_height != nil)
102
230
  end
103
231
 
104
232
  # Serializes the page settings element.
@@ -1,4 +1,5 @@
1
1
  module Axlsx
2
+
2
3
  #A collection of hyperlink objects for a worksheet
3
4
  class WorksheetHyperlinks < SimpleTypedList
4
5
 
@@ -18,6 +19,8 @@ module Axlsx
18
19
  @list.last
19
20
  end
20
21
 
22
+ # The relationships required by this collection's hyperlinks
23
+ # @return Array
21
24
  def relationships
22
25
  return [] if empty?
23
26
  map { |hyperlink| hyperlink.relationship }
@@ -60,7 +60,7 @@ class TestCell < Test::Unit::TestCase
60
60
  assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
61
61
  assert_nothing_raised("type can be changed") { @c.type = :string }
62
62
  assert_equal(@c.value, "1.0", "changing type casts the value")
63
-
63
+ assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
64
64
  assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
65
65
  assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
66
66
  assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
@@ -88,6 +88,7 @@ class TestCell < Test::Unit::TestCase
88
88
  assert_equal(@c.send(:cell_type_from_value, -1), :integer)
89
89
  assert_equal(@c.send(:cell_type_from_value, true), :boolean)
90
90
  assert_equal(@c.send(:cell_type_from_value, false), :boolean)
91
+ assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
91
92
  end
92
93
 
93
94
  def test_cast_value
@@ -44,6 +44,11 @@ class TestPageSetup < Test::Unit::TestCase
44
44
  assert_equal(50, @ps.scale)
45
45
  end
46
46
 
47
+ def test_paper_size
48
+ assert_raise(ArgumentError) { @ps.paper_size = 119 }
49
+ assert_nothing_raised { @ps.paper_size = 10 }
50
+ end
51
+
47
52
  def test_set_some_values
48
53
  @ps.set(:fit_to_width => 2, :orientation => :portrait)
49
54
  assert_equal(2, @ps.fit_to_width)
@@ -58,7 +63,7 @@ class TestPageSetup < Test::Unit::TestCase
58
63
  assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
59
64
  assert(@ps.fit_to_page? == false)
60
65
  end
61
-
66
+
62
67
  def test_with_height_fit_to_page?
63
68
  assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
64
69
  @ps.set(:fit_to_height => 1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -277,6 +277,7 @@ files:
277
277
  - examples/example_streamed.xlsx
278
278
  - examples/extractive.pdf
279
279
  - examples/extractive.rb
280
+ - examples/extractive.xlsx
280
281
  - examples/hyperlinks.rb
281
282
  - examples/hyperlinks.xlsx
282
283
  - examples/image1.gif
@@ -284,14 +285,21 @@ files:
284
285
  - examples/image1.jpg
285
286
  - examples/image1.png
286
287
  - examples/no-use_autowidth.xlsx
288
+ - examples/page_setup.rb
289
+ - examples/page_setup.xlsx
287
290
  - examples/sample.png
288
291
  - examples/scraping_html.rb
289
292
  - examples/shared_strings_example.xlsx
290
293
  - examples/sheet_protection.rb
291
294
  - examples/sheet_view.rb
295
+ - examples/skydrive/axlsx.csv
292
296
  - examples/skydrive/axlsx.xlsx
293
297
  - examples/skydrive/real_example.rb
298
+ - examples/sprk2012/basics.rb
299
+ - examples/sprk2012/images.rb
300
+ - examples/sprk2012/styles.rb
294
301
  - examples/two_cell_anchor_image.rb
302
+ - examples/~$extractive.xlsx
295
303
  - LICENSE
296
304
  - README.md
297
305
  - Rakefile
@@ -411,7 +419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
419
  version: '0'
412
420
  segments:
413
421
  - 0
414
- hash: 3191615889138307722
422
+ hash: 1228635287654264801
415
423
  requirements: []
416
424
  rubyforge_project:
417
425
  rubygems_version: 1.8.24