axlsx 1.1.6 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -6
- data/examples/axis-titles.xlsx +0 -0
- data/examples/basic_charts.rb +46 -0
- data/examples/basic_charts.xlsx +0 -0
- data/examples/charts.xlsx +0 -0
- data/examples/example.rb +17 -1
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/pie_chart_excel.xlsx +0 -0
- data/examples/pie_chart_saved.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/sheet_view.rb +34 -0
- data/examples/sheet_view.xlsx +0 -0
- data/examples/~$example.xlsx +0 -0
- data/lib/axlsx.rb +3 -2
- data/lib/axlsx/drawing/axis.rb +18 -0
- data/lib/axlsx/drawing/cat_axis.rb +3 -3
- data/lib/axlsx/drawing/chart.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +0 -1
- data/lib/axlsx/drawing/graphic_frame.rb +2 -2
- data/lib/axlsx/drawing/num_data.rb +2 -2
- data/lib/axlsx/drawing/title.rb +21 -9
- data/lib/axlsx/package.rb +9 -5
- data/lib/axlsx/util/validators.rb +28 -4
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +7 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +4 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +1 -1
- data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +27 -10
- data/test/drawing/tc_axis.rb +19 -2
- data/test/drawing/tc_cat_axis.rb +3 -3
- data/test/drawing/tc_num_data.rb +5 -1
- data/test/drawing/tc_title.rb +16 -0
- data/test/tc_package.rb +24 -4
- data/test/util/tc_validators.rb +68 -11
- data/test/workbook/worksheet/tc_pane.rb +94 -0
- data/test/workbook/worksheet/tc_selection.rb +94 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
- data/test/workbook/worksheet/tc_worksheet.rb +0 -7
- metadata +28 -13
- data/examples/pie_chart.rb +0 -16
- data/examples/pie_chart.xlsx +0 -0
- data/examples/~$pie_chart_saved.xlsx +0 -0
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
16
16
|
|
17
17
|
**License**: MIT License
|
18
18
|
|
19
|
-
**Latest Version**: 1.1.
|
19
|
+
**Latest Version**: 1.1.7
|
20
20
|
|
21
21
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
22
22
|
|
@@ -24,7 +24,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
24
24
|
|
25
25
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
26
26
|
|
27
|
-
**Release Date**:
|
27
|
+
**Release Date**: June 11th 2012
|
28
28
|
|
29
29
|
If you are working in rails, or with active record see:
|
30
30
|
http://github.com/randym/acts_as_xlsx
|
@@ -113,7 +113,16 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
113
113
|
|
114
114
|
#Change log
|
115
115
|
---------
|
116
|
-
- **
|
116
|
+
- **June.11.12**: 1.1.7 release
|
117
|
+
- fix chart rendering issue when label offset is specified as a
|
118
|
+
percentage in serialization and ensure that formula are not stored
|
119
|
+
in value caches
|
120
|
+
- fix bug that causes repair warnings when using a text only title reference.
|
121
|
+
- Add title property to axis so you can lable the x/y/series axis for
|
122
|
+
charts.
|
123
|
+
- Add sheet views with panes
|
124
|
+
|
125
|
+
- **May.30.12**: 1.1.6 release
|
117
126
|
- data protection with passwords for sheets
|
118
127
|
- cell level input validators
|
119
128
|
- added support for two cell anchors for images
|
@@ -124,14 +133,14 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
124
133
|
- resolved all warnings generating from this gem.
|
125
134
|
- improved comment relationship management for multiple comments
|
126
135
|
|
127
|
-
- **
|
136
|
+
- **May.13.12**: 1.1.5 release
|
128
137
|
- MOAR print options! You can now specify paper size, orientation,
|
129
138
|
fit to width, page margings and gridlines for printing.
|
130
139
|
- Support for adding comments to your worksheets
|
131
140
|
- bugfix for applying style to empty cells
|
132
141
|
- bugfix for parsing formula with multiple '='
|
133
142
|
|
134
|
-
- **
|
143
|
+
- **May.3.12:**: 1.1.4 release
|
135
144
|
- MOAR examples
|
136
145
|
- added outline level for rows and columns
|
137
146
|
- rebuild of numeric and axis data sources for charts
|
@@ -155,6 +164,10 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
155
164
|
Please see the {file:CHANGELOG.md} document for past release information.
|
156
165
|
|
157
166
|
#Thanks!
|
167
|
+
|
168
|
+
Open source software is a community effort. None of this could have been
|
169
|
+
done without the help of the people below.
|
170
|
+
|
158
171
|
--------
|
159
172
|
[ochko](https://github.com/ochko) - for performance fixes, kicking the crap out of axlsx and helping to maintain my general sanity.
|
160
173
|
|
@@ -176,7 +189,7 @@ Please see the {file:CHANGELOG.md} document for past release information.
|
|
176
189
|
|
177
190
|
[scpike](https://github.com/scpike) - for keeping numbers fixed even when they are rational and a super clean implementation of conditional formatting.
|
178
191
|
|
179
|
-
[janhuehne](https://github.com/janhuehne) - for working out the decoder ring and adding in cell level validation.
|
192
|
+
[janhuehne](https://github.com/janhuehne) - for working out the decoder ring and adding in cell level validation, and providing a support for window panes.
|
180
193
|
|
181
194
|
#Copyright and License
|
182
195
|
----------
|
Binary file
|
@@ -0,0 +1,46 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
require 'axlsx'
|
3
|
+
p = Axlsx::Package.new
|
4
|
+
wb = p.workbook
|
5
|
+
|
6
|
+
# Pie Chart
|
7
|
+
wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
8
|
+
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
9
|
+
sheet.add_row [1, 2, 3, 4]
|
10
|
+
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=> 'dark corner here') do |chart|
|
11
|
+
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# line chart
|
16
|
+
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
17
|
+
sheet.add_row ['1', '2', '3', '4']
|
18
|
+
sheet.add_row [1, 2, 3, '=sum(A2:C2)']
|
19
|
+
sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart|
|
20
|
+
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# bar chart
|
25
|
+
wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
26
|
+
sheet.add_row ["A Simple Bar Chart"]
|
27
|
+
sheet.add_row ["First", "Second", "Third"]
|
28
|
+
sheet.add_row [1, 2, 3]
|
29
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
|
30
|
+
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
31
|
+
chart.valAxis.label_rotation = -45
|
32
|
+
chart.catAxis.label_rotation = 45
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# specifying colors and title
|
37
|
+
wb.add_worksheet(:name => "Colored Pie Chart") do |sheet|
|
38
|
+
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
39
|
+
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
40
|
+
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
|
41
|
+
chart.add_series :data => sheet["A2:D2"], :labels => ["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
p.serialize('basic_charts.xlsx')
|
46
|
+
|
Binary file
|
Binary file
|
data/examples/example.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby -w -s
|
2
2
|
# -*- coding: utf-8 -*-
|
3
|
-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
4
|
|
5
5
|
#```ruby
|
6
6
|
require 'axlsx'
|
@@ -276,6 +276,8 @@ wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
276
276
|
chart.end_at 10, 15
|
277
277
|
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
|
278
278
|
chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
|
279
|
+
chart.catAxis.title = 'Y Axis'
|
280
|
+
chart.valAxis.title = 'X Axis'
|
279
281
|
end
|
280
282
|
end
|
281
283
|
#```
|
@@ -350,6 +352,20 @@ wb.add_worksheet(:name => 'comments') do |sheet|
|
|
350
352
|
sheet.add_comment :ref => 'A1', :author => 'Bob', :text => 'Yes We Can!'
|
351
353
|
end
|
352
354
|
|
355
|
+
## Frozen/Split panes
|
356
|
+
## ``` ruby
|
357
|
+
wb.add_worksheet(:name => 'fixed headers') do |sheet|
|
358
|
+
sheet.add_row(['', (0..99).map { |i| "column header #{i}" }].flatten )
|
359
|
+
100.times.with_index { |index| sheet << ["row header", (0..index).to_a].flatten }
|
360
|
+
sheet.sheet_view.pane do |pane|
|
361
|
+
pane.top_left_cell = "B2"
|
362
|
+
pane.state = :frozen_split
|
363
|
+
pane.y_split = 1
|
364
|
+
pane.x_split = 1
|
365
|
+
pane.active_pane = :bottom_right
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
353
369
|
##Validate and Serialize
|
354
370
|
|
355
371
|
#```ruby
|
data/examples/example.xlsx
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
require 'axlsx'
|
5
|
+
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
ws = p.workbook.add_worksheet :name => "Sheetview - Split"
|
8
|
+
ws.sheet_view do |vs|
|
9
|
+
vs.pane do |p|
|
10
|
+
p.active_pane = :top_right
|
11
|
+
p.state = :split
|
12
|
+
p.x_split = 11080
|
13
|
+
p.y_split = 5000
|
14
|
+
p.top_left_cell = 'C44'
|
15
|
+
end
|
16
|
+
|
17
|
+
vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
|
18
|
+
vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
|
19
|
+
vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
|
20
|
+
vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
ws = p.workbook.add_worksheet :name => "Sheetview - Frozen"
|
25
|
+
ws.sheet_view do |vs|
|
26
|
+
vs.pane do |p|
|
27
|
+
p.state = :frozen
|
28
|
+
p.x_split = 3
|
29
|
+
p.y_split = 4
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
p.serialize 'sheet_view.xlsx'
|
Binary file
|
Binary file
|
data/lib/axlsx.rb
CHANGED
@@ -87,8 +87,9 @@ module Axlsx
|
|
87
87
|
# performs the increadible feat of changing snake_case to CamelCase
|
88
88
|
# @param [String] s The snake case string to camelize
|
89
89
|
# @return [String]
|
90
|
-
def self.camel(s="")
|
91
|
-
s = s.capitalize
|
90
|
+
def self.camel(s="", all_caps = true)
|
91
|
+
s = s.capitalize if all_caps
|
92
|
+
s.gsub(/_(.)/){ $1.upcase }
|
92
93
|
end
|
93
94
|
|
94
95
|
end
|
data/lib/axlsx/drawing/axis.rb
CHANGED
@@ -52,6 +52,9 @@ module Axlsx
|
|
52
52
|
# @return [Boolean]
|
53
53
|
attr_reader :delete
|
54
54
|
|
55
|
+
# the title for the axis. This can be a cell or a fixed string.
|
56
|
+
attr_reader :title
|
57
|
+
|
55
58
|
# Creates an Axis object
|
56
59
|
# @param [Integer] ax_id the id of this axis
|
57
60
|
# @param [Integer] cross_ax the id of the perpendicular axis
|
@@ -67,6 +70,7 @@ module Axlsx
|
|
67
70
|
@format_code = "General"
|
68
71
|
@delete = @label_rotation = 0
|
69
72
|
@scaling = Scaling.new(:orientation=>:minMax)
|
73
|
+
@title = nil
|
70
74
|
self.ax_pos = :b
|
71
75
|
self.tick_lbl_pos = :nextTo
|
72
76
|
self.format_code = "General"
|
@@ -113,6 +117,19 @@ module Axlsx
|
|
113
117
|
@label_rotation = adjusted
|
114
118
|
end
|
115
119
|
|
120
|
+
|
121
|
+
# The title object for the chart.
|
122
|
+
# @param [String, Cell] v
|
123
|
+
# @return [Title]
|
124
|
+
def title=(v)
|
125
|
+
DataTypeValidator.validate "#{self.class}.title", [String, Cell], v
|
126
|
+
@title ||= Title.new
|
127
|
+
if v.is_a?(String)
|
128
|
+
@title.text = v
|
129
|
+
elsif v.is_a?(Cell)
|
130
|
+
@title.cell = v
|
131
|
+
end
|
132
|
+
end
|
116
133
|
|
117
134
|
# Serializes the object
|
118
135
|
# @param [String] str
|
@@ -131,6 +148,7 @@ module Axlsx
|
|
131
148
|
str << '</c:spPr>'
|
132
149
|
end
|
133
150
|
str << '</c:majorGridlines>'
|
151
|
+
@title.to_xml_string(str) unless @title == nil
|
134
152
|
str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
|
135
153
|
str << '<c:majorTickMark val="none"/>'
|
136
154
|
str << '<c:minorTickMark val="none"/>'
|
@@ -28,7 +28,7 @@ module Axlsx
|
|
28
28
|
|
29
29
|
|
30
30
|
# regex for validating label offset
|
31
|
-
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)
|
31
|
+
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/
|
32
32
|
|
33
33
|
# Creates a new CatAxis object
|
34
34
|
# @param [Integer] axId the id of this axis. Inherited
|
@@ -46,7 +46,7 @@ module Axlsx
|
|
46
46
|
@tickMarkSkip = 1
|
47
47
|
self.auto = 1
|
48
48
|
self.lblAlgn = :ctr
|
49
|
-
self.lblOffset = "100
|
49
|
+
self.lblOffset = "100"
|
50
50
|
super(axId, crossAx, options)
|
51
51
|
end
|
52
52
|
|
@@ -77,7 +77,7 @@ module Axlsx
|
|
77
77
|
super(str)
|
78
78
|
str << '<c:auto val="' << @auto.to_s << '"/>'
|
79
79
|
str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
|
80
|
-
str << '<c:lblOffset val="' << @lblOffset.to_s << '"/>'
|
80
|
+
str << '<c:lblOffset val="' << @lblOffset.to_i.to_s << '"/>'
|
81
81
|
str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>'
|
82
82
|
str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>'
|
83
83
|
str << '</c:catAx>'
|
data/lib/axlsx/drawing/chart.rb
CHANGED
@@ -44,7 +44,7 @@ module Axlsx
|
|
44
44
|
# @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
|
45
45
|
# @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
|
46
46
|
def initialize(frame, options={})
|
47
|
-
@style =
|
47
|
+
@style = 18
|
48
48
|
@view3D = nil
|
49
49
|
@graphic_frame=frame
|
50
50
|
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
|
@@ -120,13 +120,13 @@ module Axlsx
|
|
120
120
|
# @return [String]
|
121
121
|
def to_xml_string(str = '')
|
122
122
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
123
|
-
str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '">'
|
123
|
+
str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">'
|
124
124
|
str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
|
125
125
|
str << '<c:style val="' << style.to_s << '"/>'
|
126
126
|
str << '<c:chart>'
|
127
127
|
@title.to_xml_string str
|
128
128
|
# do these need the c: namespace as well???
|
129
|
-
str << '<c:autoTitleDeleted val="
|
129
|
+
str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
|
130
130
|
@view3D.to_xml_string(str) if @view3D
|
131
131
|
str << '<c:floor><c:thickness val="0"/></c:floor>'
|
132
132
|
str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
|
@@ -155,7 +155,6 @@ module Axlsx
|
|
155
155
|
# @return [String]
|
156
156
|
def to_xml_string(str = '')
|
157
157
|
str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
158
|
-
# str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '" xmlns:c="' << XML_NS_C << '">'
|
159
158
|
str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
|
160
159
|
|
161
160
|
anchors.each { |anchor| anchor.to_xml_string(str) }
|
@@ -33,9 +33,9 @@ module Axlsx
|
|
33
33
|
# @return [String]
|
34
34
|
def to_xml_string(str = '')
|
35
35
|
# macro attribute should be optional!
|
36
|
-
str << '<xdr:graphicFrame
|
36
|
+
str << '<xdr:graphicFrame>'
|
37
37
|
str << '<xdr:nvGraphicFramePr>'
|
38
|
-
str << '<xdr:cNvPr id="
|
38
|
+
str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
|
39
39
|
str << '<xdr:cNvGraphicFramePr/>'
|
40
40
|
str << '</xdr:nvGraphicFramePr>'
|
41
41
|
str << '<xdr:xfrm>'
|
@@ -25,8 +25,8 @@ module Axlsx
|
|
25
25
|
def data=(values=[])
|
26
26
|
@tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
|
27
27
|
values.each do |value|
|
28
|
-
|
29
|
-
@pt << NumVal.new(:v =>
|
28
|
+
value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
|
29
|
+
@pt << NumVal.new(:v => value)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/lib/axlsx/drawing/title.rb
CHANGED
@@ -46,15 +46,27 @@ module Axlsx
|
|
46
46
|
str << '<c:title>'
|
47
47
|
unless @text.empty?
|
48
48
|
str << '<c:tx>'
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
if @cell.is_a?(Cell)
|
50
|
+
str << '<c:strRef>'
|
51
|
+
str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
|
52
|
+
str << '<c:strCache>'
|
53
|
+
str << '<c:ptCount val="1"/>'
|
54
|
+
str << '<c:pt idx="0">'
|
55
|
+
str << '<c:v>' << @text << '</c:v>'
|
56
|
+
str << '</c:pt>'
|
57
|
+
str << '</c:strCache>'
|
58
|
+
str << '</c:strRef>'
|
59
|
+
else
|
60
|
+
str << '<c:rich>'
|
61
|
+
str << '<a:bodyPr/>'
|
62
|
+
str << '<a:lstStyle/>'
|
63
|
+
str << '<a:p>'
|
64
|
+
str << '<a:r>'
|
65
|
+
str << '<a:t>' << @text.to_s << '</a:t>'
|
66
|
+
str << '</a:r>'
|
67
|
+
str << '</a:p>'
|
68
|
+
str << '</c:rich>'
|
69
|
+
end
|
58
70
|
str << '</c:tx>'
|
59
71
|
end
|
60
72
|
str << '<c:layout/>'
|
data/lib/axlsx/package.rb
CHANGED
@@ -80,9 +80,8 @@ module Axlsx
|
|
80
80
|
|
81
81
|
# Serialize your workbook to disk as an xlsx document.
|
82
82
|
#
|
83
|
-
# @param [
|
83
|
+
# @param [String] output The name of the file you want to serialize your package to
|
84
84
|
# @param [Boolean] confirm_valid Validate the package prior to serialization.
|
85
|
-
# @option options stream indicates if we should be writing to a stream or a file. True for stream, nil for file
|
86
85
|
# @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
|
87
86
|
# @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
|
88
87
|
# confirm_valid should be used in the rare case that you cannot open the serialized file.
|
@@ -90,10 +89,15 @@ module Axlsx
|
|
90
89
|
# @example
|
91
90
|
# # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts.
|
92
91
|
# # Take a look at the README for an example of how to do it!
|
93
|
-
# f = File.open('test.xlsx', 'w')
|
94
|
-
# Package.new.serialize(f)
|
95
92
|
#
|
96
|
-
# #
|
93
|
+
# #serialize to a file
|
94
|
+
# p = Axlsx::Package.new
|
95
|
+
# # ......add cool stuff to your workbook......
|
96
|
+
# p.serialize("example.xlsx")
|
97
|
+
#
|
98
|
+
# # Serialize to a stream
|
99
|
+
# s = p.to_stream()
|
100
|
+
# File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
|
97
101
|
def serialize(output, confirm_valid=false)
|
98
102
|
return false unless !confirm_valid || self.validate.empty?
|
99
103
|
Zip::ZipOutputStream.open(output) do |zip|
|
@@ -109,9 +109,14 @@ module Axlsx
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# Requires that the value is an integer ranging from 10 to 400.
|
112
|
-
def self.
|
112
|
+
def self.validate_scale_10_400(v)
|
113
113
|
DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
|
114
114
|
end
|
115
|
+
|
116
|
+
# Requires that the value is an integer ranging from 10 to 400 or 0.
|
117
|
+
def self.validate_scale_0_10_400(v)
|
118
|
+
DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
|
119
|
+
end
|
115
120
|
|
116
121
|
# Requires that the value is one of :default, :landscape, or :portrait.
|
117
122
|
def self.validate_page_orientation(v)
|
@@ -132,8 +137,6 @@ module Axlsx
|
|
132
137
|
# thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
|
133
138
|
def self.validate_time_period_type(v)
|
134
139
|
RestrictionValidator.validate :time_period_type, [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek], v
|
135
|
-
|
136
|
-
|
137
140
|
end
|
138
141
|
|
139
142
|
# Requires that the value is one of the valid ST_IconSet types
|
@@ -238,4 +241,25 @@ module Axlsx
|
|
238
241
|
def self.validate_data_validation_type(v)
|
239
242
|
RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole], v
|
240
243
|
end
|
241
|
-
|
244
|
+
|
245
|
+
# Requires that the value is a valid sheet view type.
|
246
|
+
# valid types must be one of normal, page_break_preview, page_layout
|
247
|
+
# @param [Any] v The value validated
|
248
|
+
def self.validate_sheet_view_type(v)
|
249
|
+
RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
|
250
|
+
end
|
251
|
+
|
252
|
+
# Requires that the value is a valid active pane type.
|
253
|
+
# valid types must be one of bottom_left, bottom_right, top_left, top_right
|
254
|
+
# @param [Any] v The value validated
|
255
|
+
def self.validate_pane_type(v)
|
256
|
+
RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
|
257
|
+
end
|
258
|
+
|
259
|
+
# Requires that the value is a valid split state type.
|
260
|
+
# valid types must be one of frozen, frozen_split, split
|
261
|
+
# @param [Any] v The value validated
|
262
|
+
def self.validate_split_state_type(v)
|
263
|
+
RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
|
264
|
+
end
|
265
|
+
end
|