axlsx 1.2.0 → 2.0.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.
- checksums.yaml +7 -0
- data/.yardopts +3 -2
- data/.yardopts_guide +19 -0
- data/CHANGELOG.md +64 -1
- data/README.md +105 -87
- data/Rakefile +0 -5
- data/examples/2010_comments.rb +17 -0
- data/examples/anchor_swapping.rb +28 -0
- data/examples/auto_filter.rb +16 -0
- data/examples/basic_charts.rb +4 -0
- data/examples/colored_links.rb +59 -0
- data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
- data/examples/example.rb +569 -258
- data/examples/ios_preview.rb +14 -0
- data/examples/page_setup.rb +11 -0
- data/examples/pivot_table.rb +39 -0
- data/examples/skydrive/real_example.rb +8 -8
- data/examples/styles.rb +66 -0
- data/examples/underline.rb +13 -0
- data/examples/wrap_text.rb +21 -0
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/content_type/default.rb +6 -37
- data/lib/axlsx/content_type/override.rb +6 -38
- data/lib/axlsx/doc_props/app.rb +10 -7
- data/lib/axlsx/doc_props/core.rb +6 -1
- data/lib/axlsx/drawing/axes.rb +61 -0
- data/lib/axlsx/drawing/axis.rb +20 -17
- data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
- data/lib/axlsx/drawing/cat_axis.rb +2 -10
- data/lib/axlsx/drawing/chart.rb +33 -6
- data/lib/axlsx/drawing/d_lbls.rb +21 -31
- data/lib/axlsx/drawing/drawing.rb +11 -17
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +42 -36
- data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
- data/lib/axlsx/drawing/line_chart.rb +99 -0
- data/lib/axlsx/drawing/line_series.rb +20 -2
- data/lib/axlsx/drawing/marker.rb +38 -18
- data/lib/axlsx/drawing/num_data.rb +6 -6
- data/lib/axlsx/drawing/num_data_source.rb +17 -16
- data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
- data/lib/axlsx/drawing/pic.rb +43 -45
- data/lib/axlsx/drawing/picture_locking.rb +12 -44
- data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
- data/lib/axlsx/drawing/scaling.rb +13 -13
- data/lib/axlsx/drawing/scatter_chart.rb +32 -21
- data/lib/axlsx/drawing/ser_axis.rb +15 -16
- data/lib/axlsx/drawing/series.rb +3 -6
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +7 -8
- data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
- data/lib/axlsx/drawing/val_axis.rb +14 -13
- data/lib/axlsx/drawing/view_3D.rb +52 -38
- data/lib/axlsx/drawing/vml_shape.rb +20 -79
- data/lib/axlsx/package.rb +58 -28
- data/lib/axlsx/rels/relationship.rb +75 -9
- data/lib/axlsx/rels/relationships.rb +8 -1
- data/lib/axlsx/stylesheet/border.rb +29 -20
- data/lib/axlsx/stylesheet/border_pr.rb +5 -4
- data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
- data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
- data/lib/axlsx/stylesheet/cell_style.rb +19 -14
- data/lib/axlsx/stylesheet/color.rb +20 -17
- data/lib/axlsx/stylesheet/dxf.rb +4 -4
- data/lib/axlsx/stylesheet/font.rb +22 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
- data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
- data/lib/axlsx/stylesheet/styles.rb +37 -22
- data/lib/axlsx/stylesheet/table_style.rb +17 -16
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
- data/lib/axlsx/stylesheet/table_styles.rb +14 -11
- data/lib/axlsx/stylesheet/xf.rb +28 -26
- data/lib/axlsx/util/accessors.rb +64 -0
- data/lib/axlsx/util/constants.rb +127 -6
- data/lib/axlsx/util/options_parser.rb +15 -0
- data/lib/axlsx/util/serialized_attributes.rb +79 -0
- data/lib/axlsx/util/simple_typed_list.rb +50 -15
- data/lib/axlsx/util/validators.rb +51 -16
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/defined_name.rb +14 -59
- data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
- data/lib/axlsx/workbook/workbook.rb +85 -6
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
- data/lib/axlsx/workbook/worksheet/break.rb +37 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
- data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
- data/lib/axlsx/workbook/worksheet/col.rb +43 -29
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
- data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
- data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
- data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
- data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
- data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
- data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
- data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
- data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
- data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +59 -83
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
- data/lib/axlsx/workbook/worksheet/table.rb +25 -19
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/axlsx.rb +55 -5
- data/lib/schema/sml.xsd +4 -0
- data/test/axlsx.qcachegrind +2226 -0
- data/test/benchmark.rb +2 -3
- data/test/content_type/tc_default.rb +0 -11
- data/test/content_type/tc_override.rb +0 -13
- data/test/doc_props/tc_core.rb +7 -0
- data/test/drawing/tc_axes.rb +8 -0
- data/test/drawing/tc_axis.rb +15 -17
- data/test/drawing/tc_bar_3D_chart.rb +6 -0
- data/test/drawing/tc_cat_axis.rb +9 -9
- data/test/drawing/tc_chart.rb +20 -0
- data/test/drawing/tc_d_lbls.rb +14 -4
- data/test/drawing/tc_drawing.rb +0 -5
- data/test/drawing/tc_graphic_frame.rb +5 -3
- data/test/drawing/tc_hyperlink.rb +0 -4
- data/test/drawing/tc_line_chart.rb +39 -0
- data/test/drawing/tc_line_series.rb +8 -2
- data/test/drawing/tc_pic.rb +14 -3
- data/test/drawing/tc_ser_axis.rb +13 -12
- data/test/drawing/tc_two_cell_anchor.rb +3 -3
- data/test/drawing/tc_val_axis.rb +6 -6
- data/test/drawing/tc_vml_shape.rb +9 -3
- data/test/profile.rb +11 -21
- data/test/rels/tc_relationship.rb +32 -9
- data/test/rels/tc_relationships.rb +12 -1
- data/test/stylesheet/tc_color.rb +6 -0
- data/test/stylesheet/tc_styles.rb +15 -2
- data/test/tc_axlsx.rb +35 -2
- data/test/tc_helper.rb +7 -1
- data/test/tc_package.rb +44 -5
- data/test/util/tc_serialized_attributes.rb +19 -0
- data/test/util/tc_validators.rb +26 -1
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_shared_strings_table.rb +6 -0
- data/test/workbook/tc_workbook.rb +38 -1
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
- data/test/workbook/worksheet/tc_break.rb +49 -0
- data/test/workbook/worksheet/tc_cell.rb +40 -6
- data/test/workbook/worksheet/tc_col.rb +11 -1
- data/test/workbook/worksheet/tc_color_scale.rb +31 -2
- data/test/workbook/worksheet/tc_comment.rb +21 -6
- data/test/workbook/worksheet/tc_comments.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
- data/test/workbook/worksheet/tc_data_bar.rb +7 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
- data/test/workbook/worksheet/tc_header_footer.rb +151 -0
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_page_setup.rb +6 -1
- data/test/workbook/worksheet/tc_pane.rb +5 -45
- data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
- data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
- data/test/workbook/worksheet/tc_row.rb +4 -4
- data/test/workbook/worksheet/tc_selection.rb +9 -48
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
- data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +131 -16
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
- metadata +97 -64
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.pdf +0 -0
- data/examples/image1.gif +0 -0
- data/examples/image1.jpg +0 -0
- data/examples/image1.png +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/sample.png +0 -0
- data/examples/scraping_html.rb +0 -91
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/sheet_view.rb +0 -34
- data/examples/two_cell_anchor_image.rb +0 -11
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
|
|
8
|
+
p = Axlsx::Package.new
|
|
9
|
+
p.use_shared_strings = true
|
|
10
|
+
s = p.workbook.add_worksheet(:name => "Formula test")
|
|
11
|
+
s.add_row [1, 2, 3]
|
|
12
|
+
s.add_row %w(a b c)
|
|
13
|
+
s.add_row ["=SUM(A1:C1)"], :formula_values => [6]
|
|
14
|
+
p.serialize "ios_preview.xlsx"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
xls = Axlsx::Package.new
|
|
4
|
+
wb = xls.workbook
|
|
5
|
+
wb.add_worksheet do |ws|
|
|
6
|
+
# Excel does not currently follow the specification and will ignore paper_width and paper_height so if you need
|
|
7
|
+
# to for a paper size, be sure to set :paper_size
|
|
8
|
+
ws.page_setup.set :paper_width => "210mm", :paper_size => 10, :paper_height => "297mm", :orientation => :landscape
|
|
9
|
+
ws.add_row %w(AXLSX is cool)
|
|
10
|
+
end
|
|
11
|
+
xls.serialize "page_setup.xlsx"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
5
|
+
require 'axlsx'
|
|
6
|
+
|
|
7
|
+
p = Axlsx::Package.new
|
|
8
|
+
wb = p.workbook
|
|
9
|
+
|
|
10
|
+
# Create some data in a sheet
|
|
11
|
+
def month
|
|
12
|
+
%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec).sample
|
|
13
|
+
end
|
|
14
|
+
def year
|
|
15
|
+
%w(2010 2011 2012).sample
|
|
16
|
+
end
|
|
17
|
+
def type
|
|
18
|
+
%w(Meat Dairy Beverages Produce).sample
|
|
19
|
+
end
|
|
20
|
+
def sales
|
|
21
|
+
rand(5000)
|
|
22
|
+
end
|
|
23
|
+
def region
|
|
24
|
+
%w(East West North South).sample
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
wb.add_worksheet(:name => "Data Sheet") do |sheet|
|
|
28
|
+
sheet.add_row ['Month', 'Year', 'Type', 'Sales', 'Region']
|
|
29
|
+
30.times { sheet.add_row [month, year, type, sales, region] }
|
|
30
|
+
sheet.add_pivot_table 'G4:L17', "A1:E31" do |pivot_table|
|
|
31
|
+
pivot_table.rows = ['Month', 'Year']
|
|
32
|
+
pivot_table.columns = ['Type']
|
|
33
|
+
pivot_table.data = ['Sales']
|
|
34
|
+
pivot_table.pages = ['Region']
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Write the excel file
|
|
39
|
+
p.serialize("pivot_table.xlsx")
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
2
2
|
|
|
3
3
|
require 'axlsx'
|
|
4
4
|
|
|
5
5
|
Axlsx::Package.new do |p|
|
|
6
6
|
p.workbook do |wb|
|
|
7
7
|
styles = wb.styles
|
|
8
|
-
header
|
|
8
|
+
header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
|
|
9
9
|
tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center }
|
|
10
10
|
ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1}
|
|
11
|
-
col_header
|
|
12
|
-
label
|
|
13
|
-
money
|
|
14
|
-
t_label
|
|
15
|
-
t_money
|
|
11
|
+
col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center }
|
|
12
|
+
label = styles.add_style :alignment => { :indent => 1 }
|
|
13
|
+
money = styles.add_style :num_fmt => 5
|
|
14
|
+
t_label = styles.add_style :b => true, :bg_color => "FFDFDEDF"
|
|
15
|
+
t_money = styles.add_style :b => true, :num_fmt => 5, :bg_color => "FFDFDEDF"
|
|
16
16
|
|
|
17
17
|
wb.add_worksheet do |sheet|
|
|
18
18
|
sheet.add_row
|
|
@@ -54,7 +54,7 @@ Axlsx::Package.new do |p|
|
|
|
54
54
|
chart.start_at 7, 16
|
|
55
55
|
chart.end_at 12, 31
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
%w(B4:C4 E4:F4 B11:C11 E11:F11 B2:F2).each { |range| sheet.merge_cells(range) }
|
|
58
58
|
sheet.column_widths 2, nil, nil, 2, nil, nil, 2
|
|
59
59
|
end
|
|
60
60
|
end
|
data/examples/styles.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
require 'date'
|
|
4
|
+
|
|
5
|
+
p = Axlsx::Package.new
|
|
6
|
+
wb = p.workbook
|
|
7
|
+
wb.styles do |style|
|
|
8
|
+
|
|
9
|
+
# Date/Time Styles
|
|
10
|
+
#
|
|
11
|
+
# The most important thing to remember about OOXML styles is that they are
|
|
12
|
+
# exclusive. This means that each style must define all the components it
|
|
13
|
+
# requires to render the cell the way you want. A good example of this is
|
|
14
|
+
# changing the font size for a date. You cannot specify just the font size,
|
|
15
|
+
# you must also specify the number format or format code so that renders
|
|
16
|
+
# know how to display the serialized date float value
|
|
17
|
+
#
|
|
18
|
+
# The parts that make up a custom styles are:
|
|
19
|
+
#
|
|
20
|
+
# fonts(Font), fills(Fill), borders(Border) and number formats(NumFmt).
|
|
21
|
+
# Getting to know those classes will help you make the most out of custom
|
|
22
|
+
# styling. However axlsx certainly does not expect you to create all those
|
|
23
|
+
# objects manually.
|
|
24
|
+
#
|
|
25
|
+
# workbook.styles.add_style provides a helper method 'add_style' for defining
|
|
26
|
+
# styles in one go. The docs for that method are definitely worth a read.
|
|
27
|
+
# @see Style#add_style
|
|
28
|
+
|
|
29
|
+
# When no style is applied to a cell, axlsx will automatically apply date/time
|
|
30
|
+
# formatting to Date and Time objects for you. However, if you are defining
|
|
31
|
+
# custom styles, you define all aspects of the style you want to apply.
|
|
32
|
+
#
|
|
33
|
+
# An aside on styling and auto-width. Auto-width calculations do not
|
|
34
|
+
# currently take into account any style or formatting you have applied to the
|
|
35
|
+
# data in your cells as it would require the creation of a rendering engine,
|
|
36
|
+
# and frankly kill performance. If you are doing a lot of custom formatting,
|
|
37
|
+
# you are going to be better served by specifying fixed column widths.
|
|
38
|
+
#
|
|
39
|
+
# Let's look at an example:
|
|
40
|
+
#
|
|
41
|
+
# A style that only applies a font size
|
|
42
|
+
large_font = wb.styles.add_style :sz => 20
|
|
43
|
+
|
|
44
|
+
# A style that applies both a font size and a predefined number format.
|
|
45
|
+
# @see NumFmt
|
|
46
|
+
predefined_format = wb.styles.add_style :sz => 20, :num_fmt => 14
|
|
47
|
+
|
|
48
|
+
# A style that a applies a font size and a custom formatting code
|
|
49
|
+
custom_format = wb.styles.add_style :sz => 20, :format_code => 'yyyy-mm-dd'
|
|
50
|
+
|
|
51
|
+
# A style that overrides top and left border style
|
|
52
|
+
override_border = wb.styles.add_style :border => { :style => :thin, :color =>"FAAC58", :edges => [:right, :top, :left] }, :border_top => { :style => :thick, :color => "01DF74" }, :border_left => { :color => "0101DF" }
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
wb.add_worksheet do |sheet|
|
|
56
|
+
|
|
57
|
+
# We then apply those styles positionally
|
|
58
|
+
sheet.add_row [123, "123", Time.now], style: [nil, large_font, predefined_format]
|
|
59
|
+
sheet.add_row [123, "123", Date.new(2012, 9, 14)], style: [large_font, nil, custom_format]
|
|
60
|
+
sheet.add_row [123, "123", Date.new(2000, 9, 12)] # This uses the axlsx default format_code (14)
|
|
61
|
+
sheet.add_row [123, "123", Time.now], style: [large_font, override_border, predefined_format]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
p.serialize 'styles.xlsx'
|
|
66
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
p = Axlsx::Package.new
|
|
4
|
+
p.workbook do |wb|
|
|
5
|
+
wb.styles do |s|
|
|
6
|
+
no_underline = s.add_style :sz => 10, :b => true, :u => false, :alignment => { :horizontal=> :right }
|
|
7
|
+
wb.add_worksheet(:name => 'wunderlinen') do |sheet|
|
|
8
|
+
sheet.add_row %w{a b c really?}, :style => no_underline
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
p.serialize 'no_underline.xlsx'
|
|
13
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
p = Axlsx::Package.new
|
|
4
|
+
p.workbook do |wb|
|
|
5
|
+
wb.styles do |s|
|
|
6
|
+
wrap_text = s.add_style :fg_color=> "FFFFFF",
|
|
7
|
+
:b => true,
|
|
8
|
+
:bg_color => "004586",
|
|
9
|
+
:sz => 12,
|
|
10
|
+
:border => { :style => :thin, :color => "00" },
|
|
11
|
+
:alignment => { :horizontal => :center,
|
|
12
|
+
:vertical => :center ,
|
|
13
|
+
:wrap_text => true}
|
|
14
|
+
wb.add_worksheet(:name => 'wrap text') do |sheet|
|
|
15
|
+
sheet.add_row ['Torp, White and Cronin'], :style => wrap_text
|
|
16
|
+
# Forcing the column to be a bit narrow so we can see if the text wrap.
|
|
17
|
+
sheet.column_info.first.width = 5
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
p.serialize 'wrap_text.xlsx'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
|
|
3
|
+
# This class extracts the common parts from Default and Override
|
|
4
|
+
class AbstractContentType
|
|
5
|
+
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
|
|
8
|
+
# Initializes an abstract content type
|
|
9
|
+
# @see Default, Override
|
|
10
|
+
def initialize(options={})
|
|
11
|
+
parse_options options
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# The type of content.
|
|
15
|
+
# @return [String]
|
|
16
|
+
attr_reader :content_type
|
|
17
|
+
alias :ContentType :content_type
|
|
18
|
+
|
|
19
|
+
# The content type.
|
|
20
|
+
# @see Axlsx#validate_content_type
|
|
21
|
+
def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
|
|
22
|
+
alias :ContentType= :content_type=
|
|
23
|
+
|
|
24
|
+
# Serialize the contenty type to xml
|
|
25
|
+
def to_xml_string(node_name = '', str = '')
|
|
26
|
+
str << "<#{node_name} "
|
|
27
|
+
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
28
|
+
str << '/>'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -2,55 +2,24 @@
|
|
|
2
2
|
module Axlsx
|
|
3
3
|
|
|
4
4
|
# An default content part. These parts are automatically created by for you based on the content of your package.
|
|
5
|
-
class Default
|
|
5
|
+
class Default < AbstractContentType
|
|
6
6
|
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
# @option options [String] content_type
|
|
10
|
-
# @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
|
|
11
|
-
def initialize(options={})
|
|
12
|
-
raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
|
|
13
|
-
options.each do |name, value|
|
|
14
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Error string for option validation
|
|
19
|
-
INVALID_ARGUMENTS = "extension and content_type are required"
|
|
7
|
+
# The serialization node name for this class
|
|
8
|
+
NODE_NAME = 'Default'
|
|
20
9
|
|
|
21
10
|
# The extension of the content type.
|
|
22
11
|
# @return [String]
|
|
23
12
|
attr_reader :extension
|
|
24
13
|
alias :Extension :extension
|
|
25
14
|
|
|
26
|
-
# The type of content.
|
|
27
|
-
# @return [String]
|
|
28
|
-
attr_reader :content_type
|
|
29
|
-
alias :ContentType :content_type
|
|
30
|
-
|
|
31
15
|
# Sets the file extension for this content type.
|
|
32
16
|
def extension=(v) Axlsx::validate_string v; @extension = v end
|
|
33
17
|
alias :Extension= :extension=
|
|
34
18
|
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
alias :ContentType= :content_type=
|
|
39
|
-
|
|
40
|
-
# Serializes the object
|
|
41
|
-
# @param [String] str
|
|
42
|
-
# @return [String]
|
|
43
|
-
def to_xml_string(str = '')
|
|
44
|
-
str << '<Default '
|
|
45
|
-
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
46
|
-
str << '/>'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
def validate_options(options)
|
|
51
|
-
(options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
|
|
19
|
+
# Serializes this object to xml
|
|
20
|
+
def to_xml_string(str ='')
|
|
21
|
+
super(NODE_NAME, str)
|
|
52
22
|
end
|
|
53
|
-
|
|
54
23
|
end
|
|
55
24
|
|
|
56
25
|
end
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
+
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
module Axlsx
|
|
3
4
|
|
|
4
5
|
# An override content part. These parts are automatically created by for you based on the content of your package.
|
|
5
|
-
class Override
|
|
6
|
-
|
|
7
|
-
#Creates a new Override object
|
|
8
|
-
# @option options [String] PartName
|
|
9
|
-
# @option options [String] ContentType
|
|
10
|
-
# @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
|
|
11
|
-
def initialize(options={})
|
|
12
|
-
raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
|
|
13
|
-
options.each do |name, value|
|
|
14
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
15
|
-
end
|
|
16
|
-
end
|
|
6
|
+
class Override < AbstractContentType
|
|
17
7
|
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# The type of content.
|
|
22
|
-
# @return [String]
|
|
23
|
-
attr_reader :content_type
|
|
24
|
-
alias :ContentType :content_type
|
|
8
|
+
# Serialization node name for this object
|
|
9
|
+
NODE_NAME = 'Override'
|
|
25
10
|
|
|
26
11
|
# The name and location of the part.
|
|
27
12
|
# @return [String]
|
|
@@ -32,26 +17,9 @@ module Axlsx
|
|
|
32
17
|
def part_name=(v) Axlsx::validate_string v; @part_name = v end
|
|
33
18
|
alias :PartName= :part_name=
|
|
34
19
|
|
|
35
|
-
#
|
|
36
|
-
# @see Axlsx#validate_content_type
|
|
37
|
-
def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
|
|
38
|
-
alias :ContentType= :content_type=
|
|
39
|
-
|
|
40
|
-
# Serializes the object
|
|
41
|
-
# @param [String] str
|
|
42
|
-
# @return [String]
|
|
20
|
+
# Serializes this object to xml
|
|
43
21
|
def to_xml_string(str = '')
|
|
44
|
-
str
|
|
45
|
-
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
46
|
-
str << '/>'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def validate_options(options)
|
|
52
|
-
(options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
|
|
22
|
+
super(NODE_NAME, str)
|
|
53
23
|
end
|
|
54
|
-
|
|
55
24
|
end
|
|
56
|
-
|
|
57
25
|
end
|
data/lib/axlsx/doc_props/app.rb
CHANGED
|
@@ -11,6 +11,8 @@ module Axlsx
|
|
|
11
11
|
# DigSig (DigSigBlob)
|
|
12
12
|
class App
|
|
13
13
|
|
|
14
|
+
include Axlsx::OptionsParser
|
|
15
|
+
|
|
14
16
|
# Creates an App object
|
|
15
17
|
# @option options [String] template
|
|
16
18
|
# @option options [String] manager
|
|
@@ -35,9 +37,7 @@ module Axlsx
|
|
|
35
37
|
# @option options [String] app_version
|
|
36
38
|
# @option options [Integer] doc_security
|
|
37
39
|
def initialize(options={})
|
|
38
|
-
options
|
|
39
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
40
|
-
end
|
|
40
|
+
parse_options options
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# @return [String] The name of the document template.
|
|
@@ -134,15 +134,15 @@ module Axlsx
|
|
|
134
134
|
|
|
135
135
|
# Sets the template property of your app.xml file
|
|
136
136
|
def template=(v) Axlsx::validate_string v; @template = v; end
|
|
137
|
-
alias :Template :template
|
|
137
|
+
alias :Template= :template=
|
|
138
138
|
|
|
139
139
|
# Sets the manager property of your app.xml file
|
|
140
140
|
def manager=(v) Axlsx::validate_string v; @manager = v; end
|
|
141
|
-
alias :Manager :manager
|
|
141
|
+
alias :Manager= :manager=
|
|
142
142
|
|
|
143
143
|
# Sets the company property of your app.xml file
|
|
144
144
|
def company=(v) Axlsx::validate_string v; @company = v; end
|
|
145
|
-
alias :Company :company
|
|
145
|
+
alias :Company= :company=
|
|
146
146
|
# Sets the pages property of your app.xml file
|
|
147
147
|
def pages=(v) Axlsx::validate_int v; @pages = v; end
|
|
148
148
|
|
|
@@ -223,7 +223,10 @@ module Axlsx
|
|
|
223
223
|
def to_xml_string(str = '')
|
|
224
224
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
225
225
|
str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
|
|
226
|
-
|
|
226
|
+
instance_values.each do |key, value|
|
|
227
|
+
node_name = Axlsx.camel(key)
|
|
228
|
+
str << "<#{node_name}>#{value}</#{node_name}>"
|
|
229
|
+
end
|
|
227
230
|
str << '</Properties>'
|
|
228
231
|
end
|
|
229
232
|
|
data/lib/axlsx/doc_props/core.rb
CHANGED
|
@@ -8,14 +8,19 @@ module Axlsx
|
|
|
8
8
|
|
|
9
9
|
# Creates a new Core object.
|
|
10
10
|
# @option options [String] creator
|
|
11
|
+
# @option options [Time] created
|
|
11
12
|
def initialize(options={})
|
|
12
13
|
@creator = options[:creator] || 'axlsx'
|
|
14
|
+
@created = options[:created]
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
# The author of the document. By default this is 'axlsx'
|
|
16
18
|
# @return [String]
|
|
17
19
|
attr_accessor :creator
|
|
18
20
|
|
|
21
|
+
# Creation time of the document. If nil, the current time will be used.
|
|
22
|
+
attr_accessor :created
|
|
23
|
+
|
|
19
24
|
# serializes the core.xml document
|
|
20
25
|
# @return [String]
|
|
21
26
|
def to_xml_string(str = '')
|
|
@@ -24,7 +29,7 @@ module Axlsx
|
|
|
24
29
|
str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
|
|
25
30
|
str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
|
|
26
31
|
str << '<dc:creator>' << self.creator << '</dc:creator>'
|
|
27
|
-
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
|
|
32
|
+
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
|
|
28
33
|
str << '<cp:revision>0</cp:revision>'
|
|
29
34
|
str << '</cp:coreProperties>'
|
|
30
35
|
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
|
|
3
|
+
# The Axes class creates and manages axis information and
|
|
4
|
+
# serialization for charts.
|
|
5
|
+
class Axes
|
|
6
|
+
|
|
7
|
+
# @param [Hash] options options used to generate axis each key
|
|
8
|
+
# should be an axis name like :val_axis and its value should be the
|
|
9
|
+
# class of the axis type to construct. The :cat_axis, if there is one,
|
|
10
|
+
# must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
|
|
11
|
+
def initialize(options={})
|
|
12
|
+
raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis
|
|
13
|
+
options.each do |name, axis_class|
|
|
14
|
+
add_axis(name, axis_class)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# [] provides assiciative access to a specic axis store in an axes
|
|
19
|
+
# instance.
|
|
20
|
+
# @return [Axis]
|
|
21
|
+
def [](name)
|
|
22
|
+
axes.assoc(name)[1]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Serializes the object
|
|
26
|
+
# @param [String] str
|
|
27
|
+
# @param [Hash] options
|
|
28
|
+
# @option options ids
|
|
29
|
+
# If the ids option is specified only the axis identifier is
|
|
30
|
+
# serialized. Otherwise, each axis is serialized in full.
|
|
31
|
+
def to_xml_string(str = '', options = {})
|
|
32
|
+
if options[:ids]
|
|
33
|
+
# CatAxis must come first in the XML (for Microsoft Excel at least)
|
|
34
|
+
sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 }
|
|
35
|
+
sorted.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
|
|
36
|
+
else
|
|
37
|
+
axes.each { |axis| axis[1].to_xml_string(str) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Adds an axis to the collection
|
|
42
|
+
# @param [Symbol] name The name of the axis
|
|
43
|
+
# @param [Axis] axis_class The axis class to generate
|
|
44
|
+
def add_axis(name, axis_class)
|
|
45
|
+
axis = axis_class.new
|
|
46
|
+
set_cross_axis(axis)
|
|
47
|
+
axes << [name, axis]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def axes
|
|
53
|
+
@axes ||= []
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def set_cross_axis(axis)
|
|
57
|
+
axes.first[1].cross_axis = axis if axes.size == 1
|
|
58
|
+
axis.cross_axis = axes.first[1] unless axes.empty?
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/lib/axlsx/drawing/axis.rb
CHANGED
|
@@ -4,18 +4,16 @@ module Axlsx
|
|
|
4
4
|
# the access class defines common properties and values for a chart axis.
|
|
5
5
|
class Axis
|
|
6
6
|
|
|
7
|
+
include Axlsx::OptionsParser
|
|
8
|
+
|
|
7
9
|
# Creates an Axis object
|
|
8
|
-
# @
|
|
9
|
-
# @param [Integer] cross_ax the id of the perpendicular axis
|
|
10
|
+
# @option options [Axis] cross_axis the perpendicular axis
|
|
10
11
|
# @option options [Symbol] ax_pos
|
|
11
12
|
# @option options [Symbol] crosses
|
|
12
13
|
# @option options [Symbol] tick_lbl_pos
|
|
13
14
|
# @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
|
|
14
|
-
def initialize(
|
|
15
|
-
|
|
16
|
-
Axlsx::validate_unsigned_int(cross_ax)
|
|
17
|
-
@ax_id = ax_id
|
|
18
|
-
@cross_ax = cross_ax
|
|
15
|
+
def initialize(options={})
|
|
16
|
+
@id = rand(8 ** 8)
|
|
19
17
|
@format_code = "General"
|
|
20
18
|
@delete = @label_rotation = 0
|
|
21
19
|
@scaling = Scaling.new(:orientation=>:minMax)
|
|
@@ -25,9 +23,7 @@ module Axlsx
|
|
|
25
23
|
self.format_code = "General"
|
|
26
24
|
self.crosses = :autoZero
|
|
27
25
|
self.gridlines = true
|
|
28
|
-
options
|
|
29
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
30
|
-
end
|
|
26
|
+
parse_options options
|
|
31
27
|
end
|
|
32
28
|
|
|
33
29
|
# the fill color to use in the axis shape properties. This should be a 6 character long hex string
|
|
@@ -37,13 +33,13 @@ module Axlsx
|
|
|
37
33
|
|
|
38
34
|
# the id of the axis.
|
|
39
35
|
# @return [Integer]
|
|
40
|
-
attr_reader :
|
|
41
|
-
alias :axID :
|
|
36
|
+
attr_reader :id
|
|
37
|
+
alias :axID :id
|
|
42
38
|
|
|
43
39
|
# The perpendicular axis
|
|
44
40
|
# @return [Integer]
|
|
45
|
-
attr_reader :
|
|
46
|
-
alias :crossAx :
|
|
41
|
+
attr_reader :cross_axis
|
|
42
|
+
alias :crossAx :cross_axis
|
|
47
43
|
|
|
48
44
|
# The scaling of the axis
|
|
49
45
|
# @see Scaling
|
|
@@ -94,6 +90,13 @@ module Axlsx
|
|
|
94
90
|
def color=(color_rgb)
|
|
95
91
|
@color = color_rgb
|
|
96
92
|
end
|
|
93
|
+
|
|
94
|
+
# The crossing axis for this axis
|
|
95
|
+
# @param [Axis] axis
|
|
96
|
+
def cross_axis=(axis)
|
|
97
|
+
DataTypeValidator.validate "#{self.class}.cross_axis", [Axis], axis
|
|
98
|
+
@cross_axis = axis
|
|
99
|
+
end
|
|
97
100
|
|
|
98
101
|
# The position of the axis
|
|
99
102
|
# must be one of [:l, :r, :t, :b]
|
|
@@ -102,7 +105,7 @@ module Axlsx
|
|
|
102
105
|
|
|
103
106
|
# the position of the tick labels
|
|
104
107
|
# must be one of [:nextTo, :high, :low1]
|
|
105
|
-
def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low], v; @tick_lbl_pos = v; end
|
|
108
|
+
def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v; @tick_lbl_pos = v; end
|
|
106
109
|
alias :tickLblPos= :tick_lbl_pos=
|
|
107
110
|
|
|
108
111
|
# The number format format code for this axis
|
|
@@ -147,7 +150,7 @@ module Axlsx
|
|
|
147
150
|
# @param [String] str
|
|
148
151
|
# @return [String]
|
|
149
152
|
def to_xml_string(str = '')
|
|
150
|
-
str << '<c:axId val="' << @
|
|
153
|
+
str << '<c:axId val="' << @id.to_s << '"/>'
|
|
151
154
|
@scaling.to_xml_string str
|
|
152
155
|
str << '<c:delete val="'<< @delete.to_s << '"/>'
|
|
153
156
|
str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
|
|
@@ -175,7 +178,7 @@ module Axlsx
|
|
|
175
178
|
end
|
|
176
179
|
# some potential value in implementing this in full. Very detailed!
|
|
177
180
|
str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
|
|
178
|
-
str << '<c:crossAx val="' << @
|
|
181
|
+
str << '<c:crossAx val="' << @cross_axis.id.to_s << '"/>'
|
|
179
182
|
str << '<c:crosses val="' << @crosses.to_s << '"/>'
|
|
180
183
|
end
|
|
181
184
|
|