axlsx 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/CHANGELOG.md +14 -0
  2. data/Gemfile +3 -7
  3. data/Gemfile.lock +17 -8
  4. data/README.md +88 -59
  5. data/axlsx.gemspec +9 -3
  6. data/doc/Axlsx.html +482 -248
  7. data/doc/Axlsx/App.html +237 -159
  8. data/doc/Axlsx/Axis.html +75 -51
  9. data/doc/Axlsx/Bar3DChart.html +75 -53
  10. data/doc/Axlsx/BarSeries.html +45 -31
  11. data/doc/Axlsx/Border.html +70 -50
  12. data/doc/Axlsx/BorderPr.html +80 -62
  13. data/doc/Axlsx/CatAxis.html +62 -43
  14. data/doc/Axlsx/CatAxisData.html +23 -16
  15. data/doc/Axlsx/Cell.html +2022 -393
  16. data/doc/Axlsx/CellAlignment.html +103 -75
  17. data/doc/Axlsx/CellProtection.html +44 -30
  18. data/doc/Axlsx/CellStyle.html +66 -46
  19. data/doc/Axlsx/Chart.html +159 -108
  20. data/doc/Axlsx/Color.html +73 -52
  21. data/doc/Axlsx/ContentType.html +20 -14
  22. data/doc/Axlsx/Core.html +29 -20
  23. data/doc/Axlsx/DataTypeValidator.html +27 -19
  24. data/doc/Axlsx/Default.html +39 -27
  25. data/doc/Axlsx/Drawing.html +104 -70
  26. data/doc/Axlsx/Fill.html +33 -23
  27. data/doc/Axlsx/Font.html +132 -98
  28. data/doc/Axlsx/GradientFill.html +70 -48
  29. data/doc/Axlsx/GradientStop.html +31 -21
  30. data/doc/Axlsx/GraphicFrame.html +40 -27
  31. data/doc/Axlsx/Line3DChart.html +62 -43
  32. data/doc/Axlsx/LineSeries.html +37 -25
  33. data/doc/Axlsx/Marker.html +63 -43
  34. data/doc/Axlsx/NumFmt.html +79 -65
  35. data/doc/Axlsx/OneCellAnchor.html +78 -54
  36. data/doc/Axlsx/Override.html +39 -27
  37. data/doc/Axlsx/Package.html +103 -163
  38. data/doc/Axlsx/Parser.html +549 -0
  39. data/doc/Axlsx/PatternFill.html +66 -51
  40. data/doc/Axlsx/Pic.html +230 -123
  41. data/doc/Axlsx/PictureLocking.html +1159 -0
  42. data/doc/Axlsx/Pie3DChart.html +23 -16
  43. data/doc/Axlsx/PieSeries.html +44 -30
  44. data/doc/Axlsx/RegexValidator.html +14 -10
  45. data/doc/Axlsx/Relationship.html +40 -27
  46. data/doc/Axlsx/Relationships.html +20 -14
  47. data/doc/Axlsx/RestrictionValidator.html +25 -17
  48. data/doc/Axlsx/Row.html +73 -53
  49. data/doc/Axlsx/Scaling.html +46 -31
  50. data/doc/Axlsx/SerAxis.html +49 -33
  51. data/doc/Axlsx/Series.html +51 -35
  52. data/doc/Axlsx/SeriesTitle.html +14 -10
  53. data/doc/Axlsx/Styles.html +210 -156
  54. data/doc/Axlsx/TableStyle.html +47 -32
  55. data/doc/Axlsx/TableStyleElement.html +75 -61
  56. data/doc/Axlsx/TableStyles.html +42 -28
  57. data/doc/Axlsx/Title.html +36 -25
  58. data/doc/Axlsx/TwoCellAnchor.html +83 -58
  59. data/doc/Axlsx/ValAxis.html +35 -24
  60. data/doc/Axlsx/ValAxisData.html +13 -9
  61. data/doc/Axlsx/View3D.html +64 -43
  62. data/doc/Axlsx/Workbook.html +305 -147
  63. data/doc/Axlsx/Worksheet.html +567 -271
  64. data/doc/Axlsx/Xf.html +114 -77
  65. data/doc/_index.html +15 -1
  66. data/doc/class_list.html +1 -1
  67. data/doc/css/style.css +1 -1
  68. data/doc/file.LICENSE.html +25 -21
  69. data/doc/file.README.html +89 -66
  70. data/doc/index.html +89 -66
  71. data/doc/js/app.js +4 -4
  72. data/doc/method_list.html +717 -413
  73. data/doc/top-level-namespace.html +1 -1
  74. data/examples/example.rb +52 -25
  75. data/examples/follow_20111202.xlsx +0 -0
  76. data/lib/axlsx.rb +14 -1
  77. data/lib/axlsx/drawing/chart.rb +20 -4
  78. data/lib/axlsx/drawing/drawing.rb +1 -1
  79. data/lib/axlsx/drawing/pic.rb +5 -2
  80. data/lib/axlsx/drawing/picture_locking.rb +72 -0
  81. data/lib/axlsx/package.rb +9 -7
  82. data/lib/axlsx/stylesheet/color.rb +19 -9
  83. data/lib/axlsx/stylesheet/styles.rb +2 -0
  84. data/lib/axlsx/util/constants.rb +6 -0
  85. data/lib/axlsx/util/parser.rb +43 -0
  86. data/lib/axlsx/version.rb +1 -1
  87. data/lib/axlsx/workbook/workbook.rb +21 -1
  88. data/lib/axlsx/workbook/worksheet/cell.rb +159 -7
  89. data/lib/axlsx/workbook/worksheet/row.rb +4 -2
  90. data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -4
  91. data/test/drawing/tc_picture_locking.rb +73 -0
  92. data/test/rels/tc_relationships.rb +0 -1
  93. data/test/stylesheet/tc_styles.rb +0 -12
  94. data/test/tc_package.rb +5 -3
  95. data/test/workbook/tc_workbook.rb +7 -0
  96. data/test/workbook/worksheet/tc_cell.rb +102 -1
  97. data/test/workbook/worksheet/tc_worksheet.rb +17 -0
  98. metadata +79 -19
  99. data/doc/Axlsx/Ar.html +0 -196
  100. data/doc/Axlsx/Ar/ClassMethods.html +0 -188
  101. data/doc/Axlsx/Ar/InstanceMethods.html +0 -108
  102. data/doc/Axlsx/Ar/SingletonMethods.html +0 -312
@@ -94,7 +94,7 @@
94
94
  </div>
95
95
 
96
96
  <div id="footer">
97
- Generated on Wed Nov 30 08:53:53 2011 by
97
+ Generated on Mon Dec 5 14:21:23 2011 by
98
98
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
99
99
  0.7.3 (ruby-1.8.7).
100
100
  </div>
data/examples/example.rb CHANGED
@@ -9,7 +9,7 @@ if ARGV.size == 0 || ARGV.include?("1")
9
9
  p = Axlsx::Package.new
10
10
  p.workbook.add_worksheet do |sheet|
11
11
  sheet.add_row ["First", "Second", "Third"]
12
- sheet.add_row [1, 2, 3]
12
+ sheet.add_row [1, 2, Time.now]
13
13
  end
14
14
  p.serialize("example1.xlsx")
15
15
  end
@@ -18,26 +18,29 @@ if ARGV.size==0 || ARGV.include?("2")
18
18
 
19
19
  p = Axlsx::Package.new
20
20
  p.workbook.add_worksheet do |sheet|
21
+ sheet.add_row ["A Simple Bar Chart"]
21
22
  sheet.add_row ["First", "Second", "Third"]
22
23
  sheet.add_row [1, 2, 3]
23
- sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0,2], :end_at => [5, 15], :title=>"example 2: Chart") do |chart|
24
- chart.add_series :data=>sheet.rows.last.cells, :labels=> sheet.rows.first.cells
24
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17", :title=>sheet["A1"]) do |chart|
25
+ chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"]
25
26
  end
26
27
  end
27
28
  p.serialize("example2.xlsx")
29
+
28
30
  end
29
31
  #Generating A Pie Chart
30
32
  if ARGV.size==0 || ARGV.include?("3")
31
33
 
32
34
  p = Axlsx::Package.new
33
35
  p.workbook.add_worksheet do |sheet|
34
- sheet.add_row ["First", "Second", "Third"]
35
- sheet.add_row [1, 2, 3]
36
+ sheet.add_row ["First", "Second", "Third", "Fourth"]
37
+ sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
36
38
  sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=>"example 3: Pie Chart") do |chart|
37
- chart.add_series :data=>sheet.rows.last.cells, :labels=> sheet.rows.first.cells
39
+ chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
38
40
  end
39
41
  end
40
42
  p.serialize("example3.xlsx")
43
+
41
44
  end
42
45
 
43
46
  #Using Custom Styles
@@ -45,13 +48,14 @@ if ARGV.size==0 || ARGV.include?("4")
45
48
 
46
49
  p = Axlsx::Package.new
47
50
  wb = p.workbook
48
- black_cell = wb.styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz=>14, :alignment => { :horizontal=> :center }
49
- blue_cell = wb.styles.add_style :bg_color => "FF0000FF", :fg_color => "FFFFFFFF", :sz=>14, :alignment => { :horizontal=> :center }
51
+ black_cell = wb.styles.add_style :bg_color => "00", :fg_color => "FF", :sz=>14, :alignment => { :horizontal=> :center }
52
+ blue_cell = wb.styles.add_style :bg_color => "0000FF", :fg_color => "FF", :sz=>14, :alignment => { :horizontal=> :center }
50
53
  wb.add_worksheet do |sheet|
51
54
  sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
52
55
  sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
53
56
  end
54
57
  p.serialize("example4.xlsx")
58
+
55
59
  end
56
60
  #Using Custom Formatting and date1904
57
61
  if ARGV.size==0 || ARGV.include?("5")
@@ -80,6 +84,7 @@ if ARGV.size==0 || ARGV.include?("6")
80
84
  p.validate.each do |error|
81
85
  puts error.inspect
82
86
  end
87
+
83
88
  end
84
89
  #Generating A Line Chart
85
90
  if ARGV.size==0 || ARGV.include?("7")
@@ -91,26 +96,29 @@ if ARGV.size==0 || ARGV.include?("7")
91
96
  sheet.add_chart(Axlsx::Line3DChart, :title=>"example 6: Line Chart") do |chart|
92
97
  chart.start_at 0, 2
93
98
  chart.end_at 10, 15
94
- chart.add_series :data=>sheet.rows.first.cells[(1..-1)], :title=> sheet.rows.first.cells.first
99
+ chart.add_series :data=>["B1:E1"], :title=> sheet["A1"]
95
100
  chart.add_series :data=>sheet.rows.last.cells[(1..-1)], :title=> sheet.rows.last.cells.first
96
101
  end
97
102
 
98
103
  end
99
104
  p.serialize("example7.xlsx")
105
+
100
106
  end
107
+
101
108
  #Add an Image
102
109
  if ARGV.size==0 || ARGV.include?("8")
103
110
 
104
111
  p = Axlsx::Package.new
105
112
  p.workbook.add_worksheet do |sheet|
106
113
  img = File.expand_path('examples/image1.jpeg')
107
- sheet.add_image(:image_src => img) do |image|
114
+ sheet.add_image(:image_src => img, :noSelect=>true, :noMove=>true) do |image|
108
115
  image.width=720
109
116
  image.height=666
110
117
  image.start_at 2, 2
111
118
  end
112
119
  end
113
120
  p.serialize("example8.xlsx")
121
+
114
122
  end
115
123
 
116
124
  #Asian Language Support
@@ -123,11 +131,13 @@ if ARGV.size==0 || ARGV.include?("9")
123
131
  sheet.add_row ["한국어/조선말"]
124
132
  end
125
133
  p.serialize("example9.xlsx")
134
+
126
135
  end
127
136
 
128
137
 
129
138
  #Styling Columns
130
139
  if ARGV.size==0 || ARGV.include?("10")
140
+
131
141
  p = Axlsx::Package.new
132
142
  percent = p.workbook.styles.add_style :num_fmt => 9
133
143
  p.workbook.add_worksheet do |sheet|
@@ -138,10 +148,12 @@ if ARGV.size==0 || ARGV.include?("10")
138
148
  end
139
149
  p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
140
150
  p.serialize("example10.xlsx")
151
+
141
152
  end
142
153
 
143
154
  #Styling Rows
144
155
  if ARGV.size==0 || ARGV.include?("11")
156
+
145
157
  p = Axlsx::Package.new
146
158
  p.workbook.add_worksheet do |sheet|
147
159
  sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
@@ -149,27 +161,42 @@ if ARGV.size==0 || ARGV.include?("11")
149
161
  sheet.add_row [1, 2, 0.2, 4]
150
162
  sheet.add_row [1, 2, 0.1, 4]
151
163
  end
152
- head = p.workbook.styles.add_style :bg_color => "FF000000", :fg_color=>"FFFFFFFF"
164
+ head = p.workbook.styles.add_style :bg_color => "00", :fg_color=>"FF"
153
165
  percent = p.workbook.styles.add_style :num_fmt => 9
154
166
  p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
155
167
  p.workbook.worksheets.first.row_style 0, head
156
168
  p.serialize("example11.xlsx")
169
+
157
170
  end
158
171
 
159
- #Rails 3
160
-
161
- # class MyModel < ActiveRecord::Base
162
- # acts_as_axlsx
163
- # end
164
- #
165
- # class MyModelController < ApplicationController
166
- #
167
- # GET /posts/xlsx
168
- # def xlsx
169
- # p = Post.to_xlsx
170
- # p.serialize('posts.xlsx')
171
- # send_file 'posts.xlsx', :type=>"application/xlsx", :x_sendfile=>true
172
- # end
172
+ #Using formula
173
+ if ARGV.size==0 || ARGV.include?("12")
174
+
175
+ p = Axlsx::Package.new
176
+ p.workbook.add_worksheet do |sheet|
177
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
178
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
179
+ end
180
+ p.serialize("example12.xlsx")
181
+
182
+ end
183
+
184
+
185
+ #Using cell specific styling and range / name based access
186
+ if ARGV.size==0 || ARGV.include?("13")
187
+
188
+ p = Axlsx::Package.new
189
+ p.workbook.add_worksheet(:name=>'My Worksheet') do |sheet|
190
+ # cell level style overides when adding cells
191
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
192
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
193
+ # cell level style overrides via sheet range
194
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
195
+ end
196
+ p.workbook['My Worksheet!A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
197
+ p.serialize("example13.xlsx")
198
+
199
+ end
173
200
 
174
201
 
175
202
 
Binary file
data/lib/axlsx.rb CHANGED
@@ -1,10 +1,13 @@
1
-
2
1
  Encoding::default_internal = 'UTF-8' unless RUBY_VERSION < '1.9'
3
2
  Encoding::default_external = 'UTF-8' unless RUBY_VERSION < '1.9'
4
3
 
5
4
  require 'axlsx/util/simple_typed_list.rb'
6
5
  require 'axlsx/util/constants.rb'
7
6
  require 'axlsx/util/validators.rb'
7
+
8
+ # to be included with parsable intitites.
9
+ #require 'axlsx/util/parser.rb'
10
+
8
11
  require 'axlsx/stylesheet/styles.rb'
9
12
 
10
13
  require 'axlsx/doc_props/app.rb'
@@ -38,4 +41,14 @@ module Axlsx
38
41
  ref += ":#{items.last.r_abs}" if items.size > 1
39
42
  ref
40
43
  end
44
+
45
+ def self.name_to_indices(name)
46
+ raise ArgumentError, 'invalid cell name' unless name.size > 1
47
+ v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |v, c|
48
+ v[:i] += ((c.bytes.first - 65) + v[:base]); v[:base] *= 26; v
49
+ end
50
+
51
+ [v[:i]-1, ((name[/[1-9]+/]).to_i)-1]
52
+
53
+ end
41
54
  end
@@ -51,8 +51,8 @@ module Axlsx
51
51
  options.each do |o|
52
52
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
53
53
  end
54
- start_at(*options[:start_at]) if options[:start_at]
55
- end_at(*options[:end_at]) if options[:start_at]
54
+ start_at *options[:start_at] if options[:start_at]
55
+ end_at *options[:end_at] if options[:start_at]
56
56
  yield self if block_given?
57
57
  end
58
58
 
@@ -140,7 +140,8 @@ module Axlsx
140
140
  # @param [Integer] x The column
141
141
  # @param [Integer] y The row
142
142
  # @return [Marker]
143
- def start_at(x, y)
143
+ def start_at(x, y=0)
144
+ x, y = *parse_coord_args(x, y)
144
145
  @graphic_frame.anchor.from.col = x
145
146
  @graphic_frame.anchor.from.row = y
146
147
  end
@@ -151,12 +152,27 @@ module Axlsx
151
152
  # @param [Integer] x The column
152
153
  # @param [Integer] y The row
153
154
  # @return [Marker]
154
- def end_at(x, y)
155
+ def end_at(x, y=0)
156
+ x, y = *parse_coord_args(x, y)
155
157
  @graphic_frame.anchor.to.col = x
156
158
  @graphic_frame.anchor.to.row = y
157
159
  end
158
160
 
159
161
  private
162
+
163
+ def parse_coord_args(x, y=0)
164
+ if x.is_a?(String)
165
+ x, y = *Axlsx::name_to_indices(x)
166
+ end
167
+ if x.is_a?(Cell)
168
+ x, y = *x.pos
169
+ end
170
+ if x.is_a?(Array)
171
+ x, y = *x
172
+ end
173
+ [x, y]
174
+ end
175
+
160
176
  def view3D=(v) DataTypeValidator.validate "#{self.class}.view3D", View3D, v; @view3D = v; end
161
177
 
162
178
  end
@@ -27,7 +27,7 @@ module Axlsx
27
27
  require 'axlsx/drawing/bar_3D_chart.rb'
28
28
  require 'axlsx/drawing/line_3D_chart.rb'
29
29
 
30
-
30
+ require 'axlsx/drawing/picture_locking.rb'
31
31
  require 'axlsx/drawing/pic.rb'
32
32
 
33
33
  # A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors.
@@ -26,6 +26,8 @@ module Axlsx
26
26
  # @return [OneCellAnchor]
27
27
  attr_reader :anchor
28
28
 
29
+ # The picture locking attributes for this picture
30
+ attr_reader :picture_locking
29
31
 
30
32
  # Creates a new Pic(ture) object
31
33
  # @param [Anchor] anchor the anchor that holds this image
@@ -43,6 +45,7 @@ module Axlsx
43
45
  end
44
46
  start_at(*options[:start_at]) if options[:start_at]
45
47
  yield self if block_given?
48
+ @picture_locking = PictureLocking.new(options)
46
49
  end
47
50
 
48
51
  def image_src=(v)
@@ -94,7 +97,7 @@ module Axlsx
94
97
  def width=(v)
95
98
  @anchor.width = v
96
99
  end
97
-
100
+
98
101
  # providing access to update the anchor's height attribute
99
102
  # @param [Integer] v
100
103
  # @see OneCellAnchor.width
@@ -126,7 +129,7 @@ module Axlsx
126
129
  xml.send('xdr:nvPicPr') {
127
130
  xml.send('xdr:cNvPr', :id=>"2", :name=>name, :descr=>descr)
128
131
  xml.send('xdr:cNvPicPr') {
129
- xml.send('a:picLocks', :noChangeAspect=>1)
132
+ picture_locking.to_xml(xml)
130
133
  }
131
134
  }
132
135
  xml.send('xdr:blipFill') {
@@ -0,0 +1,72 @@
1
+ module Axlsx
2
+ # The picture locking class defines the locking properties for pictures in your workbook.
3
+ class PictureLocking
4
+
5
+
6
+ attr_reader :noGrp
7
+ attr_reader :noSelect
8
+ attr_reader :noRot
9
+ attr_reader :noChangeAspect
10
+ attr_reader :noMove
11
+ attr_reader :noResize
12
+ attr_reader :noEditPoints
13
+ attr_reader :noAdjustHandles
14
+ attr_reader :noChangeArrowheads
15
+ attr_reader :noChangeShapeType
16
+
17
+ # Creates a new PictureLocking object
18
+ # @option options [Boolean] noGrp
19
+ # @option options [Boolean] noSelect
20
+ # @option options [Boolean] noRot
21
+ # @option options [Boolean] noChangeAspect
22
+ # @option options [Boolean] noMove
23
+ # @option options [Boolean] noResize
24
+ # @option options [Boolean] noEditPoints
25
+ # @option options [Boolean] noAdjustHandles
26
+ # @option options [Boolean] noChangeArrowheads
27
+ # @option options [Boolean] noChangeShapeType
28
+ def initialize(options={})
29
+ @noChangeAspect = true
30
+ options.each do |o|
31
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
32
+ end
33
+ end
34
+
35
+ # @see noGrp
36
+ def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
37
+
38
+ # @see noSelect
39
+ def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
40
+
41
+ # @see noRot
42
+ def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
43
+
44
+ # @see noChangeAspect
45
+ def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
46
+
47
+ # @see noMove
48
+ def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
49
+
50
+ # @see noResize
51
+ def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
52
+
53
+ # @see noEditPoints
54
+ def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
55
+
56
+ # @see noAdjustHandles
57
+ def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
58
+
59
+ # @see noChangeArrowheads
60
+ def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
61
+
62
+ # @see noChangeShapeType
63
+ def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
64
+
65
+ # Serializes the picture locking
66
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
67
+ # @return [String]
68
+ def to_xml(xml)
69
+ xml[:a].picLocks(self.instance_values)
70
+ end
71
+ end
72
+ end
data/lib/axlsx/package.rb CHANGED
@@ -16,12 +16,6 @@ module Axlsx
16
16
  yield self if block_given?
17
17
  end
18
18
 
19
- # Accepts a ruport table for serialization to xlsx
20
- # @param [Table] table a ruport Table object
21
- def ruport_table(table)
22
- puts table
23
- end
24
-
25
19
  # The workbook this package will serialize or validate.
26
20
  # @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
27
21
  # @raise ArgumentError if workbook parameter is not a Workbook instance.
@@ -39,6 +33,13 @@ module Axlsx
39
33
  yield @workbook if block_given?
40
34
  @workbook
41
35
  end
36
+
37
+ #def self.parse(input, confirm_valid = false)
38
+ # p = Package.new
39
+ # z = Zip::ZipFile.open(input)
40
+ # p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN)
41
+ # p
42
+ #end
42
43
 
43
44
  # @see workbook
44
45
  def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end
@@ -76,7 +77,8 @@ module Axlsx
76
77
  end
77
78
  true
78
79
  end
79
-
80
+
81
+
80
82
  # Validate all parts of the package against xsd schema.
81
83
  # @return [Array] An array of all validation errors found.
82
84
  # @note This gem includes all schema from OfficeOpenXML-XMLSchema-Transitional.zip and OpenPackagingConventions-XMLSchema.zip
@@ -5,16 +5,19 @@ module Axlsx
5
5
  # @return [Boolean]
6
6
  attr_reader :auto
7
7
 
8
- # Backwards compatability color index
9
- # return [Integer]
10
- #attr_reader :indexed
11
-
12
8
  # The color as defined in rgb terms.
13
9
  # @note
14
10
  # rgb colors need to conform to ST_UnsignedIntHex. That basically means put 'FF' before you color
15
- # @example rgb colors
16
- # "FF000000" is black
17
- # "FFFFFFFF" is white
11
+ # When assigning the rgb value the behavior is much like CSS selectors and can use shorthand versions as follows:
12
+ # If you provide a two character value it will be repeated for each r, g, b assignment
13
+ # If you provide data that is not 2 characters in length, and is less than 8 characters it will be padded with "F"
14
+ # @example
15
+ # Color.new :rgb => "FF000000"
16
+ # => #<Axlsx::Color:0x102106b68 @rgb="FF000000">
17
+ # Color.new :rgb => "0A"
18
+ # => #<Axlsx::Color:0x102106b68 @rgb="FF0A0A0A">
19
+ # Color.new :rgb => "00BB"
20
+ # => #<Axlsx::Color:0x102106b68 @rgb="FFFF00BB">
18
21
  # @return [String]
19
22
  attr_reader :rgb
20
23
 
@@ -39,8 +42,15 @@ module Axlsx
39
42
  end
40
43
  # @see auto
41
44
  def auto=(v) Axlsx::validate_boolean v; @auto = v end
42
- # @see rgb
43
- def rgb=(v) Axlsx::validate_string v; @rgb = v end
45
+ # @see color
46
+ def rgb=(v)
47
+ Axlsx::validate_string(v)
48
+ v.upcase!
49
+ v = v * 3 if v.size == 2
50
+ v = v.rjust(8, 'FF')
51
+ raise ArgumentError, "Invalid color rgb value: #{v}." unless v.match(/[0-9A-F]{8}/)
52
+ @rgb = v
53
+ end
44
54
  # @see tint
45
55
  def tint=(v) Axlsx::validate_float v; @tint = v end
46
56