axlsx 1.1.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +5 -2
- data/CHANGELOG.md +39 -0
- data/README.md +84 -46
- data/Rakefile +3 -2
- data/examples/basic_charts.rb +8 -0
- data/examples/chart_colors.rb +18 -3
- data/examples/example.rb +106 -46
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.pdf +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/content_type/content_type.rb +2 -0
- data/lib/axlsx/content_type/default.rb +21 -12
- data/lib/axlsx/content_type/override.rb +22 -11
- data/lib/axlsx/doc_props/app.rb +36 -32
- data/lib/axlsx/doc_props/core.rb +9 -5
- data/lib/axlsx/drawing/ax_data_source.rb +7 -6
- data/lib/axlsx/drawing/axis.rb +48 -27
- data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
- data/lib/axlsx/drawing/bar_series.rb +1 -0
- data/lib/axlsx/drawing/cat_axis.rb +42 -38
- data/lib/axlsx/drawing/chart.rb +63 -52
- data/lib/axlsx/drawing/d_lbls.rb +100 -0
- data/lib/axlsx/drawing/drawing.rb +7 -4
- data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
- data/lib/axlsx/drawing/num_data_source.rb +1 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
- data/lib/axlsx/drawing/scatter_chart.rb +2 -8
- data/lib/axlsx/drawing/two_cell_anchor.rb +41 -9
- data/lib/axlsx/drawing/view_3D.rb +41 -31
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +11 -11
- data/lib/axlsx/rels/relationship.rb +3 -3
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +15 -8
- data/lib/axlsx/util/validators.rb +2 -2
- 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 -14
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +25 -2
- 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_bar.rb +1 -1
- 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/page_setup.rb +9 -0
- data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -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 +300 -293
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
- data/lib/axlsx.rb +21 -14
- data/test/content_type/tc_content_type.rb +1 -6
- data/test/doc_props/tc_core.rb +1 -1
- data/test/drawing/tc_axis.rb +8 -0
- data/test/drawing/tc_bar_3D_chart.rb +12 -12
- data/test/drawing/tc_bar_series.rb +1 -2
- data/test/drawing/tc_chart.rb +8 -6
- 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 +4 -8
- 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/drawing/tc_view_3D.rb +18 -18
- data/test/tc_package.rb +18 -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_page_setup.rb +20 -3
- data/test/workbook/worksheet/tc_protected_range.rb +17 -0
- data/test/workbook/worksheet/tc_row.rb +2 -2
- data/test/workbook/worksheet/tc_selection.rb +1 -1
- data/test/workbook/worksheet/tc_worksheet.rb +53 -34
- metadata +93 -101
- data/examples/axis-titles.xlsx +0 -0
- data/examples/basic_charts.xlsx +0 -0
- data/examples/chart_colors.xlsx +0 -0
- data/examples/charts.xlsx +0 -0
- data/examples/conditional_formatting/getting_barred.xlsx +0 -0
- data/examples/doc/_index.html +0 -84
- data/examples/doc/class_list.html +0 -47
- data/examples/doc/css/common.css +0 -1
- data/examples/doc/css/full_list.css +0 -55
- data/examples/doc/css/style.css +0 -322
- data/examples/doc/file_list.html +0 -46
- data/examples/doc/frames.html +0 -13
- data/examples/doc/index.html +0 -84
- data/examples/doc/js/app.js +0 -205
- data/examples/doc/js/full_list.js +0 -173
- data/examples/doc/js/jquery.js +0 -16
- data/examples/doc/method_list.html +0 -46
- data/examples/doc/top-level-namespace.html +0 -95
- data/examples/examples_saved.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/fish.xlsx +0 -0
- data/examples/pareto.rb +0 -28
- data/examples/pareto.xlsx +0 -0
- data/examples/pie_chart_excel.xlsx +0 -0
- data/examples/pie_chart_saved.xlsx +0 -0
- data/examples/sheet_protection.xlsx +0 -0
- data/examples/sheet_view.xlsx +0 -0
- data/examples/two_cell_anchor_image.xlsx +0 -0
- data/examples/~$example.xlsx +0 -0
- data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
- data/lib/axlsx/drawing/data_source.rb~ +0 -51
- data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
- data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
- data/lib/axlsx/drawing/num_data.rb~ +0 -51
- data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
- data/lib/axlsx/drawing/num_val.rb~ +0 -40
- data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
- data/lib/axlsx/drawing/ref.rb~ +0 -41
- data/lib/axlsx/drawing/str_data.rb~ +0 -58
- data/lib/axlsx/drawing/str_val.rb~ +0 -35
- data/lib/axlsx/drawing/vml_drawing.rb~ +0 -6
- data/lib/axlsx/drawing/vml_shape.rb~ +0 -61
- data/lib/axlsx/util/cbf.rb +0 -333
- data/lib/axlsx/util/cfb.rb~ +0 -201
- data/lib/axlsx/util/font_tables.rb~ +0 -0
- data/lib/axlsx/util/ms_off_crypto.rb +0 -189
- data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
- data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
- data/lib/axlsx/util/parser.rb~ +0 -6
- data/lib/axlsx/util/storage.rb~ +0 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
- data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
- data/lib/axlsx/workbook/worksheet/comment.rb~ +0 -91
- data/lib/axlsx/workbook/worksheet/comments.rb~ +0 -86
- data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
- data/lib/schema/dc.xsd~ +0 -118
- data/lib/schema/dcterms.xsd~ +0 -331
- data/lib/schema/opc-coreProperties.xsd~ +0 -50
- data/test/drawing/tc_data_source.rb~ +0 -30
- data/test/drawing/tc_num_data.rb~ +0 -35
- data/test/drawing/tc_num_val.rb~ +0 -29
- data/test/drawing/tc_str_data.rb~ +0 -30
- data/test/drawing/tc_str_val.rb~ +0 -26
- data/test/drawing/tc_vml_drawing.rb~ +0 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
- data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
- data/test/workbook/worksheet/tc_col.rb~ +0 -10
- data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
- data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
- data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Axlsx: Office Open XML Spreadsheet Generation
|
|
2
2
|
====================================
|
|
3
3
|
[](http://travis-ci.org/randym/axlsx/)
|
|
4
|
+
[](http://www.pledgie.com/campaigns/17814)
|
|
4
5
|
|
|
5
6
|
**IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
|
|
6
7
|
|
|
@@ -16,7 +17,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
|
16
17
|
|
|
17
18
|
**License**: MIT License
|
|
18
19
|
|
|
19
|
-
**Latest Version**: 1.
|
|
20
|
+
**Latest Version**: 1.2.0
|
|
20
21
|
|
|
21
22
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
|
22
23
|
|
|
@@ -24,13 +25,23 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
|
24
25
|
|
|
25
26
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
|
26
27
|
|
|
27
|
-
**Release Date**:
|
|
28
|
+
**Release Date**: August 5th 2012
|
|
28
29
|
|
|
29
30
|
If you are working in rails, or with active record see:
|
|
30
|
-
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!
|
|
31
42
|
|
|
32
43
|
There are guides for using axlsx and acts_as_xlsx here:
|
|
33
|
-
[http://axlsx.
|
|
44
|
+
[http://axlsx.blog.randym.net](http://axlsx.blog.randym.net)
|
|
34
45
|
|
|
35
46
|
The examples directory contains a number of more specific examples as
|
|
36
47
|
well.
|
|
@@ -69,8 +80,6 @@ Feature List
|
|
|
69
80
|
**10. Support for formulas, merging, row and column outlining as well as
|
|
70
81
|
cell level input data validation.
|
|
71
82
|
|
|
72
|
-
**11. Support for cell merging as well as column and row outline
|
|
73
|
-
|
|
74
83
|
**12. Auto filtering tables with worksheet.auto_filter as well as support for Tables
|
|
75
84
|
|
|
76
85
|
**13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
|
|
@@ -81,6 +90,13 @@ cell level input data validation.
|
|
|
81
90
|
|
|
82
91
|
**16. Support for password and non password based sheet protection.
|
|
83
92
|
|
|
93
|
+
**17. First stage interoperability support for GoogleDocs, LibreOffice,
|
|
94
|
+
and Numbers
|
|
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
|
+
|
|
84
100
|
Installing
|
|
85
101
|
----------
|
|
86
102
|
|
|
@@ -93,7 +109,23 @@ To install Axlsx, use the following command:
|
|
|
93
109
|
|
|
94
110
|
The example listing is getting overly large to maintain here.
|
|
95
111
|
If you are using Yard, you will be able to see the examples in line below.
|
|
96
|
-
|
|
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.
|
|
97
129
|
|
|
98
130
|
{include:file:examples/example.rb}
|
|
99
131
|
|
|
@@ -113,6 +145,25 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
|
113
145
|
|
|
114
146
|
#Change log
|
|
115
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
|
|
158
|
+
- **July.14.12**: 1.1.8 release
|
|
159
|
+
- added html entity encoding for sheet names. This allows you to use
|
|
160
|
+
characters like '<' and '&' in your sheet names.
|
|
161
|
+
- new - first round google docs interoperability
|
|
162
|
+
- added filter to strip out control characters from cell data.
|
|
163
|
+
- added in interop requirements so that charts are properly exported
|
|
164
|
+
to PDF from Libra Office
|
|
165
|
+
- various readability improvements and work standardizing attribute
|
|
166
|
+
names to snake_case. Aliases are provided for backward compatiblity
|
|
116
167
|
- **June.11.12**: 1.1.7 release
|
|
117
168
|
- fix chart rendering issue when label offset is specified as a
|
|
118
169
|
percentage in serialization and ensure that formula are not stored
|
|
@@ -122,47 +173,30 @@ in value caches
|
|
|
122
173
|
charts.
|
|
123
174
|
- Add sheet views with panes
|
|
124
175
|
|
|
125
|
-
- **May.30.12**: 1.1.6 release
|
|
126
|
-
- data protection with passwords for sheets
|
|
127
|
-
- cell level input validators
|
|
128
|
-
- added support for two cell anchors for images
|
|
129
|
-
- test coverage now back up to 100%
|
|
130
|
-
- bugfix for merge cell sorting algorithm
|
|
131
|
-
- added fit_to method for page_setup to simplify managing witdh/height
|
|
132
|
-
- added ph (phonetics) and s (style) attributes for row.
|
|
133
|
-
- resolved all warnings generating from this gem.
|
|
134
|
-
- improved comment relationship management for multiple comments
|
|
135
|
-
|
|
136
|
-
- **May.13.12**: 1.1.5 release
|
|
137
|
-
- MOAR print options! You can now specify paper size, orientation,
|
|
138
|
-
fit to width, page margings and gridlines for printing.
|
|
139
|
-
- Support for adding comments to your worksheets
|
|
140
|
-
- bugfix for applying style to empty cells
|
|
141
|
-
- bugfix for parsing formula with multiple '='
|
|
142
|
-
|
|
143
|
-
- **May.3.12:**: 1.1.4 release
|
|
144
|
-
- MOAR examples
|
|
145
|
-
- added outline level for rows and columns
|
|
146
|
-
- rebuild of numeric and axis data sources for charts
|
|
147
|
-
- added delete to axis
|
|
148
|
-
- added tick and label mark skipping for cat axis in charts
|
|
149
|
-
- bugfix for table headers method
|
|
150
|
-
- sane(er) defaults for chart positioning
|
|
151
|
-
- 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.
|
|
152
|
-
- Added support for specifying the color of data series in charts.
|
|
153
|
-
- bugfix using add_cell on row mismanaged calls to update_column_info.
|
|
154
|
-
|
|
155
|
-
- ** April.25.12:**: 1.1.3 release
|
|
156
|
-
- Primarily because I am stupid.....Updates to readme to properly report version, add in missing docs and restructure example directory.
|
|
157
|
-
|
|
158
|
-
- ** April.25.12:**: 1.1.2 release
|
|
159
|
-
- Conditional Formatting completely implemented.
|
|
160
|
-
- refactoring / documentation for Style#add_style
|
|
161
|
-
- added in label rotation for chart axis labels
|
|
162
|
-
- bugfix to properly assign style and type info to cells when only partial information is provided in the types/style option
|
|
163
|
-
|
|
164
176
|
Please see the {file:CHANGELOG.md} document for past release information.
|
|
165
177
|
|
|
178
|
+
# Known interoperability issues.
|
|
179
|
+
As axslx implements the Office Open XML (ECMA-376 spec) much of the
|
|
180
|
+
functionality is interoperable with other spreadsheet software. Below is
|
|
181
|
+
a listing of some known issues.
|
|
182
|
+
|
|
183
|
+
1. Libra Office
|
|
184
|
+
- You must specify colors for your series. see examples/chart_colors.rb
|
|
185
|
+
for an example.
|
|
186
|
+
- You must use data in your sheet for charts. You cannot use hard coded
|
|
187
|
+
values.
|
|
188
|
+
- Chart axis and gridlines do not render. I have a feeling this is
|
|
189
|
+
related to themes, which axlsx does not implement at this time.
|
|
190
|
+
|
|
191
|
+
2. Google Docs
|
|
192
|
+
- Images are known to not work with google docs
|
|
193
|
+
- border colors do not work
|
|
194
|
+
|
|
195
|
+
3. Numbers
|
|
196
|
+
- you must set 'use_shared_strings' to true
|
|
197
|
+
- charts do not render
|
|
198
|
+
|
|
199
|
+
|
|
166
200
|
#Thanks!
|
|
167
201
|
|
|
168
202
|
Open source software is a community effort. None of this could have been
|
|
@@ -191,6 +225,10 @@ done without the help of the people below.
|
|
|
191
225
|
|
|
192
226
|
[janhuehne](https://github.com/janhuehne) - for working out the decoder ring and adding in cell level validation, and providing a support for window panes.
|
|
193
227
|
|
|
228
|
+
[rfc2616](https://github.com/rfc2616) - for FINALLY working out the interop issues with google docs.
|
|
229
|
+
|
|
230
|
+
[straydogstudio](https://github.com/straydocstudio) - For making an AWESOME axlsx templating gem for rails.
|
|
231
|
+
|
|
194
232
|
#Copyright and License
|
|
195
233
|
----------
|
|
196
234
|
|
data/Rakefile
CHANGED
|
@@ -9,8 +9,9 @@ task :benchmark do
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
task :gendoc do
|
|
12
|
-
|
|
13
|
-
|
|
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"
|
|
14
15
|
end
|
|
15
16
|
|
|
16
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/chart_colors.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
|
require 'axlsx'
|
|
5
5
|
|
|
6
6
|
p = Axlsx::Package.new
|
|
@@ -36,7 +36,7 @@ end
|
|
|
36
36
|
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
|
37
37
|
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
|
38
38
|
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
|
|
39
|
-
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF']
|
|
39
|
+
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF', '000000']
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ end
|
|
|
45
45
|
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
46
46
|
sheet.add_row ["First", 1, 5, 7, 9]
|
|
47
47
|
sheet.add_row ["Second", 5, 2, 14, 9]
|
|
48
|
-
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY =>
|
|
48
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 30) do |chart|
|
|
49
49
|
chart.start_at 0, 2
|
|
50
50
|
chart.end_at 10, 15
|
|
51
51
|
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
|
|
@@ -53,6 +53,21 @@ wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
wb.add_worksheet(:name => 'Line Chart with Axis colors') do |sheet|
|
|
57
|
+
sheet.add_row ["First", 1, 5, 7, 9]
|
|
58
|
+
sheet.add_row ["Second", 5, 2, 14, 9]
|
|
59
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "example 7: Flat Line Chart", :rot_x => 0, :perspective => 0) do |chart|
|
|
60
|
+
chart.valAxis.color = "FFFF00"
|
|
61
|
+
chart.catAxis.color = "00FFFF"
|
|
62
|
+
chart.serAxis.delete = true
|
|
63
|
+
chart.start_at 0, 2
|
|
64
|
+
chart.end_at 10, 15
|
|
65
|
+
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
|
|
66
|
+
chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"], :color => "00FF00"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
56
71
|
##Generating A Scatter Chart
|
|
57
72
|
|
|
58
73
|
wb.add_worksheet(:name => "Scatter Chart") do |sheet|
|
data/examples/example.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env ruby -w -s
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
3
|
+
# $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
4
4
|
|
|
5
5
|
#```ruby
|
|
6
6
|
require 'axlsx'
|
|
@@ -210,12 +210,9 @@ end
|
|
|
210
210
|
#```ruby
|
|
211
211
|
wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
|
212
212
|
sheet.add_row ["A Simple Bar Chart"]
|
|
213
|
-
sheet.add_row [
|
|
214
|
-
sheet.
|
|
215
|
-
|
|
216
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
|
217
|
-
chart.valAxis.label_rotation = -45
|
|
218
|
-
chart.catAxis.label_rotation = 45
|
|
213
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
|
214
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
|
|
215
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"]
|
|
219
216
|
end
|
|
220
217
|
end
|
|
221
218
|
#```
|
|
@@ -224,11 +221,10 @@ end
|
|
|
224
221
|
|
|
225
222
|
#```ruby
|
|
226
223
|
wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
|
|
227
|
-
sheet.add_row ["
|
|
228
|
-
sheet.add_row [
|
|
229
|
-
sheet.
|
|
230
|
-
|
|
231
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
|
224
|
+
sheet.add_row ["Bar Chart without gridlines"]
|
|
225
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
|
226
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
|
|
227
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"]
|
|
232
228
|
chart.valAxis.gridlines = false
|
|
233
229
|
chart.catAxis.gridlines = false
|
|
234
230
|
end
|
|
@@ -239,28 +235,10 @@ end
|
|
|
239
235
|
|
|
240
236
|
#```ruby
|
|
241
237
|
wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
|
242
|
-
sheet.add_row ["
|
|
243
|
-
sheet.add_row [
|
|
244
|
-
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,
|
|
245
|
-
chart.add_series :data => sheet["
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
#```
|
|
249
|
-
|
|
250
|
-
##Data over time
|
|
251
|
-
|
|
252
|
-
#```ruby
|
|
253
|
-
wb.add_worksheet(:name=>'Charting Dates') do |sheet|
|
|
254
|
-
# cell level style overides when adding cells
|
|
255
|
-
sheet.add_row ['Date', 'Value'], :sz => 16
|
|
256
|
-
sheet.add_row [Time.now - (7*60*60*24), 3]
|
|
257
|
-
sheet.add_row [Time.now - (6*60*60*24), 7]
|
|
258
|
-
sheet.add_row [Time.now - (5*60*60*24), 18]
|
|
259
|
-
sheet.add_row [Time.now - (4*60*60*24), 1]
|
|
260
|
-
sheet.add_chart(Axlsx::Bar3DChart) do |chart|
|
|
261
|
-
chart.start_at "B7"
|
|
262
|
-
chart.end_at "H27"
|
|
263
|
-
chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
|
|
238
|
+
sheet.add_row ["Simple Pie Chart"]
|
|
239
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
|
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"], :colors => ['FF0000', '00FF00', '0000FF']
|
|
264
242
|
end
|
|
265
243
|
end
|
|
266
244
|
#```
|
|
@@ -269,15 +247,18 @@ end
|
|
|
269
247
|
|
|
270
248
|
#```ruby
|
|
271
249
|
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
272
|
-
sheet.add_row ["
|
|
273
|
-
sheet.add_row
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
chart.
|
|
279
|
-
chart.
|
|
280
|
-
chart.
|
|
250
|
+
sheet.add_row ["Simple Line Chart"]
|
|
251
|
+
sheet.add_row %w(first second)
|
|
252
|
+
4.times do
|
|
253
|
+
sheet.add_row [ rand(24)+1, rand(24)+1]
|
|
254
|
+
end
|
|
255
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
|
|
256
|
+
chart.start_at 0, 5
|
|
257
|
+
chart.end_at 10, 20
|
|
258
|
+
chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"]
|
|
259
|
+
chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"]
|
|
260
|
+
chart.catAxis.title = 'X Axis'
|
|
261
|
+
chart.valAxis.title = 'Y Axis'
|
|
281
262
|
end
|
|
282
263
|
end
|
|
283
264
|
#```
|
|
@@ -321,7 +302,7 @@ wb.add_worksheet(:name => "fit to page") do |sheet|
|
|
|
321
302
|
sheet.add_row ['this all goes on one page']
|
|
322
303
|
sheet.fit_to_page = true
|
|
323
304
|
end
|
|
324
|
-
|
|
305
|
+
##```
|
|
325
306
|
|
|
326
307
|
|
|
327
308
|
##Hide Gridlines in worksheet
|
|
@@ -331,7 +312,22 @@ wb.add_worksheet(:name => "No Gridlines") do |sheet|
|
|
|
331
312
|
sheet.add_row ["This", "Sheet", "Hides", "Gridlines"]
|
|
332
313
|
sheet.show_gridlines = false
|
|
333
314
|
end
|
|
334
|
-
|
|
315
|
+
##```
|
|
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
|
|
323
|
+
|
|
324
|
+
# Sheet Protection and excluding cells from locking.
|
|
325
|
+
unlocked = wb.styles.add_style :locked => false
|
|
326
|
+
wb.add_worksheet(:name => 'Sheet Protection') do |sheet|
|
|
327
|
+
sheet.sheet_protection.password = 'fish'
|
|
328
|
+
sheet.add_row [1, 2 ,3] # These cells will be locked
|
|
329
|
+
sheet.add_row [4, 5, 6], :style => unlocked # these cells will not!
|
|
330
|
+
end
|
|
335
331
|
|
|
336
332
|
|
|
337
333
|
##Specify page margins and other options for printing
|
|
@@ -355,7 +351,7 @@ end
|
|
|
355
351
|
## Frozen/Split panes
|
|
356
352
|
## ``` ruby
|
|
357
353
|
wb.add_worksheet(:name => 'fixed headers') do |sheet|
|
|
358
|
-
|
|
354
|
+
sheet.add_row(['', (0..99).map { |i| "column header #{i}" }].flatten )
|
|
359
355
|
100.times.with_index { |index| sheet << ["row header", (0..index).to_a].flatten }
|
|
360
356
|
sheet.sheet_view.pane do |pane|
|
|
361
357
|
pane.top_left_cell = "B2"
|
|
@@ -366,6 +362,70 @@ wb.add_worksheet(:name => 'fixed headers') do |sheet|
|
|
|
366
362
|
end
|
|
367
363
|
end
|
|
368
364
|
|
|
365
|
+
# conditional formatting
|
|
366
|
+
#
|
|
367
|
+
percent = wb.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
|
|
368
|
+
money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
|
|
369
|
+
|
|
370
|
+
# define the style for conditional formatting
|
|
371
|
+
profitable = wb.styles.add_style( :fg_color=>"FF428751",
|
|
372
|
+
:type => :dxf)
|
|
373
|
+
|
|
374
|
+
wb.add_worksheet(:name => "Conditional Cell Is") do |ws|
|
|
375
|
+
|
|
376
|
+
# Generate 20 rows of data
|
|
377
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
|
378
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
|
379
|
+
offset = 3
|
|
380
|
+
rows = 20
|
|
381
|
+
offset.upto(rows + offset) do |i|
|
|
382
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
|
386
|
+
ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
wb.add_worksheet(:name => "Conditional Color Scale") do |ws|
|
|
390
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
|
391
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
|
392
|
+
offset = 3
|
|
393
|
+
rows = 20
|
|
394
|
+
offset.upto(rows + offset) do |i|
|
|
395
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
|
396
|
+
end
|
|
397
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
|
398
|
+
color_scale = Axlsx::ColorScale.new
|
|
399
|
+
ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
wb.add_worksheet(:name => "Conditional Data Bar") do |ws|
|
|
404
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
|
405
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
|
406
|
+
offset = 3
|
|
407
|
+
rows = 20
|
|
408
|
+
offset.upto(rows + offset) do |i|
|
|
409
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
|
410
|
+
end
|
|
411
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
|
412
|
+
data_bar = Axlsx::DataBar.new
|
|
413
|
+
ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
wb.add_worksheet(:name => "Conditional Format Icon Set") do |ws|
|
|
417
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
|
418
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
|
419
|
+
offset = 3
|
|
420
|
+
rows = 20
|
|
421
|
+
offset.upto(rows + offset) do |i|
|
|
422
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
|
423
|
+
end
|
|
424
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
|
425
|
+
icon_set = Axlsx::IconSet.new
|
|
426
|
+
ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
|
|
427
|
+
end
|
|
428
|
+
|
|
369
429
|
##Validate and Serialize
|
|
370
430
|
|
|
371
431
|
#```ruby
|
data/examples/example.xlsx
CHANGED
|
Binary file
|
|
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
|