axlsx 2.1.0.pre → 3.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -20
- data/Rakefile +0 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +15 -0
- data/examples/example.rb +31 -1
- data/lib/axlsx.rb +9 -4
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/chart.rb +8 -1
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +3 -0
- data/lib/axlsx/drawing/line_series.rb +18 -1
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +2 -1
- data/lib/axlsx/drawing/pic.rb +24 -17
- data/lib/axlsx/drawing/scaling.rb +2 -2
- data/lib/axlsx/drawing/scatter_series.rb +16 -2
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +19 -1
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/package.rb +7 -16
- data/lib/axlsx/rels/relationships.rb +5 -2
- data/lib/axlsx/stylesheet/num_fmt.rb +9 -0
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/constants.rb +8 -5
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/simple_typed_list.rb +1 -1
- data/lib/axlsx/util/validators.rb +14 -9
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +19 -1
- data/lib/axlsx/workbook/workbook_view.rb +5 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +26 -19
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +15 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -0
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +36 -13
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +4 -1
- data/lib/axlsx/workbook/worksheet/rich_text.rb +23 -3
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +28 -32
- data/lib/axlsx/workbook/worksheet/row.rb +7 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +3 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +8 -51
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/test/axlsx.qcachegrind +2226 -0
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_series.rb +38 -5
- data/test/drawing/tc_pic.rb +11 -19
- data/test/drawing/tc_scatter_series.rb +16 -5
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +3 -1
- data/test/tc_package.rb +12 -0
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +1 -1
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +22 -1
- data/test/workbook/worksheet/tc_cell.rb +53 -11
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_rich_text_run.rb +11 -11
- data/test/workbook/worksheet/tc_row.rb +5 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +53 -38
- metadata +72 -20
- data/examples/IMAGE1UP.JPEG +0 -0
- data/lib/axlsx/util/string.rb +0 -7
@@ -0,0 +1,33 @@
|
|
1
|
+
module Axlsx
|
2
|
+
|
3
|
+
# The OutlinePr class manages serialization of a worksheet's outlinePr element, which provides various
|
4
|
+
# options to control outlining.
|
5
|
+
class OutlinePr
|
6
|
+
include Axlsx::OptionsParser
|
7
|
+
include Axlsx::Accessors
|
8
|
+
include Axlsx::SerializedAttributes
|
9
|
+
|
10
|
+
serializable_attributes :summary_below,
|
11
|
+
:summary_right,
|
12
|
+
:apply_styles
|
13
|
+
|
14
|
+
# These attributes are all boolean so I'm doing a bit of a hand
|
15
|
+
# waving magic show to set up the attriubte accessors
|
16
|
+
boolean_attr_accessor :summary_below,
|
17
|
+
:summary_right,
|
18
|
+
:apply_styles
|
19
|
+
|
20
|
+
# Creates a new OutlinePr object
|
21
|
+
# @param [Hash] options used to create the outline_pr
|
22
|
+
def initialize(options = {})
|
23
|
+
parse_options options
|
24
|
+
end
|
25
|
+
|
26
|
+
# Serialize the object
|
27
|
+
# @param [String] str serialized output will be appended to this object if provided.
|
28
|
+
# @return [String]
|
29
|
+
def to_xml_string(str = '')
|
30
|
+
str << "<outlinePr #{serialized_attributes} />"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -25,10 +25,20 @@ module Axlsx
|
|
25
25
|
@data = []
|
26
26
|
@pages = []
|
27
27
|
@subtotal = nil
|
28
|
+
@no_subtotals_on_headers = []
|
29
|
+
@style_info = {}
|
28
30
|
parse_options options
|
29
31
|
yield self if block_given?
|
30
32
|
end
|
31
33
|
|
34
|
+
# Defines the headers in which subtotals are not to be included
|
35
|
+
# @return[Array]
|
36
|
+
attr_accessor :no_subtotals_on_headers
|
37
|
+
|
38
|
+
# Style info for the pivot table
|
39
|
+
# @return[Hash]
|
40
|
+
attr_accessor :style_info
|
41
|
+
|
32
42
|
# The reference to the table data
|
33
43
|
# @return [String]
|
34
44
|
attr_reader :ref
|
@@ -160,12 +170,12 @@ module Axlsx
|
|
160
170
|
def to_xml_string(str = '')
|
161
171
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
162
172
|
str << ('<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '" dataOnRows="1" applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">')
|
163
|
-
str << (
|
164
|
-
str << (
|
173
|
+
str << ('<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>')
|
174
|
+
str << ('<pivotFields count="' << header_cells_count.to_s << '">')
|
165
175
|
header_cell_values.each do |cell_value|
|
166
|
-
str <<
|
176
|
+
str << pivot_field_for(cell_value, !no_subtotals_on_headers.include?(cell_value))
|
167
177
|
end
|
168
|
-
str <<
|
178
|
+
str << '</pivotFields>'
|
169
179
|
if rows.empty?
|
170
180
|
str << '<rowFields count="1"><field x="-2"/></rowFields>'
|
171
181
|
str << '<rowItems count="2"><i><x/></i> <i i="1"><x v="1"/></i></rowItems>'
|
@@ -200,12 +210,21 @@ module Axlsx
|
|
200
210
|
unless data.empty?
|
201
211
|
str << "<dataFields count=\"#{data.size}\">"
|
202
212
|
data.each do |datum_value|
|
203
|
-
|
213
|
+
# The correct name prefix in ["Sum","Average", etc...]
|
214
|
+
str << "<dataField name='#{(datum_value[:subtotal]||'')} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
|
204
215
|
str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
|
205
216
|
str << "/>"
|
206
217
|
end
|
207
218
|
str << '</dataFields>'
|
208
219
|
end
|
220
|
+
# custom pivot table style
|
221
|
+
unless style_info.empty?
|
222
|
+
str << '<pivotTableStyleInfo'
|
223
|
+
style_info.each do |k,v|
|
224
|
+
str << ' ' << k.to_s << '="' << v.to_s << '"'
|
225
|
+
end
|
226
|
+
str << ' />'
|
227
|
+
end
|
209
228
|
str << '</pivotTableDefinition>'
|
210
229
|
end
|
211
230
|
|
@@ -241,24 +260,28 @@ module Axlsx
|
|
241
260
|
|
242
261
|
private
|
243
262
|
|
244
|
-
def pivot_field_for(cell_ref)
|
263
|
+
def pivot_field_for(cell_ref, subtotal=true)
|
245
264
|
if rows.include? cell_ref
|
246
|
-
|
265
|
+
if subtotal
|
266
|
+
'<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
|
267
|
+
else
|
268
|
+
'<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1" defaultSubtotal="0"></pivotField>'
|
269
|
+
end
|
247
270
|
elsif columns.include? cell_ref
|
248
|
-
'<pivotField axis="axisCol" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"
|
271
|
+
'<pivotField axis="axisCol" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
|
249
272
|
elsif pages.include? cell_ref
|
250
|
-
'<pivotField axis="
|
273
|
+
'<pivotField axis="axisPage" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
|
251
274
|
elsif data_refs.include? cell_ref
|
252
|
-
'<pivotField dataField="1" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"
|
275
|
+
'<pivotField dataField="1" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"></pivotField>'
|
253
276
|
else
|
254
|
-
'<pivotField compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"
|
277
|
+
'<pivotField compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"></pivotField>'
|
255
278
|
end
|
256
279
|
end
|
257
|
-
|
280
|
+
|
258
281
|
def data_refs
|
259
282
|
data.map { |hash| hash[:ref] }
|
260
283
|
end
|
261
|
-
|
284
|
+
|
262
285
|
def header_range
|
263
286
|
range.gsub(/^(\w+?)(\d+)\:(\w+?)\d+$/, '\1\2:\3\2')
|
264
287
|
end
|
@@ -24,11 +24,14 @@ module Axlsx
|
|
24
24
|
last
|
25
25
|
end
|
26
26
|
|
27
|
+
# Serializes the protected ranges
|
28
|
+
# @param [String] str
|
29
|
+
# @return [String]
|
27
30
|
def to_xml_string(str = '')
|
28
31
|
return if empty?
|
29
32
|
str << '<protectedRanges>'
|
30
33
|
each { |range| range.to_xml_string(str) }
|
31
|
-
str << '</protectedRanges>'
|
34
|
+
str << '</protectedRanges>'
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,32 +1,52 @@
|
|
1
1
|
module Axlsx
|
2
|
+
|
3
|
+
# A simple, self serializing class for storing TextRuns
|
2
4
|
class RichText < SimpleTypedList
|
5
|
+
|
6
|
+
# creates a new RichText collection
|
7
|
+
# @param [String] text -optional The text to use in creating the first RichTextRun
|
8
|
+
# @param [Object] options -optional The options to use in creating the first RichTextRun
|
9
|
+
# @yield [RichText] self
|
3
10
|
def initialize(text = nil, options={})
|
4
11
|
super(RichTextRun)
|
5
12
|
add_run(text, options) unless text.nil?
|
6
13
|
yield self if block_given?
|
7
14
|
end
|
8
15
|
|
16
|
+
# The cell that owns this RichText collection
|
9
17
|
attr_reader :cell
|
10
|
-
|
18
|
+
|
19
|
+
# Assign the cell for this RichText collection
|
20
|
+
# @param [Cell] cell The cell which all RichTextRuns in the collection will belong to
|
11
21
|
def cell=(cell)
|
12
22
|
@cell = cell
|
13
23
|
each { |run| run.cell = cell }
|
14
24
|
end
|
15
|
-
|
25
|
+
|
26
|
+
# Calculates the longest autowidth of the RichTextRuns in this collection
|
27
|
+
# @return [Number]
|
16
28
|
def autowidth
|
17
29
|
widtharray = [0] # Are arrays the best way of solving this problem?
|
18
30
|
each { |run| run.autowidth(widtharray) }
|
19
31
|
widtharray.max
|
20
32
|
end
|
21
33
|
|
34
|
+
# Creates and adds a RichTextRun to this collectino
|
35
|
+
# @param [String] text The text to use in creating a new RichTextRun
|
36
|
+
# @param [Object] options The options to use in creating the new RichTextRun
|
22
37
|
def add_run(text, options={})
|
23
38
|
self << RichTextRun.new(text, options)
|
24
39
|
end
|
25
|
-
|
40
|
+
|
41
|
+
# The RichTextRuns we own
|
42
|
+
# @return [RichText]
|
26
43
|
def runs
|
27
44
|
self
|
28
45
|
end
|
29
46
|
|
47
|
+
# renders the RichTextRuns in this collection
|
48
|
+
# @param [String] str
|
49
|
+
# @return [String]
|
30
50
|
def to_xml_string(str='')
|
31
51
|
each{ |run| run.to_xml_string(str) }
|
32
52
|
str
|
@@ -1,26 +1,29 @@
|
|
1
1
|
module Axlsx
|
2
|
+
|
3
|
+
# The RichTextRun class creates and self serializing text run.
|
2
4
|
class RichTextRun
|
3
|
-
|
5
|
+
|
4
6
|
include Axlsx::OptionsParser
|
5
|
-
|
7
|
+
|
6
8
|
attr_reader :value
|
7
|
-
|
9
|
+
|
10
|
+
# A list of allowed inline style attributes used for validation
|
8
11
|
INLINE_STYLES = [:font_name, :charset,
|
9
12
|
:family, :b, :i, :strike, :outline,
|
10
13
|
:shadow, :condense, :extend, :u,
|
11
14
|
:vertAlign, :sz, :color, :scheme].freeze
|
12
|
-
|
15
|
+
|
13
16
|
def initialize(value, options={})
|
14
17
|
self.value = value
|
15
|
-
parse_options(options)
|
18
|
+
parse_options(options)
|
16
19
|
end
|
17
|
-
|
20
|
+
|
18
21
|
def value=(value)
|
19
22
|
@value = value
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
attr_accessor :cell
|
23
|
-
|
26
|
+
|
24
27
|
# The inline font_name property for the cell
|
25
28
|
# @return [String]
|
26
29
|
attr_reader :font_name
|
@@ -154,19 +157,9 @@ module Axlsx
|
|
154
157
|
set_run_style nil, :scheme, v
|
155
158
|
end
|
156
159
|
|
157
|
-
#
|
158
|
-
# @
|
159
|
-
|
160
|
-
|
161
|
-
# @return [Integer] The cellXfs item index applied to this cell.
|
162
|
-
# @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
|
163
|
-
def style=(v)
|
164
|
-
Axlsx::validate_unsigned_int(v)
|
165
|
-
count = styles.cellXfs.size
|
166
|
-
raise ArgumentError, "Invalid cellXfs id" unless v < count
|
167
|
-
@style = v
|
168
|
-
end
|
169
|
-
|
160
|
+
# Tries to work out the width of the longest line in the run
|
161
|
+
# @param [Array] widtharray this array is populated with the widths of each line in the run.
|
162
|
+
# @return [Array]
|
170
163
|
def autowidth(widtharray)
|
171
164
|
return if value.nil?
|
172
165
|
if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
|
@@ -184,19 +177,22 @@ module Axlsx
|
|
184
177
|
end
|
185
178
|
widtharray
|
186
179
|
end
|
187
|
-
|
180
|
+
|
188
181
|
# Utility method for setting inline style attributes
|
189
182
|
def set_run_style(validator, attr, value)
|
190
183
|
return unless INLINE_STYLES.include?(attr.to_sym)
|
191
184
|
Axlsx.send(validator, value) unless validator.nil?
|
192
185
|
self.instance_variable_set :"@#{attr.to_s}", value
|
193
186
|
end
|
194
|
-
|
187
|
+
|
188
|
+
# Serializes the RichTextRun
|
189
|
+
# @param [String] str
|
190
|
+
# @return [String]
|
195
191
|
def to_xml_string(str = '')
|
196
192
|
valid = RichTextRun::INLINE_STYLES
|
197
|
-
data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
|
193
|
+
data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
|
198
194
|
data = data.select { |key, value| valid.include?(key) && !value.nil? }
|
199
|
-
|
195
|
+
|
200
196
|
str << '<r><rPr>'
|
201
197
|
data.keys.each do |key|
|
202
198
|
case key
|
@@ -211,9 +207,9 @@ module Axlsx
|
|
211
207
|
clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
|
212
208
|
str << ('</rPr><t>' << clean_value << '</t></r>')
|
213
209
|
end
|
214
|
-
|
210
|
+
|
215
211
|
private
|
216
|
-
|
212
|
+
|
217
213
|
# Returns the width of a string according to the current style
|
218
214
|
# This is still not perfect...
|
219
215
|
# - scaling is not linear as font sizes increase
|
@@ -221,7 +217,7 @@ module Axlsx
|
|
221
217
|
font_scale = font_size / 10.0
|
222
218
|
string.count(Worksheet::THIN_CHARS) * font_scale
|
223
219
|
end
|
224
|
-
|
220
|
+
|
225
221
|
# we scale the font size if bold style is applied to either the style font or
|
226
222
|
# the cell itself. Yes, it is a bit of a hack, but it is much better than using
|
227
223
|
# imagemagick and loading metrics for every character.
|
@@ -230,15 +226,15 @@ module Axlsx
|
|
230
226
|
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
|
231
227
|
(font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
|
232
228
|
end
|
233
|
-
|
229
|
+
|
234
230
|
def style
|
235
231
|
cell.style
|
236
232
|
end
|
237
|
-
|
233
|
+
|
238
234
|
def styles
|
239
|
-
cell.row.worksheet.styles
|
235
|
+
cell.row.worksheet.styles
|
240
236
|
end
|
241
|
-
|
237
|
+
|
242
238
|
# Converts the value to the correct XML representation (fixes issues with
|
243
239
|
# Numbers)
|
244
240
|
def xml_value value
|
@@ -103,6 +103,13 @@ module Axlsx
|
|
103
103
|
c
|
104
104
|
end
|
105
105
|
|
106
|
+
# sets the color for every cell in this row
|
107
|
+
def color=(color)
|
108
|
+
each_with_index do | cell, index |
|
109
|
+
cell.color = color.is_a?(Array) ? color[index] : color
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
106
113
|
# sets the style for every cell in this row
|
107
114
|
def style=(style)
|
108
115
|
each_with_index do | cell, index |
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Axlsx
|
2
2
|
|
3
|
-
# The SheetPr class manages serialization
|
3
|
+
# The SheetPr class manages serialization of a worksheet's sheetPr element.
|
4
4
|
class SheetPr
|
5
5
|
include Axlsx::OptionsParser
|
6
6
|
include Axlsx::Accessors
|
@@ -8,7 +8,7 @@ module Axlsx
|
|
8
8
|
|
9
9
|
serializable_attributes :sync_horizontal,
|
10
10
|
:sync_vertical,
|
11
|
-
:
|
11
|
+
:transition_evaluation,
|
12
12
|
:transition_entry,
|
13
13
|
:published,
|
14
14
|
:filter_mode,
|
@@ -20,7 +20,7 @@ module Axlsx
|
|
20
20
|
# waving magic show to set up the attriubte accessors
|
21
21
|
boolean_attr_accessor :sync_horizontal,
|
22
22
|
:sync_vertical,
|
23
|
-
:
|
23
|
+
:transition_evaluation,
|
24
24
|
:transition_entry,
|
25
25
|
:published,
|
26
26
|
:filter_mode,
|
@@ -33,6 +33,7 @@ module Axlsx
|
|
33
33
|
def initialize(worksheet, options={})
|
34
34
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
35
35
|
@worksheet = worksheet
|
36
|
+
@outline_pr = nil
|
36
37
|
parse_options options
|
37
38
|
end
|
38
39
|
|
@@ -40,12 +41,18 @@ module Axlsx
|
|
40
41
|
# @return [Worksheet]
|
41
42
|
attr_reader :worksheet
|
42
43
|
|
44
|
+
# The tab color of the sheet.
|
45
|
+
# @return [Color]
|
46
|
+
attr_reader :tab_color
|
47
|
+
|
43
48
|
# Serialize the object
|
44
49
|
# @param [String] str serialized output will be appended to this object if provided.
|
45
50
|
# @return [String]
|
46
51
|
def to_xml_string(str = '')
|
47
52
|
update_properties
|
48
53
|
str << "<sheetPr #{serialized_attributes}>"
|
54
|
+
tab_color.to_xml_string(str, 'tabColor') if tab_color
|
55
|
+
outline_pr.to_xml_string(str) if @outline_pr
|
49
56
|
page_setup_pr.to_xml_string(str)
|
50
57
|
str << "</sheetPr>"
|
51
58
|
end
|
@@ -55,6 +62,17 @@ module Axlsx
|
|
55
62
|
def page_setup_pr
|
56
63
|
@page_setup_pr ||= PageSetUpPr.new
|
57
64
|
end
|
65
|
+
|
66
|
+
# The OutlinePr for this sheet pr object
|
67
|
+
# @return [OutlinePr]
|
68
|
+
def outline_pr
|
69
|
+
@outline_pr ||= OutlinePr.new
|
70
|
+
end
|
71
|
+
|
72
|
+
# @see tab_color
|
73
|
+
def tab_color=(v)
|
74
|
+
@tab_color ||= Color.new(:rgb => v)
|
75
|
+
end
|
58
76
|
|
59
77
|
private
|
60
78
|
|
@@ -20,6 +20,9 @@ module Axlsx
|
|
20
20
|
map{ |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
|
21
21
|
end
|
22
22
|
|
23
|
+
# renders the tables xml
|
24
|
+
# @param [String] str
|
25
|
+
# @return [String]
|
23
26
|
def to_xml_string(str = "")
|
24
27
|
return if empty?
|
25
28
|
str << "<tableParts count='#{size}'>"
|
@@ -8,7 +8,7 @@ module Axlsx
|
|
8
8
|
# definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count.
|
9
9
|
# This is used for autowidth calculations
|
10
10
|
THIN_CHARS = '^.acfijklrstxzFIJL()-'.freeze
|
11
|
-
|
11
|
+
|
12
12
|
# Creates a new worksheet.
|
13
13
|
# @note the recommended way to manage worksheets is Workbook#add_worksheet
|
14
14
|
# @see Workbook#add_worksheet
|
@@ -27,7 +27,7 @@ module Axlsx
|
|
27
27
|
yield self if block_given?
|
28
28
|
end
|
29
29
|
|
30
|
-
serializable_attributes :sheet_id, :
|
30
|
+
serializable_attributes :sheet_id, :state
|
31
31
|
|
32
32
|
# Initalizes page margin, setup and print options
|
33
33
|
# @param [Hash] options Options passed in from the initializer
|
@@ -91,7 +91,7 @@ module Axlsx
|
|
91
91
|
# @see [SheetFormatPr]
|
92
92
|
def sheet_format_pr
|
93
93
|
@sheet_format_pr ||= SheetFormatPr.new
|
94
|
-
|
94
|
+
yield @sheet_format_pr if block_given?
|
95
95
|
@sheet_format_pr
|
96
96
|
end
|
97
97
|
|
@@ -152,7 +152,7 @@ module Axlsx
|
|
152
152
|
# cell at a specific index. The block will be called with the row and column
|
153
153
|
# index in the missing cell was found.
|
154
154
|
# @example
|
155
|
-
# cols { |row_index, column_index|
|
155
|
+
# cols { |row_index, column_index| puts "warn - row #{row_index} does not have a cell at #{column_index}" }
|
156
156
|
def cols(&block)
|
157
157
|
@rows.transpose(&block)
|
158
158
|
end
|
@@ -264,7 +264,7 @@ module Axlsx
|
|
264
264
|
@header_footer
|
265
265
|
end
|
266
266
|
|
267
|
-
#
|
267
|
+
# convenience method to access all cells in this worksheet
|
268
268
|
# @return [Array] cells
|
269
269
|
def cells
|
270
270
|
rows.flatten
|
@@ -305,50 +305,6 @@ module Axlsx
|
|
305
305
|
@sheet_pr ||= SheetPr.new self
|
306
306
|
end
|
307
307
|
|
308
|
-
# Indicates if gridlines should be shown in the sheet.
|
309
|
-
# This is true by default.
|
310
|
-
# @return [Boolean]
|
311
|
-
# @deprecated Use SheetView#show_grid_lines= instead.
|
312
|
-
def show_gridlines=(v)
|
313
|
-
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
|
314
|
-
Axlsx::validate_boolean v
|
315
|
-
sheet_view.show_grid_lines = v
|
316
|
-
end
|
317
|
-
|
318
|
-
# @see selected
|
319
|
-
# @return [Boolean]
|
320
|
-
# @deprecated Use SheetView#tab_selected= instead.
|
321
|
-
def selected=(v)
|
322
|
-
warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
|
323
|
-
Axlsx::validate_boolean v
|
324
|
-
sheet_view.tab_selected = v
|
325
|
-
end
|
326
|
-
|
327
|
-
# Indicates if the worksheet should show gridlines or not
|
328
|
-
# @return Boolean
|
329
|
-
# @deprecated Use SheetView#show_grid_lines instead.
|
330
|
-
def show_gridlines
|
331
|
-
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
|
332
|
-
sheet_view.show_grid_lines
|
333
|
-
end
|
334
|
-
|
335
|
-
# Indicates if the worksheet is selected in the workbook
|
336
|
-
# It is possible to have more than one worksheet selected, however it might cause issues
|
337
|
-
# in some older versions of excel when using copy and paste.
|
338
|
-
# @return Boolean
|
339
|
-
# @deprecated Use SheetView#tab_selected instead.
|
340
|
-
def selected
|
341
|
-
warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
|
342
|
-
sheet_view.tab_selected
|
343
|
-
end
|
344
|
-
|
345
|
-
# (see #fit_to_page)
|
346
|
-
# @return [Boolean]
|
347
|
-
def fit_to_page=(v)
|
348
|
-
warn('axlsx::DEPRECIATED: Worksheet#fit_to_page has been depreciated. This value will automatically be set for you when you use PageSetup#fit_to.')
|
349
|
-
fit_to_page?
|
350
|
-
end
|
351
|
-
|
352
308
|
# The name of the worksheet
|
353
309
|
# The name of a worksheet must be unique in the workbook, and must not exceed 31 characters
|
354
310
|
# @param [String] name
|
@@ -555,7 +511,7 @@ module Axlsx
|
|
555
511
|
# @example This would set the first and third column widhts but leave the second column in autofit state.
|
556
512
|
# ws.column_widths 7.2, nil, 3
|
557
513
|
# @note For updating only a single column it is probably easier to just set the width of the ws.column_info[col_index].width directly
|
558
|
-
# @param [Integer|Float|
|
514
|
+
# @param [Integer|Float|nil] widths
|
559
515
|
def column_widths(*widths)
|
560
516
|
widths.each_with_index do |value, index|
|
561
517
|
next if value == nil
|
@@ -597,6 +553,7 @@ module Axlsx
|
|
597
553
|
add_autofilter_defined_name_to_workbook
|
598
554
|
str << '<sheet '
|
599
555
|
serialized_attributes str
|
556
|
+
str << ('name="' << name << '" ')
|
600
557
|
str << ('r:id="' << rId << '"></sheet>')
|
601
558
|
end
|
602
559
|
|
@@ -629,7 +586,7 @@ module Axlsx
|
|
629
586
|
# Returns the cell or cells defined using excel style A1:B3 references.
|
630
587
|
# @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber
|
631
588
|
# @return [Cell, Array]
|
632
|
-
def []
|
589
|
+
def [](cell_def)
|
633
590
|
return rows[cell_def] if cell_def.is_a?(Integer)
|
634
591
|
parts = cell_def.split(':').map{ |part| name_to_cell part }
|
635
592
|
if parts.size == 1
|