axlsx 2.0.1 → 2.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/Rakefile +9 -10
- data/examples/IMAGE1UP.JPEG +0 -0
- data/examples/auto_filter.rb +10 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +3 -3
- data/examples/example.rb +72 -4
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/split.rb +16 -0
- data/lib/axlsx.rb +30 -16
- data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +5 -5
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +12 -9
- data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
- data/lib/axlsx/drawing/bar_series.rb +9 -9
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +5 -5
- data/lib/axlsx/drawing/chart.rb +44 -7
- data/lib/axlsx/drawing/drawing.rb +3 -1
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +1 -3
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/line_chart.rb +10 -10
- data/lib/axlsx/drawing/line_series.rb +14 -2
- data/lib/axlsx/drawing/marker.rb +1 -1
- data/lib/axlsx/drawing/num_data.rb +4 -4
- data/lib/axlsx/drawing/num_data_source.rb +6 -6
- data/lib/axlsx/drawing/num_val.rb +1 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +1 -1
- data/lib/axlsx/drawing/pic.rb +2 -3
- data/lib/axlsx/drawing/picture_locking.rb +1 -3
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
- data/lib/axlsx/drawing/pie_series.rb +6 -6
- data/lib/axlsx/drawing/scaling.rb +4 -4
- data/lib/axlsx/drawing/scatter_chart.rb +10 -10
- data/lib/axlsx/drawing/scatter_series.rb +26 -7
- data/lib/axlsx/drawing/ser_axis.rb +2 -2
- data/lib/axlsx/drawing/series.rb +3 -3
- data/lib/axlsx/drawing/series_title.rb +2 -2
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +1 -1
- data/lib/axlsx/drawing/title.rb +3 -3
- data/lib/axlsx/drawing/val_axis.rb +1 -1
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +39 -28
- data/lib/axlsx/rels/relationship.rb +1 -1
- data/lib/axlsx/rels/relationships.rb +2 -2
- data/lib/axlsx/stylesheet/border_pr.rb +2 -2
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
- data/lib/axlsx/stylesheet/cell_style.rb +1 -3
- data/lib/axlsx/stylesheet/color.rb +1 -3
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +1 -3
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +6 -6
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/constants.rb +106 -101
- data/lib/axlsx/util/options_parser.rb +2 -1
- data/lib/axlsx/util/parser.rb +4 -4
- data/lib/axlsx/util/serialized_attributes.rb +16 -6
- data/lib/axlsx/util/simple_typed_list.rb +28 -52
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/string.rb +7 -0
- data/lib/axlsx/util/validators.rb +20 -13
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +11 -12
- data/lib/axlsx/workbook/defined_names.rb +2 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
- data/lib/axlsx/workbook/workbook.rb +19 -12
- data/lib/axlsx/workbook/workbook_view.rb +78 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
- data/lib/axlsx/workbook/worksheet/break.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +128 -73
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +50 -40
- data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +1 -1
- data/lib/axlsx/workbook/worksheet/col.rb +7 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
- data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
- data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
- data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -2
- data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +17 -24
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
- data/lib/axlsx/workbook/worksheet/rich_text.rb +35 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +254 -0
- data/lib/axlsx/workbook/worksheet/row.rb +33 -51
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/table.rb +6 -6
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +59 -30
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
- data/test/drawing/tc_axis.rb +27 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_data_source.rb +6 -0
- data/test/drawing/tc_line_chart.rb +5 -5
- data/test/drawing/tc_line_series.rb +10 -2
- data/test/drawing/tc_pic.rb +4 -0
- data/test/drawing/tc_scatter_series.rb +25 -1
- data/test/tc_helper.rb +1 -1
- data/test/tc_package.rb +7 -1
- data/test/util/tc_simple_typed_list.rb +1 -2
- data/test/workbook/tc_defined_name.rb +12 -4
- data/test/workbook/tc_workbook.rb +16 -2
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
- data/test/workbook/worksheet/tc_break.rb +1 -1
- data/test/workbook/worksheet/tc_cell.rb +30 -4
- data/test/workbook/worksheet/tc_col.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
- data/test/workbook/worksheet/tc_data_bar.rb +1 -1
- data/test/workbook/worksheet/tc_data_validation.rb +11 -11
- data/test/workbook/worksheet/tc_header_footer.rb +2 -2
- data/test/workbook/worksheet/tc_icon_set.rb +1 -1
- data/test/workbook/worksheet/tc_page_setup.rb +3 -3
- data/test/workbook/worksheet/tc_print_options.rb +1 -1
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +2 -2
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
- data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
- data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
- data/test/workbook/worksheet/tc_worksheet.rb +49 -10
- metadata +81 -55
- data/test/axlsx.qcachegrind +0 -2226
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbd74d60d15e7375b31b29eb04943c5014519d0a
|
4
|
+
data.tar.gz: 13a7cdaf65bd1da6d7b780b9c8217cf544141679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92fdb46000096174c14f32b6783e8758b39535ceb2bc193cfb0f45723c98babe7abfdab3e1ae2af76c999f414e67bf47afe93e46827571db5aa0b3bb97f79492
|
7
|
+
data.tar.gz: 2b7e3f18fa42835e8ca6e48a40b8641cb0d799f898124e827c7993adb097216df788bef033dde4d1a5525338d4d24a28112092f42ce9684f61ad74daf2b09df1
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ appreciation for the gem, please don't hesitate to make a donation.
|
|
11
11
|
|
12
12
|
**Git**:[http://github.com/randym/axlsx](http://github.com/randym/axlsx)
|
13
13
|
|
14
|
-
**Twitter**: [https://twitter.com
|
14
|
+
**Twitter**: [https://twitter.com/morgan_randy](https://twitter.com/morgan_randy)
|
15
15
|
|
16
16
|
**Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx)
|
17
17
|
|
@@ -50,7 +50,7 @@ There are guides for using axlsx and acts_as_xlsx here:
|
|
50
50
|
|
51
51
|
If you are working with ActiveAdmin see:
|
52
52
|
|
53
|
-
[
|
53
|
+
[activeadmin-axlsx](http://github.com/randym/activeadmin-axlsx)
|
54
54
|
|
55
55
|
It provies a plugin and dsl for generating downloadable reports.
|
56
56
|
|
@@ -164,7 +164,10 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
164
164
|
|
165
165
|
#Change log
|
166
166
|
---------
|
167
|
-
|
167
|
+
- **
|
168
|
+
- Added Cell#name so you you can quickly create a defined name for a single cell in your workbook.
|
169
|
+
- Added full book view and sheet state management. This means you can specify how the workbook renders as well as manage sheet visibility.
|
170
|
+
- Added smoothing management for line charts series
|
168
171
|
- **September.12.13**:2.0.1
|
169
172
|
- Unpinned rubyzip version
|
170
173
|
- **September.12.13**:2.0.0
|
data/Rakefile
CHANGED
@@ -10,18 +10,17 @@ end
|
|
10
10
|
|
11
11
|
task :gendoc do
|
12
12
|
#puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
13
|
-
|
14
|
-
|
13
|
+
system "yardoc"
|
14
|
+
system "yard stats --list-undoc"
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
|
18
|
+
require 'rake/testtask'
|
19
|
+
Rake::TestTask.new do |t|
|
20
|
+
t.libs << 'test'
|
21
|
+
t.test_files = FileList['test/**/tc_*.rb']
|
22
|
+
t.verbose = false
|
23
|
+
t.warning = true
|
25
24
|
end
|
26
25
|
|
27
26
|
task :release => :build do
|
Binary file
|
data/examples/auto_filter.rb
CHANGED
@@ -10,7 +10,16 @@ Axlsx::Package.new do |p|
|
|
10
10
|
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
11
11
|
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
12
12
|
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
13
|
-
sheet.auto_filter = 'A2:D5'
|
13
|
+
sheet.auto_filter = 'A2:D5'
|
14
|
+
sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2']
|
15
|
+
end
|
16
|
+
p.workbook.add_worksheet(:name => "Table 2") do |sheet|
|
17
|
+
sheet.add_row ["Build Matrix"]
|
18
|
+
sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
|
19
|
+
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
20
|
+
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
21
|
+
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
22
|
+
sheet.auto_filter = 'A2:D5'
|
14
23
|
sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2']
|
15
24
|
end
|
16
25
|
end.serialize('auto_filter.xlsx')
|
@@ -11,8 +11,8 @@ percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE
|
|
11
11
|
money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
|
12
12
|
|
13
13
|
# define the style for conditional formatting
|
14
|
-
profitable = book.styles.add_style( :fg_color => "
|
15
|
-
unprofitable =
|
14
|
+
profitable = book.styles.add_style( :fg_color => "428751", :type => :dxf )
|
15
|
+
unprofitable = book.styles.add_style( :fg_color => "FF0000", :type => :dxf )
|
16
16
|
|
17
17
|
book.add_worksheet(:name => "Cell Is") do |ws|
|
18
18
|
|
@@ -28,7 +28,7 @@ book.add_worksheet(:name => "Cell Is") do |ws|
|
|
28
28
|
# Apply conditional formatting to range B3:B100 in the worksheet
|
29
29
|
ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
|
30
30
|
# Apply conditional using the between operator; NOTE: supply an array to :formula for between/notBetween
|
31
|
-
|
31
|
+
ws.add_conditional_formatting("C3:C100", { :type => :cellIs, :operator => :between, :formula => ["0.00%","100.00%"], :dxfId => unprofitable, :priority => 1 })
|
32
32
|
end
|
33
33
|
|
34
34
|
book.add_worksheet(:name => "Color Scale") do |ws|
|
data/examples/example.rb
CHANGED
@@ -14,6 +14,7 @@ examples << :surrounding_border
|
|
14
14
|
examples << :deep_custom_borders
|
15
15
|
examples << :row_column_style
|
16
16
|
examples << :fixed_column_width
|
17
|
+
examples << :height
|
17
18
|
examples << :outline_level
|
18
19
|
examples << :merge_cells
|
19
20
|
examples << :images
|
@@ -40,13 +41,16 @@ examples << :printing
|
|
40
41
|
examples << :header_footer
|
41
42
|
examples << :comments
|
42
43
|
examples << :panes
|
44
|
+
examples << :book_view
|
43
45
|
examples << :sheet_view
|
46
|
+
examples << :hiding_sheets
|
44
47
|
examples << :conditional_formatting
|
45
48
|
examples << :streaming
|
46
49
|
examples << :shared_strings
|
47
50
|
examples << :no_autowidth
|
48
51
|
examples << :cached_formula
|
49
52
|
examples << :page_breaks
|
53
|
+
examples << :rich_text
|
50
54
|
|
51
55
|
p = Axlsx::Package.new
|
52
56
|
wb = p.workbook
|
@@ -207,6 +211,7 @@ if examples.include? :row_column_style
|
|
207
211
|
head = s.add_style :bg_color => "00", :fg_color => "FF"
|
208
212
|
percent = s.add_style :num_fmt => 9
|
209
213
|
wb.add_worksheet(:name => "Columns and Rows") do |sheet|
|
214
|
+
# Note: you must add rows to the document *BEFORE* applying column styles to them
|
210
215
|
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4', 'col5']
|
211
216
|
sheet.add_row [1, 2, 0.3, 4, 5.0]
|
212
217
|
sheet.add_row [1, 2, 0.2, 4, 5.0]
|
@@ -243,6 +248,21 @@ if examples.include? :fixed_column_width
|
|
243
248
|
end
|
244
249
|
end
|
245
250
|
|
251
|
+
|
252
|
+
##Specifying Row height
|
253
|
+
|
254
|
+
#```ruby
|
255
|
+
if examples.include? :height
|
256
|
+
wb.styles do |s|
|
257
|
+
head = s.add_style :bg_color => "00", :fg_color => "FF"
|
258
|
+
wb.add_worksheet(:name => "fixed row height") do |sheet|
|
259
|
+
sheet.add_row ["This row will have a fixed height", "It will overwite the default row height"], :height => 30
|
260
|
+
sheet.add_row ["This row can have a different height too"], :height => 10, :style => head
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
|
246
266
|
#```ruby
|
247
267
|
if examples.include? :outline_level
|
248
268
|
wb.add_worksheet(name: 'outline_level') do |sheet|
|
@@ -279,13 +299,23 @@ if examples.include? :images
|
|
279
299
|
wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
|
280
300
|
img = File.expand_path('../image1.jpeg', __FILE__)
|
281
301
|
# specifying the :hyperlink option will add a hyper link to your image.
|
302
|
+
#
|
282
303
|
# @note - Numbers does not support this part of the specification.
|
304
|
+
|
283
305
|
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
284
306
|
image.width=720
|
285
307
|
image.height=666
|
286
308
|
image.hyperlink.tooltip = "Labeled Link"
|
287
|
-
image.start_at
|
309
|
+
image.start_at 0, 0
|
288
310
|
end
|
311
|
+
|
312
|
+
# position in block
|
313
|
+
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
314
|
+
image.start_at 22, 14
|
315
|
+
image.end_at 23, 17
|
316
|
+
end
|
317
|
+
# all in one go
|
318
|
+
sheet.add_image(:image_src => img, :start_at => [15, 33], :end_at => [20, 37], :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com")
|
289
319
|
end
|
290
320
|
end
|
291
321
|
#```
|
@@ -470,7 +500,7 @@ if examples.include? :line_chart
|
|
470
500
|
sheet.add_chart(Axlsx::LineChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
|
471
501
|
chart.start_at 0, 21
|
472
502
|
chart.end_at 10, 41
|
473
|
-
chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "FF0000"
|
503
|
+
chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "FF0000", :show_marker => true, :smooth => true
|
474
504
|
chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "00FF00"
|
475
505
|
chart.catAxis.title = 'X Axis'
|
476
506
|
chart.valAxis.title = 'Y Axis'
|
@@ -644,7 +674,27 @@ if examples.include? :sheet_view
|
|
644
674
|
end
|
645
675
|
end
|
646
676
|
|
677
|
+
## Book Views
|
678
|
+
#
|
679
|
+
## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
|
680
|
+
## tuning values for the UI @see Axlsx::WorkbookView
|
681
|
+
## ```ruby
|
682
|
+
if examples.include? :book_view
|
683
|
+
# when you open example.xml the second sheet is selected, and the horizontal scroll bar is much smaller showing more sheets
|
684
|
+
wb.add_view tab_ratio: 800, active_tab: 1
|
685
|
+
end
|
647
686
|
|
687
|
+
## Hiding Sheets
|
688
|
+
##
|
689
|
+
## Sheets can be hidden with the state attribute
|
690
|
+
if examples.include? :hiding_sheets
|
691
|
+
wb.add_worksheet name: 'hidden', state: :hidden do |sheet|
|
692
|
+
sheet.add_row ['you cant see me!']
|
693
|
+
end
|
694
|
+
wb.add_worksheet name: 'very hidden', state: :very_hidden do |sheet|
|
695
|
+
sheet.add_row ['you really cant see me!']
|
696
|
+
end
|
697
|
+
end
|
648
698
|
# conditional formatting
|
649
699
|
#
|
650
700
|
if examples.include? :conditional_formatting
|
@@ -763,8 +813,7 @@ if examples.include? :no_autowidth
|
|
763
813
|
end
|
764
814
|
#```
|
765
815
|
|
766
|
-
|
767
|
-
|
816
|
+
#```ruby
|
768
817
|
if examples.include? :cached_formula
|
769
818
|
p = Axlsx::Package.new
|
770
819
|
p.use_shared_strings = true
|
@@ -774,4 +823,23 @@ if examples.include? :cached_formula
|
|
774
823
|
end
|
775
824
|
p.serialize 'cached_formula.xlsx'
|
776
825
|
end
|
826
|
+
#```
|
777
827
|
|
828
|
+
#```ruby
|
829
|
+
if examples.include? :rich_text
|
830
|
+
p = Axlsx::Package.new
|
831
|
+
p.use_shared_strings = true
|
832
|
+
wb = p.workbook
|
833
|
+
wrap_text = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
|
834
|
+
rt = Axlsx::RichText.new
|
835
|
+
rt.add_run('I\'m bold, ', :b => true)
|
836
|
+
rt.add_run('I\'m italic, ', :i => true)
|
837
|
+
rt.add_run('I\'m strike' + "\n", :strike => true)
|
838
|
+
rt.add_run('I\'m bold, italic and strike' + "\n", :b => true, :i => true, :strike => true)
|
839
|
+
rt.add_run('I\'m style-less :D')
|
840
|
+
wb.add_worksheet(:name => "RichText") do | sheet |
|
841
|
+
sheet.add_row [rt], :style => wrap_text
|
842
|
+
end
|
843
|
+
p.serialize 'rich_text.xlsx'
|
844
|
+
end
|
845
|
+
#```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
|
5
|
+
#```ruby
|
6
|
+
require 'axlsx'
|
7
|
+
package = Axlsx::Package.new
|
8
|
+
package.workbook do |workbook|
|
9
|
+
workbook.add_worksheet name: 'merged_cells' do |sheet|
|
10
|
+
4.times do
|
11
|
+
sheet.add_row %w(a b c d e f g)
|
12
|
+
end
|
13
|
+
sheet.merge_cells "A1:A2"
|
14
|
+
sheet.merge_cells "B1:B2"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
package.serialize 'merged_cells.xlsx'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
|
5
|
+
#```ruby
|
6
|
+
require 'axlsx'
|
7
|
+
package = Axlsx::Package.new
|
8
|
+
package.workbook do |workbook|
|
9
|
+
workbook.styles do |s|
|
10
|
+
gridstyle_border = s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" }
|
11
|
+
workbook.add_worksheet :name => "Custom Borders" do |sheet|
|
12
|
+
sheet.sheet_view.show_grid_lines = false
|
13
|
+
sheet.add_row ["with", "grid", "style"], :style => gridstyle_border
|
14
|
+
sheet.add_row ["no", "border"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
package.serialize 'no_grid_with_borders.xlsx'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class RandomReportGenerator
|
2
|
+
def date
|
3
|
+
Date.today.strftime("%m/%d/%Y")
|
4
|
+
end
|
5
|
+
def member_id
|
6
|
+
@i ||= 0
|
7
|
+
@i += 1
|
8
|
+
end
|
9
|
+
def name
|
10
|
+
"John S."
|
11
|
+
end
|
12
|
+
def gender
|
13
|
+
["Male", "Female"].sample
|
14
|
+
end
|
15
|
+
def age
|
16
|
+
rand(100)
|
17
|
+
end
|
18
|
+
def city
|
19
|
+
["New York", "Mountain View", "Newark", "Phoenix"].sample
|
20
|
+
end
|
21
|
+
def state
|
22
|
+
["NY", "CA", "NJ", "AZ"].sample
|
23
|
+
end
|
24
|
+
def parenting
|
25
|
+
"Foo"
|
26
|
+
end
|
27
|
+
def student
|
28
|
+
"Bar"
|
29
|
+
end
|
30
|
+
def income
|
31
|
+
"Bar"
|
32
|
+
end
|
33
|
+
def education
|
34
|
+
"Bar"
|
35
|
+
end
|
36
|
+
def answer
|
37
|
+
["Yes", "No", "Maybe", "I dont know"].sample
|
38
|
+
end
|
39
|
+
def run
|
40
|
+
package = Axlsx::Package.new
|
41
|
+
workbook = package.workbook
|
42
|
+
|
43
|
+
workbook.add_worksheet(:name => "Data Sheet") do |sheet|
|
44
|
+
sheet.add_row [
|
45
|
+
"Date", "Member ID", "Name", "Gender", "Age", "City", "State",
|
46
|
+
"Parenting Status", "Student Status", "Income", "Education", "Answer"
|
47
|
+
]
|
48
|
+
30.times do
|
49
|
+
sheet.add_row [date, member_id, name, gender, age, city, state,
|
50
|
+
parenting, student, income, education, answer]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
workbook.add_worksheet(:name => "Summary") do |sheet|
|
55
|
+
pivot_table = Axlsx::PivotTable.new 'A1:B15', "A1:L31", workbook.worksheets[0]
|
56
|
+
pivot_table.rows = ['Answer']
|
57
|
+
pivot_table.data = [{:ref => "Member ID", :subtotal => "count"}]
|
58
|
+
sheet.pivot_tables << pivot_table
|
59
|
+
end
|
60
|
+
|
61
|
+
package.serialize("pivot_table.xlsx")
|
62
|
+
end
|
63
|
+
end
|
data/examples/split.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
require 'axlsx'
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
wb = p.workbook
|
7
|
+
wb.add_worksheet name: 'pane' do |sheet|
|
8
|
+
sheet.sheet_view.pane do |pane|
|
9
|
+
pane.top_left_cell = "B2"
|
10
|
+
pane.state = :frozen_split
|
11
|
+
pane.y_split = 2
|
12
|
+
pane.x_split = 1
|
13
|
+
pane.active_pane = :bottom_right
|
14
|
+
end
|
15
|
+
end
|
16
|
+
p.serialize 'pane.xlsx'
|
data/lib/axlsx.rb
CHANGED
@@ -10,6 +10,7 @@ require 'axlsx/util/serialized_attributes'
|
|
10
10
|
require 'axlsx/util/options_parser'
|
11
11
|
# to be included with parsable intitites.
|
12
12
|
#require 'axlsx/util/parser.rb'
|
13
|
+
require 'axlsx/util/string'
|
13
14
|
|
14
15
|
require 'axlsx/stylesheet/styles.rb'
|
15
16
|
|
@@ -53,7 +54,7 @@ module Axlsx
|
|
53
54
|
cells = sort_cells(cells)
|
54
55
|
reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
|
55
56
|
if absolute
|
56
|
-
escaped_name = cells.first.row.worksheet.name.gsub
|
57
|
+
escaped_name = cells.first.row.worksheet.name.gsub ''', "''"
|
57
58
|
"'#{escaped_name}'!#{reference}"
|
58
59
|
else
|
59
60
|
reference
|
@@ -65,7 +66,7 @@ module Axlsx
|
|
65
66
|
# @param [Array] cells
|
66
67
|
# @return [Array]
|
67
68
|
def self.sort_cells(cells)
|
68
|
-
cells.sort { |x, y| [x.index, x.row.
|
69
|
+
cells.sort { |x, y| [x.index, x.row.row_index] <=> [y.index, y.row.row_index] }
|
69
70
|
end
|
70
71
|
|
71
72
|
#global reference html entity encoding
|
@@ -88,20 +89,21 @@ module Axlsx
|
|
88
89
|
# @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
|
89
90
|
# @return [String]
|
90
91
|
def self.col_ref(index)
|
91
|
-
chars =
|
92
|
+
chars = ''
|
92
93
|
while index >= 26 do
|
93
|
-
|
94
|
-
|
94
|
+
index, char = index.divmod(26)
|
95
|
+
chars.prepend((char + 65).chr)
|
96
|
+
index -= 1
|
95
97
|
end
|
96
|
-
chars
|
97
|
-
chars
|
98
|
+
chars.prepend((index + 65).chr)
|
99
|
+
chars
|
98
100
|
end
|
99
101
|
|
100
102
|
# @return [String] The alpha(column)numeric(row) reference for this sell.
|
101
103
|
# @example Relative Cell Reference
|
102
104
|
# ws.rows.first.cells.first.r #=> "A1"
|
103
105
|
def self.cell_r(c_index, r_index)
|
104
|
-
|
106
|
+
col_ref(c_index) << (r_index+1).to_s
|
105
107
|
end
|
106
108
|
|
107
109
|
# Creates an array of individual cell references based on an excel reference range.
|
@@ -113,7 +115,7 @@ module Axlsx
|
|
113
115
|
end_col, end_row = name_to_indices($2)
|
114
116
|
(start_row..end_row).to_a.map do |row_num|
|
115
117
|
(start_col..end_col).to_a.map do |col_num|
|
116
|
-
|
118
|
+
cell_r(col_num, row_num)
|
117
119
|
end
|
118
120
|
end
|
119
121
|
end
|
@@ -127,14 +129,26 @@ module Axlsx
|
|
127
129
|
s.gsub(/_(.)/){ $1.upcase }
|
128
130
|
end
|
129
131
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
132
|
+
# returns the provided string with all invalid control charaters
|
133
|
+
# removed.
|
134
|
+
# @param [String] str The string to process
|
135
|
+
# @return [String]
|
136
|
+
def self.sanitize(str)
|
137
|
+
str.delete!(CONTROL_CHARS)
|
138
|
+
str
|
139
|
+
end
|
140
|
+
|
141
|
+
# If value is boolean return 1 or 0
|
142
|
+
# else return the value
|
143
|
+
# @param [Object] value The value to process
|
144
|
+
# @return [Object]
|
145
|
+
def self.booleanize(value)
|
146
|
+
if value == true || value == false
|
147
|
+
value ? 1 : 0
|
148
|
+
else
|
149
|
+
value
|
136
150
|
end
|
137
|
-
|
151
|
+
end
|
138
152
|
|
139
153
|
# Instructs the serializer to not try to escape cell value input.
|
140
154
|
# This will give you a huge speed bonus, but if you content has <, > or other xml character data
|