axlsx 1.1.8 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +5 -2
- data/CHANGELOG.md +39 -0
- data/README.md +48 -46
- data/Rakefile +3 -3
- data/examples/basic_charts.rb +8 -0
- data/examples/example.rb +7 -1
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/scraping_html.rb +91 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx.rb +14 -8
- data/lib/axlsx/drawing/bar_3D_chart.rb +2 -8
- data/lib/axlsx/drawing/chart.rb +29 -25
- data/lib/axlsx/drawing/d_lbls.rb +100 -0
- data/lib/axlsx/drawing/drawing.rb +2 -0
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -9
- data/lib/axlsx/drawing/pie_3D_chart.rb +3 -0
- data/lib/axlsx/drawing/scatter_chart.rb +2 -8
- data/lib/axlsx/drawing/two_cell_anchor.rb +38 -1
- data/lib/axlsx/util/simple_typed_list.rb +13 -6
- data/lib/axlsx/version.rb +2 -7
- data/lib/axlsx/workbook/defined_name.rb +174 -0
- data/lib/axlsx/workbook/defined_names.rb +21 -0
- data/lib/axlsx/workbook/workbook.rb +39 -13
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +24 -1
- data/lib/axlsx/workbook/worksheet/col.rb +15 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
- data/lib/axlsx/workbook/worksheet/comments.rb +8 -0
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
- data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
- data/lib/axlsx/workbook/worksheet/row.rb +1 -1
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +263 -380
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
- data/test/drawing/tc_bar_series.rb +1 -1
- data/test/drawing/tc_chart.rb +7 -1
- data/test/drawing/tc_d_lbls.rb +47 -0
- data/test/drawing/tc_drawing.rb +5 -4
- data/test/drawing/tc_line_series.rb +1 -1
- data/test/drawing/tc_pie_3D_chart.rb +1 -1
- data/test/drawing/tc_pie_series.rb +1 -1
- data/test/drawing/tc_scatter_series.rb +1 -1
- data/test/drawing/tc_series.rb +1 -1
- data/test/tc_package.rb +16 -1
- data/test/workbook/tc_defined_name.rb +41 -0
- data/test/workbook/tc_workbook.rb +5 -3
- data/test/workbook/worksheet/table/tc_table.rb +0 -8
- data/test/workbook/worksheet/tc_cell.rb +2 -4
- data/test/workbook/worksheet/tc_protected_range.rb +0 -1
- data/test/workbook/worksheet/tc_row.rb +2 -2
- data/test/workbook/worksheet/tc_worksheet.rb +19 -21
- metadata +48 -7
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
- **May.30.12**: 1.1.6 release
|
4
|
+
- data protection with passwords for sheets
|
5
|
+
- cell level input validators
|
6
|
+
- added support for two cell anchors for images
|
7
|
+
- test coverage now back up to 100%
|
8
|
+
- bugfix for merge cell sorting algorithm
|
9
|
+
- added fit_to method for page_setup to simplify managing witdh/height
|
10
|
+
- added ph (phonetics) and s (style) attributes for row.
|
11
|
+
- resolved all warnings generating from this gem.
|
12
|
+
- improved comment relationship management for multiple comments
|
13
|
+
|
14
|
+
- **May.13.12**: 1.1.5 release
|
15
|
+
- MOAR print options! You can now specify paper size, orientation,
|
16
|
+
fit to width, page margings and gridlines for printing.
|
17
|
+
- Support for adding comments to your worksheets
|
18
|
+
- bugfix for applying style to empty cells
|
19
|
+
- bugfix for parsing formula with multiple '='
|
20
|
+
|
21
|
+
- **May.3.12:**: 1.1.4 release
|
22
|
+
- MOAR examples
|
23
|
+
- added outline level for rows and columns
|
24
|
+
- rebuild of numeric and axis data sources for charts
|
25
|
+
- added delete to axis
|
26
|
+
- added tick and label mark skipping for cat axis in charts
|
27
|
+
- bugfix for table headers method
|
28
|
+
- sane(er) defaults for chart positioning
|
29
|
+
- bugfix in val_axis_data to properly serialize value axis data. Excel does not mind as it reads from the sheet, but nokogiri has a fit if the elements are empty.
|
30
|
+
- Added support for specifying the color of data series in charts.
|
31
|
+
- bugfix using add_cell on row mismanaged calls to update_column_info.
|
32
|
+
|
33
|
+
- ** April.25.12:**: 1.1.3 release
|
34
|
+
- Primarily because I am stupid.....Updates to readme to properly report version, add in missing docs and restructure example directory.
|
35
|
+
|
36
|
+
- ** April.25.12:**: 1.1.2 release
|
37
|
+
- Conditional Formatting completely implemented.
|
38
|
+
- refactoring / documentation for Style#add_style
|
39
|
+
- added in label rotation for chart axis labels
|
40
|
+
- bugfix to properly assign style and type info to cells when only partial information is provided in the types/style option
|
41
|
+
|
3
42
|
- ** April.18.12**: 1.1.1 release
|
4
43
|
- bugfix for autowidth calculations across multiple rows
|
5
44
|
- bugfix for dimension calculations with nil cells.
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
17
17
|
|
18
18
|
**License**: MIT License
|
19
19
|
|
20
|
-
**Latest Version**: 1.
|
20
|
+
**Latest Version**: 1.2.0
|
21
21
|
|
22
22
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
23
23
|
|
@@ -25,13 +25,23 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
25
25
|
|
26
26
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
27
27
|
|
28
|
-
**Release Date**:
|
28
|
+
**Release Date**: August 5th 2012
|
29
29
|
|
30
30
|
If you are working in rails, or with active record see:
|
31
|
-
http://github.com/randym/acts_as_xlsx
|
31
|
+
* http://github.com/randym/acts_as_xlsx
|
32
|
+
acts_as_xlsx is a simple ActiveRecord mixin that lets you generate a workbook with:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Posts.where(created_at > Time.now-30.days).to_xlsx
|
36
|
+
```
|
37
|
+
|
38
|
+
** and **
|
39
|
+
|
40
|
+
* http://github.com/straydogstudio/axlsx_rails
|
41
|
+
Axlsx_Rails provides an Axlsx renderer so you can move all your spreadsheet code from your controller into view files. Partials are supported so you can organize any code into reusable chunks (e.g. cover sheets, common styling, etc.) You can use it with acts_as_xlsx, placing the to_xlsx call in a view and add ':package => xlsx_package' to the parameter list. Now you can keep your controllers thin!
|
32
42
|
|
33
43
|
There are guides for using axlsx and acts_as_xlsx here:
|
34
|
-
[http://axlsx.
|
44
|
+
[http://axlsx.blog.randym.net](http://axlsx.blog.randym.net)
|
35
45
|
|
36
46
|
The examples directory contains a number of more specific examples as
|
37
47
|
well.
|
@@ -80,9 +90,13 @@ cell level input data validation.
|
|
80
90
|
|
81
91
|
**16. Support for password and non password based sheet protection.
|
82
92
|
|
83
|
-
**17. First stage interoperability support for GoogleDocs,
|
93
|
+
**17. First stage interoperability support for GoogleDocs, LibreOffice,
|
84
94
|
and Numbers
|
85
95
|
|
96
|
+
**18. Support for defined names, which gives you repeated header rows for printing.
|
97
|
+
|
98
|
+
**19. Data labels for charts as well as series color customization.
|
99
|
+
|
86
100
|
Installing
|
87
101
|
----------
|
88
102
|
|
@@ -95,7 +109,23 @@ To install Axlsx, use the following command:
|
|
95
109
|
|
96
110
|
The example listing is getting overly large to maintain here.
|
97
111
|
If you are using Yard, you will be able to see the examples in line below.
|
98
|
-
|
112
|
+
|
113
|
+
Here's a teaser that kicks about 2% of what the gem can do.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
Axlsx::Package.new do |p|
|
117
|
+
p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
|
118
|
+
sheet.add_row ["Simple Pie Chart"]
|
119
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
120
|
+
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
|
121
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ['FF0000', '00FF00', '0000FF']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
p.serialize('simple.xlsx')
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
Please see the [examples](https://github.com/randym/axlsx/tree/master/examples/example.rb) for more.
|
99
129
|
|
100
130
|
{include:file:examples/example.rb}
|
101
131
|
|
@@ -115,6 +145,16 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
115
145
|
|
116
146
|
#Change log
|
117
147
|
---------
|
148
|
+
- **August.5.12**: 1.2.0
|
149
|
+
- rebuilt worksheet serialization to clean up the code base a bit.
|
150
|
+
- added data labels for charts
|
151
|
+
- added table header printing for each sheet via defined_name. This
|
152
|
+
means that when you print your worksheet, the header rows show for every page
|
153
|
+
- **July.??.12**: 1.1.9 release
|
154
|
+
- lots of code clean up for worksheet
|
155
|
+
- added in data labels for pie charts, line charts and bar charts.
|
156
|
+
- bugfix chard with data in a sheet that has a space in the name are
|
157
|
+
now auto updating formula based values
|
118
158
|
- **July.14.12**: 1.1.8 release
|
119
159
|
- added html entity encoding for sheet names. This allows you to use
|
120
160
|
characters like '<' and '&' in your sheet names.
|
@@ -133,45 +173,6 @@ in value caches
|
|
133
173
|
charts.
|
134
174
|
- Add sheet views with panes
|
135
175
|
|
136
|
-
- **May.30.12**: 1.1.6 release
|
137
|
-
- data protection with passwords for sheets
|
138
|
-
- cell level input validators
|
139
|
-
- added support for two cell anchors for images
|
140
|
-
- test coverage now back up to 100%
|
141
|
-
- bugfix for merge cell sorting algorithm
|
142
|
-
- added fit_to method for page_setup to simplify managing witdh/height
|
143
|
-
- added ph (phonetics) and s (style) attributes for row.
|
144
|
-
- resolved all warnings generating from this gem.
|
145
|
-
- improved comment relationship management for multiple comments
|
146
|
-
|
147
|
-
- **May.13.12**: 1.1.5 release
|
148
|
-
- MOAR print options! You can now specify paper size, orientation,
|
149
|
-
fit to width, page margings and gridlines for printing.
|
150
|
-
- Support for adding comments to your worksheets
|
151
|
-
- bugfix for applying style to empty cells
|
152
|
-
- bugfix for parsing formula with multiple '='
|
153
|
-
|
154
|
-
- **May.3.12:**: 1.1.4 release
|
155
|
-
- MOAR examples
|
156
|
-
- added outline level for rows and columns
|
157
|
-
- rebuild of numeric and axis data sources for charts
|
158
|
-
- added delete to axis
|
159
|
-
- added tick and label mark skipping for cat axis in charts
|
160
|
-
- bugfix for table headers method
|
161
|
-
- sane(er) defaults for chart positioning
|
162
|
-
- bugfix in val_axis_data to properly serialize value axis data. Excel does not mind as it reads from the sheet, but nokogiri has a fit if the elements are empty.
|
163
|
-
- Added support for specifying the color of data series in charts.
|
164
|
-
- bugfix using add_cell on row mismanaged calls to update_column_info.
|
165
|
-
|
166
|
-
- ** April.25.12:**: 1.1.3 release
|
167
|
-
- Primarily because I am stupid.....Updates to readme to properly report version, add in missing docs and restructure example directory.
|
168
|
-
|
169
|
-
- ** April.25.12:**: 1.1.2 release
|
170
|
-
- Conditional Formatting completely implemented.
|
171
|
-
- refactoring / documentation for Style#add_style
|
172
|
-
- added in label rotation for chart axis labels
|
173
|
-
- bugfix to properly assign style and type info to cells when only partial information is provided in the types/style option
|
174
|
-
|
175
176
|
Please see the {file:CHANGELOG.md} document for past release information.
|
176
177
|
|
177
178
|
# Known interoperability issues.
|
@@ -190,7 +191,6 @@ related to themes, which axlsx does not implement at this time.
|
|
190
191
|
2. Google Docs
|
191
192
|
- Images are known to not work with google docs
|
192
193
|
- border colors do not work
|
193
|
-
- Charts, for the most part, do not work. Google docs has some specific requirements about how the worksheet is set up to create a chart.
|
194
194
|
|
195
195
|
3. Numbers
|
196
196
|
- you must set 'use_shared_strings' to true
|
@@ -227,6 +227,8 @@ done without the help of the people below.
|
|
227
227
|
|
228
228
|
[rfc2616](https://github.com/rfc2616) - for FINALLY working out the interop issues with google docs.
|
229
229
|
|
230
|
+
[straydogstudio](https://github.com/straydocstudio) - For making an AWESOME axlsx templating gem for rails.
|
231
|
+
|
230
232
|
#Copyright and License
|
231
233
|
----------
|
232
234
|
|
data/Rakefile
CHANGED
@@ -9,9 +9,9 @@ task :benchmark do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
task :gendoc do
|
12
|
-
puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
13
|
-
|
14
|
-
|
12
|
+
#puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
13
|
+
system "yardoc"
|
14
|
+
system "yard stats --list-undoc"
|
15
15
|
end
|
16
16
|
|
17
17
|
task :test do
|
data/examples/basic_charts.rb
CHANGED
@@ -9,6 +9,10 @@ wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
|
9
9
|
sheet.add_row [1, 2, 3, 4]
|
10
10
|
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=> 'dark corner here') do |chart|
|
11
11
|
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
|
12
|
+
chart.d_lbls.show_val = true
|
13
|
+
chart.d_lbls.show_percent = true
|
14
|
+
chart.d_lbls.d_lbl_pos = :outEnd
|
15
|
+
chart.d_lbls.show_leader_lines = true
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -18,6 +22,8 @@ end
|
|
18
22
|
sheet.add_row [1, 2, 3, '=sum(A2:C2)']
|
19
23
|
sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart|
|
20
24
|
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob'
|
25
|
+
chart.d_lbls.show_val = true
|
26
|
+
chart.d_lbls.show_cat_name = true
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
@@ -30,6 +36,8 @@ end
|
|
30
36
|
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
31
37
|
chart.valAxis.label_rotation = -45
|
32
38
|
chart.catAxis.label_rotation = 45
|
39
|
+
chart.d_lbls.d_lbl_pos = :outEnd
|
40
|
+
chart.d_lbls.show_val = true
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
data/examples/example.rb
CHANGED
@@ -238,7 +238,7 @@ wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
|
238
238
|
sheet.add_row ["Simple Pie Chart"]
|
239
239
|
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
240
240
|
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
|
241
|
-
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"]
|
241
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ['FF0000', '00FF00', '0000FF']
|
242
242
|
end
|
243
243
|
end
|
244
244
|
#```
|
@@ -314,6 +314,12 @@ wb.add_worksheet(:name => "No Gridlines") do |sheet|
|
|
314
314
|
end
|
315
315
|
##```
|
316
316
|
|
317
|
+
#```ruby
|
318
|
+
wb.add_worksheet(:name => "repeated header") do |sheet|
|
319
|
+
sheet.add_row %w(These Column Header Will Render On Every Printed Sheet)
|
320
|
+
200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) }
|
321
|
+
wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
|
322
|
+
end
|
317
323
|
|
318
324
|
# Sheet Protection and excluding cells from locking.
|
319
325
|
unlocked = wb.styles.add_style :locked => false
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'axlsx'
|
5
|
+
|
6
|
+
class Scraper
|
7
|
+
|
8
|
+
def initialize(url, selector)
|
9
|
+
@url = url
|
10
|
+
@selector = selector
|
11
|
+
end
|
12
|
+
|
13
|
+
def hooks
|
14
|
+
@hooks ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_hook(clue, p_roc)
|
18
|
+
hooks[clue] = p_roc
|
19
|
+
end
|
20
|
+
|
21
|
+
def export(file_name)
|
22
|
+
Scraper.clues.each do |clue|
|
23
|
+
if detail = parse_clue(clue)
|
24
|
+
output << [clue, detail.pop]
|
25
|
+
detail.each { |datum| output << ['', datum] }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
serialize(file_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.clues
|
34
|
+
@clues ||= ['Operating system', 'Processors', 'Chipset', 'Memory type', 'Hard drive', 'Graphics',
|
35
|
+
'Ports', 'Webcam', 'Pointing device', 'Keyboard', 'Network interface', 'Chipset', 'Wireless',
|
36
|
+
'Power supply type', 'Energy efficiency', 'Weight', 'Minimum dimensions (W x D x H)',
|
37
|
+
'Warranty', 'Software included', 'Product color']
|
38
|
+
end
|
39
|
+
|
40
|
+
def doc
|
41
|
+
@doc ||= begin
|
42
|
+
Nokogiri::HTML(open(@url))
|
43
|
+
rescue
|
44
|
+
raise ArgumentError, 'Invalid URL - Nothing to parse'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def output
|
49
|
+
@output ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def selector_for_clue(clue)
|
53
|
+
@selector % clue
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_clue(clue)
|
57
|
+
if element = doc.at(selector_for_clue(clue))
|
58
|
+
call_hook(clue, element) || element.inner_html.split('<br>').each(&:strip)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def call_hook(clue, element)
|
63
|
+
if hooks[clue].is_a? Proc
|
64
|
+
value = hooks[clue].call(element)
|
65
|
+
value.is_a?(Array) ? value : [value]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def package
|
70
|
+
@package ||= Axlsx::Package.new
|
71
|
+
end
|
72
|
+
|
73
|
+
def serialize(file_name)
|
74
|
+
package.workbook.add_worksheet do |sheet|
|
75
|
+
output.each { |datum| sheet.add_row datum }
|
76
|
+
end
|
77
|
+
package.serialize(file_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
scraper = Scraper.new("http://h10010.www1.hp.com/wwpc/ie/en/ho/WF06b/321957-321957-3329742-89318-89318-5186820-5231694.html?dnr=1", "//td[text()='%s']/following-sibling::td")
|
82
|
+
|
83
|
+
# define a custom action to take against any elements found.
|
84
|
+
os_parse = Proc.new do |element|
|
85
|
+
element.inner_html.split('<br>').each(&:strip!).each(&:upcase!)
|
86
|
+
end
|
87
|
+
|
88
|
+
scraper.add_hook('Operating system', os_parse)
|
89
|
+
|
90
|
+
scraper.export('foo.xlsx')
|
91
|
+
|
Binary file
|
data/lib/axlsx.rb
CHANGED
@@ -39,13 +39,21 @@ end
|
|
39
39
|
|
40
40
|
# xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
|
41
41
|
module Axlsx
|
42
|
+
|
42
43
|
# determines the cell range for the items provided
|
43
|
-
def self.cell_range(
|
44
|
-
return "" unless
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def self.cell_range(cells, absolute=true)
|
45
|
+
return "" unless cells.first.is_a? Cell
|
46
|
+
sort_cells(cells)
|
47
|
+
reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
|
48
|
+
absolute ? "'#{cells.first.row.worksheet.name}'!#{reference}" : reference
|
49
|
+
end
|
50
|
+
|
51
|
+
# sorts the array of cells provided to start from the minimum x,y to
|
52
|
+
# the maximum x.y#
|
53
|
+
# @param [Array] cells
|
54
|
+
# @return [Array]
|
55
|
+
def self.sort_cells(cells)
|
56
|
+
cells.sort { |x, y| [x.index, x.row.index] <=> [y.index, y.row.index] }
|
49
57
|
end
|
50
58
|
|
51
59
|
#global reference html entity encoding
|
@@ -60,9 +68,7 @@ module Axlsx
|
|
60
68
|
v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
|
61
69
|
val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
|
62
70
|
end
|
63
|
-
|
64
71
|
[v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]
|
65
|
-
|
66
72
|
end
|
67
73
|
|
68
74
|
# converts the column index into alphabetical values.
|
@@ -77,6 +77,7 @@ module Axlsx
|
|
77
77
|
super(frame, options)
|
78
78
|
@series_type = BarSeries
|
79
79
|
@view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
|
80
|
+
@d_lbls = nil
|
80
81
|
end
|
81
82
|
|
82
83
|
# The direction of the bars in the chart
|
@@ -125,14 +126,7 @@ module Axlsx
|
|
125
126
|
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
|
126
127
|
str_inner << '<c:varyColors val="1"/>'
|
127
128
|
@series.each { |ser| ser.to_xml_string(str_inner) }
|
128
|
-
|
129
|
-
str_inner << '<c:showLegendKey val="0"/>'
|
130
|
-
str_inner << '<c:showVal val="0"/>'
|
131
|
-
str_inner << '<c:showCatName val="0"/>'
|
132
|
-
str_inner << '<c:showSerName val="0"/>'
|
133
|
-
str_inner << '<c:showPercent val="0"/>'
|
134
|
-
str_inner << '<c:showBubbleSize val="0"/>'
|
135
|
-
str_inner << '</c:dLbls>'
|
129
|
+
@d_lbls.to_xml_string(str) if @d_lbls
|
136
130
|
str_inner << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
|
137
131
|
str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
|
138
132
|
str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
|
data/lib/axlsx/drawing/chart.rb
CHANGED
@@ -46,7 +46,10 @@ module Axlsx
|
|
46
46
|
attr_reader :series_type
|
47
47
|
|
48
48
|
#TODO data labels!
|
49
|
-
|
49
|
+
def d_lbls
|
50
|
+
@d_lbls ||= DLbls.new(self.class)
|
51
|
+
end
|
52
|
+
|
50
53
|
|
51
54
|
# The title object for the chart.
|
52
55
|
# @return [Title]
|
@@ -154,16 +157,32 @@ module Axlsx
|
|
154
157
|
str << '</c:chartSpace>'
|
155
158
|
end
|
156
159
|
|
157
|
-
# This is a short cut method to set the start
|
160
|
+
# This is a short cut method to set the anchor start marker position
|
158
161
|
# If you need finer granularity in positioning use
|
159
|
-
#
|
160
|
-
#
|
162
|
+
#
|
163
|
+
# This helper method acceps a fairly wide range of inputs exampled
|
164
|
+
# below
|
165
|
+
#
|
166
|
+
# @example
|
167
|
+
#
|
168
|
+
# start_at 0, 5 # The anchor start marker is set to 6th row of
|
169
|
+
# the first column
|
170
|
+
#
|
171
|
+
# start_at [0, 5] # The anchor start marker is set to start on the 6th row
|
172
|
+
# of the first column
|
173
|
+
#
|
174
|
+
# start_at "C1" # The anchor start marker is set to start on the first row
|
175
|
+
# of the third column
|
176
|
+
#
|
177
|
+
# start_at sheet.rows.first.cells.last # The anchor start
|
178
|
+
# marker is set to the location of a specific cell.
|
179
|
+
#
|
180
|
+
# @param [Array|String|Cell] x the column, coordinates, string
|
181
|
+
# reference or cell to use in setting the start marker position.
|
161
182
|
# @param [Integer] y The row
|
162
183
|
# @return [Marker]
|
163
184
|
def start_at(x=0, y=0)
|
164
|
-
|
165
|
-
@graphic_frame.anchor.from.col = x
|
166
|
-
@graphic_frame.anchor.from.row = y
|
185
|
+
@graphic_frame.anchor.start_at(x, y)
|
167
186
|
end
|
168
187
|
|
169
188
|
# This is a short cut method to set the end anchor position
|
@@ -172,27 +191,12 @@ module Axlsx
|
|
172
191
|
# @param [Integer] x The column - default 10
|
173
192
|
# @param [Integer] y The row - default 10
|
174
193
|
# @return [Marker]
|
194
|
+
# @see start_at
|
175
195
|
def end_at(x=10, y=10)
|
176
|
-
|
177
|
-
@graphic_frame.anchor.to.col = x
|
178
|
-
@graphic_frame.anchor.to.row = y
|
179
|
-
end
|
180
|
-
|
181
|
-
private
|
182
|
-
|
183
|
-
def parse_coord_args(x, y=0)
|
184
|
-
if x.is_a?(String)
|
185
|
-
x, y = *Axlsx::name_to_indices(x)
|
186
|
-
end
|
187
|
-
if x.is_a?(Cell)
|
188
|
-
x, y = *x.pos
|
189
|
-
end
|
190
|
-
if x.is_a?(Array)
|
191
|
-
x, y = *x
|
192
|
-
end
|
193
|
-
[x, y]
|
196
|
+
@graphic_frame.anchor.end_at(x, y)
|
194
197
|
end
|
195
198
|
|
199
|
+
# sets the view_3D object for the chart
|
196
200
|
def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
|
197
201
|
alias :view3D= :view_3D=
|
198
202
|
|