dg-axlsx 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/.yardopts_guide +19 -0
- data/CHANGELOG.md +239 -0
- data/LICENSE +22 -0
- data/README.md +259 -0
- data/Rakefile +30 -0
- data/examples/2010_comments.rb +17 -0
- data/examples/anchor_swapping.rb +28 -0
- data/examples/auto_filter.rb +25 -0
- data/examples/basic_charts.rb +58 -0
- data/examples/chart_colors.rb +88 -0
- data/examples/colored_links.rb +59 -0
- data/examples/conditional_formatting/example_conditional_formatting.rb +89 -0
- data/examples/conditional_formatting/getting_barred.rb +37 -0
- data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
- data/examples/conditional_formatting/scaled_colors.rb +39 -0
- data/examples/conditional_formatting/stop_and_go.rb +37 -0
- data/examples/data_validation.rb +50 -0
- data/examples/example.rb +875 -0
- data/examples/extractive.rb +45 -0
- data/examples/image1.jpeg +0 -0
- data/examples/ios_preview.rb +14 -0
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/page_setup.rb +11 -0
- data/examples/pivot_table.rb +39 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/sheet_protection.rb +10 -0
- data/examples/skydrive/real_example.rb +63 -0
- data/examples/split.rb +16 -0
- data/examples/styles.rb +66 -0
- data/examples/underline.rb +13 -0
- data/examples/wrap_text.rb +21 -0
- data/lib/axlsx.rb +168 -0
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +26 -0
- data/lib/axlsx/content_type/default.rb +25 -0
- data/lib/axlsx/content_type/override.rb +25 -0
- data/lib/axlsx/doc_props/app.rb +235 -0
- data/lib/axlsx/doc_props/core.rb +39 -0
- data/lib/axlsx/drawing/ax_data_source.rb +26 -0
- data/lib/axlsx/drawing/axes.rb +61 -0
- data/lib/axlsx/drawing/axis.rb +190 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +151 -0
- data/lib/axlsx/drawing/bar_series.rb +82 -0
- 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 +85 -0
- data/lib/axlsx/drawing/chart.rb +269 -0
- data/lib/axlsx/drawing/d_lbls.rb +90 -0
- data/lib/axlsx/drawing/drawing.rb +164 -0
- data/lib/axlsx/drawing/graphic_frame.rb +54 -0
- data/lib/axlsx/drawing/hyperlink.rb +100 -0
- data/lib/axlsx/drawing/line_3D_chart.rb +68 -0
- data/lib/axlsx/drawing/line_chart.rb +99 -0
- data/lib/axlsx/drawing/line_series.rb +110 -0
- data/lib/axlsx/drawing/marker.rb +84 -0
- data/lib/axlsx/drawing/num_data.rb +52 -0
- data/lib/axlsx/drawing/num_data_source.rb +62 -0
- data/lib/axlsx/drawing/num_val.rb +32 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +98 -0
- data/lib/axlsx/drawing/pic.rb +213 -0
- data/lib/axlsx/drawing/picture_locking.rb +42 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +47 -0
- data/lib/axlsx/drawing/pie_series.rb +74 -0
- data/lib/axlsx/drawing/scaling.rb +60 -0
- data/lib/axlsx/drawing/scatter_chart.rb +74 -0
- data/lib/axlsx/drawing/scatter_series.rb +84 -0
- data/lib/axlsx/drawing/ser_axis.rb +45 -0
- data/lib/axlsx/drawing/series.rb +69 -0
- data/lib/axlsx/drawing/series_title.rb +23 -0
- data/lib/axlsx/drawing/str_data.rb +42 -0
- data/lib/axlsx/drawing/str_val.rb +32 -0
- data/lib/axlsx/drawing/title.rb +78 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +92 -0
- data/lib/axlsx/drawing/val_axis.rb +37 -0
- data/lib/axlsx/drawing/view_3D.rb +115 -0
- data/lib/axlsx/drawing/vml_drawing.rb +42 -0
- data/lib/axlsx/drawing/vml_shape.rb +66 -0
- data/lib/axlsx/package.rb +363 -0
- data/lib/axlsx/rels/relationship.rb +129 -0
- data/lib/axlsx/rels/relationships.rb +29 -0
- data/lib/axlsx/stylesheet/border.rb +71 -0
- data/lib/axlsx/stylesheet/border_pr.rb +71 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +132 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +41 -0
- data/lib/axlsx/stylesheet/cell_style.rb +72 -0
- data/lib/axlsx/stylesheet/color.rb +76 -0
- data/lib/axlsx/stylesheet/dxf.rb +79 -0
- data/lib/axlsx/stylesheet/fill.rb +35 -0
- data/lib/axlsx/stylesheet/font.rb +148 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +103 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +37 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +77 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +73 -0
- data/lib/axlsx/stylesheet/styles.rb +420 -0
- data/lib/axlsx/stylesheet/table_style.rb +54 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +77 -0
- data/lib/axlsx/stylesheet/table_styles.rb +46 -0
- data/lib/axlsx/stylesheet/xf.rb +147 -0
- data/lib/axlsx/util/accessors.rb +64 -0
- data/lib/axlsx/util/constants.rb +397 -0
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +16 -0
- data/lib/axlsx/util/parser.rb +44 -0
- data/lib/axlsx/util/serialized_attributes.rb +89 -0
- data/lib/axlsx/util/simple_typed_list.rb +179 -0
- data/lib/axlsx/util/storage.rb +146 -0
- data/lib/axlsx/util/string.rb +7 -0
- data/lib/axlsx/util/validators.rb +311 -0
- data/lib/axlsx/version.rb +5 -0
- data/lib/axlsx/workbook/defined_name.rb +128 -0
- data/lib/axlsx/workbook/defined_names.rb +21 -0
- data/lib/axlsx/workbook/shared_strings_table.rb +77 -0
- data/lib/axlsx/workbook/workbook.rb +361 -0
- 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 +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -0
- data/lib/axlsx/workbook/worksheet/break.rb +35 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +475 -0
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +154 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -0
- data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
- data/lib/axlsx/workbook/worksheet/col.rb +141 -0
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
- data/lib/axlsx/workbook/worksheet/comment.rb +91 -0
- data/lib/axlsx/workbook/worksheet/comments.rb +82 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -0
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
- data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -0
- data/lib/axlsx/workbook/worksheet/data_validation.rb +246 -0
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -0
- data/lib/axlsx/workbook/worksheet/dimension.rb +64 -0
- data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -0
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -0
- data/lib/axlsx/workbook/worksheet/pane.rb +139 -0
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +266 -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 +39 -0
- data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -0
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
- 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 +154 -0
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +101 -0
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -0
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +79 -0
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -0
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -0
- data/lib/axlsx/workbook/worksheet/table.rb +102 -0
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +798 -0
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -0
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/dg-axlsx.rb +1 -0
- data/lib/schema/dc.xsd +118 -0
- data/lib/schema/dcmitype.xsd +52 -0
- data/lib/schema/dcterms.xsd +331 -0
- data/lib/schema/dml-chart.xsd +1499 -0
- data/lib/schema/dml-chartDrawing.xsd +146 -0
- data/lib/schema/dml-compatibility.xsd +14 -0
- data/lib/schema/dml-diagram.xsd +1091 -0
- data/lib/schema/dml-lockedCanvas.xsd +11 -0
- data/lib/schema/dml-main.xsd +3048 -0
- data/lib/schema/dml-picture.xsd +23 -0
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
- data/lib/schema/opc-contentTypes.xsd +42 -0
- data/lib/schema/opc-coreProperties.xsd +54 -0
- data/lib/schema/opc-digSig.xsd +49 -0
- data/lib/schema/opc-relationships.xsd +33 -0
- data/lib/schema/pml.xsd +1676 -0
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
- data/lib/schema/shared-bibliography.xsd +144 -0
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
- data/lib/schema/shared-math.xsd +582 -0
- data/lib/schema/shared-relationshipReference.xsd +25 -0
- data/lib/schema/sml.xsd +4434 -0
- data/lib/schema/vml-main.xsd +569 -0
- data/lib/schema/vml-officeDrawing.xsd +509 -0
- data/lib/schema/vml-presentationDrawing.xsd +12 -0
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
- data/lib/schema/wml.xsd +3644 -0
- data/lib/schema/xml.xsd +116 -0
- data/test/benchmark.rb +72 -0
- data/test/content_type/tc_content_type.rb +76 -0
- data/test/content_type/tc_default.rb +16 -0
- data/test/content_type/tc_override.rb +14 -0
- data/test/doc_props/tc_app.rb +43 -0
- data/test/doc_props/tc_core.rb +42 -0
- data/test/drawing/tc_axes.rb +8 -0
- data/test/drawing/tc_axis.rb +112 -0
- data/test/drawing/tc_bar_3D_chart.rb +71 -0
- data/test/drawing/tc_bar_series.rb +37 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_cat_axis.rb +31 -0
- data/test/drawing/tc_cat_axis_data.rb +27 -0
- data/test/drawing/tc_chart.rb +110 -0
- data/test/drawing/tc_d_lbls.rb +57 -0
- data/test/drawing/tc_data_source.rb +23 -0
- data/test/drawing/tc_drawing.rb +80 -0
- data/test/drawing/tc_graphic_frame.rb +27 -0
- data/test/drawing/tc_hyperlink.rb +64 -0
- data/test/drawing/tc_line_3d_chart.rb +47 -0
- data/test/drawing/tc_line_chart.rb +39 -0
- data/test/drawing/tc_line_series.rb +71 -0
- data/test/drawing/tc_marker.rb +44 -0
- data/test/drawing/tc_named_axis_data.rb +27 -0
- data/test/drawing/tc_num_data.rb +31 -0
- data/test/drawing/tc_num_val.rb +29 -0
- data/test/drawing/tc_one_cell_anchor.rb +66 -0
- data/test/drawing/tc_pic.rb +106 -0
- data/test/drawing/tc_picture_locking.rb +72 -0
- data/test/drawing/tc_pie_3D_chart.rb +28 -0
- data/test/drawing/tc_pie_series.rb +32 -0
- data/test/drawing/tc_scaling.rb +36 -0
- data/test/drawing/tc_scatter_chart.rb +48 -0
- data/test/drawing/tc_scatter_series.rb +45 -0
- data/test/drawing/tc_ser_axis.rb +31 -0
- data/test/drawing/tc_series.rb +23 -0
- data/test/drawing/tc_series_title.rb +33 -0
- data/test/drawing/tc_str_data.rb +18 -0
- data/test/drawing/tc_str_val.rb +21 -0
- data/test/drawing/tc_title.rb +49 -0
- data/test/drawing/tc_two_cell_anchor.rb +36 -0
- data/test/drawing/tc_val_axis.rb +24 -0
- data/test/drawing/tc_view_3D.rb +54 -0
- data/test/drawing/tc_vml_drawing.rb +25 -0
- data/test/drawing/tc_vml_shape.rb +106 -0
- data/test/profile.rb +24 -0
- data/test/rels/tc_relationship.rb +44 -0
- data/test/rels/tc_relationships.rb +37 -0
- data/test/stylesheet/tc_border.rb +37 -0
- data/test/stylesheet/tc_border_pr.rb +32 -0
- data/test/stylesheet/tc_cell_alignment.rb +81 -0
- data/test/stylesheet/tc_cell_protection.rb +29 -0
- data/test/stylesheet/tc_cell_style.rb +57 -0
- data/test/stylesheet/tc_color.rb +43 -0
- data/test/stylesheet/tc_dxf.rb +81 -0
- data/test/stylesheet/tc_fill.rb +18 -0
- data/test/stylesheet/tc_font.rb +121 -0
- data/test/stylesheet/tc_gradient_fill.rb +72 -0
- data/test/stylesheet/tc_gradient_stop.rb +31 -0
- data/test/stylesheet/tc_num_fmt.rb +30 -0
- data/test/stylesheet/tc_pattern_fill.rb +43 -0
- data/test/stylesheet/tc_styles.rb +235 -0
- data/test/stylesheet/tc_table_style.rb +44 -0
- data/test/stylesheet/tc_table_style_element.rb +45 -0
- data/test/stylesheet/tc_table_styles.rb +29 -0
- data/test/stylesheet/tc_xf.rb +120 -0
- data/test/tc_axlsx.rb +72 -0
- data/test/tc_helper.rb +10 -0
- data/test/tc_package.rb +233 -0
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_serialized_attributes.rb +19 -0
- data/test/util/tc_simple_typed_list.rb +77 -0
- data/test/util/tc_validators.rb +210 -0
- data/test/workbook/tc_defined_name.rb +49 -0
- data/test/workbook/tc_shared_strings_table.rb +58 -0
- data/test/workbook/tc_workbook.rb +139 -0
- data/test/workbook/tc_workbook_view.rb +50 -0
- 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 +358 -0
- data/test/workbook/worksheet/tc_cfvo.rb +31 -0
- data/test/workbook/worksheet/tc_col.rb +78 -0
- data/test/workbook/worksheet/tc_color_scale.rb +58 -0
- data/test/workbook/worksheet/tc_comment.rb +72 -0
- data/test/workbook/worksheet/tc_comments.rb +57 -0
- data/test/workbook/worksheet/tc_conditional_formatting.rb +224 -0
- data/test/workbook/worksheet/tc_data_bar.rb +46 -0
- data/test/workbook/worksheet/tc_data_validation.rb +265 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +124 -0
- data/test/workbook/worksheet/tc_header_footer.rb +151 -0
- data/test/workbook/worksheet/tc_icon_set.rb +45 -0
- data/test/workbook/worksheet/tc_page_margins.rb +97 -0
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_page_setup.rb +143 -0
- data/test/workbook/worksheet/tc_pane.rb +54 -0
- 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_print_options.rb +72 -0
- data/test/workbook/worksheet/tc_protected_range.rb +17 -0
- 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 +117 -0
- data/test/workbook/worksheet/tc_selection.rb +55 -0
- 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 +49 -0
- data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
- data/test/workbook/worksheet/tc_table.rb +68 -0
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +577 -0
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
- metadata +583 -0
@@ -0,0 +1,213 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
# View options for a worksheet.
|
4
|
+
#
|
5
|
+
# @note The recommended way to manage the sheet view is via Worksheet#sheet_view
|
6
|
+
# @see Worksheet#sheet_view
|
7
|
+
class SheetView
|
8
|
+
|
9
|
+
include Axlsx::OptionsParser
|
10
|
+
include Axlsx::Accessors
|
11
|
+
include Axlsx::SerializedAttributes
|
12
|
+
|
13
|
+
# Creates a new {SheetView} object
|
14
|
+
# @option options [Integer] color_id Color Id
|
15
|
+
# @option options [Boolean] default_grid_color Default Grid Color
|
16
|
+
# @option options [Boolean] right_to_left Right To Left
|
17
|
+
# @option options [Boolean] show_formulas Show Formulas
|
18
|
+
# @option options [Boolean] show_grid_lines Show Grid Lines
|
19
|
+
# @option options [Boolean] show_outline_symbols Show Outline Symbols
|
20
|
+
# @option options [Boolean] show_row_col_headers Show Headers
|
21
|
+
# @option options [Boolean] show_ruler Show Ruler
|
22
|
+
# @option options [Boolean] show_white_space Show White Space
|
23
|
+
# @option options [Boolean] show_zeros Show Zero Values
|
24
|
+
# @option options [Boolean] tab_selected Sheet Tab Selected
|
25
|
+
# @option options [String, Cell] top_left_cell Top Left Visible Cell
|
26
|
+
# @option options [Symbol] view View Type
|
27
|
+
# @option options [Boolean] window_protection Window Protection
|
28
|
+
# @option options [Integer] workbook_view_id Workbook View Index
|
29
|
+
# @option options [Integer] zoom_scale
|
30
|
+
# @option options [Integer] zoom_scale_normal Zoom Scale Normal View
|
31
|
+
# @option options [Integer] zoom_scale_page_layout_view Zoom Scale Page Layout View
|
32
|
+
# @option options [Integer] zoom_scale_sheet_layout_view Zoom Scale Page Break Preview
|
33
|
+
def initialize(options={})
|
34
|
+
#defaults
|
35
|
+
@color_id = @top_left_cell = @pane = nil
|
36
|
+
@right_to_left = @show_formulas = @show_outline_symbols = @show_white_space = @tab_selected = @window_protection = false
|
37
|
+
@default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = true
|
38
|
+
@zoom_scale = 100
|
39
|
+
@zoom_scale_normal = @zoom_scale_page_layout_view = @zoom_scale_sheet_layout_view = @workbook_view_id = 0
|
40
|
+
@selections = {}
|
41
|
+
parse_options options
|
42
|
+
end
|
43
|
+
|
44
|
+
boolean_attr_accessor :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
|
45
|
+
:show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols
|
46
|
+
|
47
|
+
serializable_attributes :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
|
48
|
+
:show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols,
|
49
|
+
:zoom_scale_sheet_layout_view, :zoom_scale_page_layout_view, :zoom_scale_normal, :workbook_view_id,
|
50
|
+
:view, :top_left_cell, :color_id, :zoom_scale
|
51
|
+
|
52
|
+
|
53
|
+
# instance values that must be serialized as their own elements - e.g. not attributes.
|
54
|
+
CHILD_ELEMENTS = [ :pane, :selections ]
|
55
|
+
|
56
|
+
# The pane object for the sheet view
|
57
|
+
# @return [Pane]
|
58
|
+
# @see [Pane]
|
59
|
+
def pane
|
60
|
+
@pane ||= Pane.new
|
61
|
+
yield @pane if block_given?
|
62
|
+
@pane
|
63
|
+
end
|
64
|
+
|
65
|
+
# A hash of selection objects keyed by pane type associated with this sheet view.
|
66
|
+
# @return [Hash]
|
67
|
+
attr_reader :selections
|
68
|
+
|
69
|
+
#
|
70
|
+
# Color Id
|
71
|
+
# Index to the color value for row/column
|
72
|
+
# text headings and gridlines. This is an
|
73
|
+
# 'index color value' (ICV) rather than
|
74
|
+
# rgb value.
|
75
|
+
# @see type
|
76
|
+
# @return [Integer]
|
77
|
+
# default nil
|
78
|
+
attr_reader :color_id
|
79
|
+
|
80
|
+
# Top Left Visible Cell
|
81
|
+
# Location of the top left visible cell Location
|
82
|
+
# of the top left visible cell in the bottom right
|
83
|
+
# pane (when in Left-to-Right mode).
|
84
|
+
# @see type
|
85
|
+
# @return [String]
|
86
|
+
# default nil
|
87
|
+
attr_reader :top_left_cell
|
88
|
+
|
89
|
+
|
90
|
+
# View Type
|
91
|
+
# Indicates the view type.
|
92
|
+
# Options are
|
93
|
+
# * normal: Normal view
|
94
|
+
# * page_break_preview: Page break preview
|
95
|
+
# * page_layout: Page Layout View
|
96
|
+
# @see type
|
97
|
+
# @return [Symbol]
|
98
|
+
# default :normal
|
99
|
+
attr_reader :view
|
100
|
+
|
101
|
+
# Workbook View Index
|
102
|
+
# Zero-based index of this workbook view, pointing
|
103
|
+
# to a workbookView element in the bookViews collection.
|
104
|
+
# @see type
|
105
|
+
# @return [Integer]
|
106
|
+
# default 0
|
107
|
+
attr_reader :workbook_view_id
|
108
|
+
|
109
|
+
# Zoom Scale
|
110
|
+
# Window zoom magnification for current view
|
111
|
+
# representing percent values. This attribute
|
112
|
+
# is restricted to values ranging from 10 to 400.
|
113
|
+
# Horizontal & Vertical scale together.
|
114
|
+
# Current view can be Normal, Page Layout, or
|
115
|
+
# Page Break Preview.
|
116
|
+
# @see type
|
117
|
+
# @return [Integer]
|
118
|
+
# default 100
|
119
|
+
attr_reader :zoom_scale
|
120
|
+
|
121
|
+
|
122
|
+
# Zoom Scale Normal View
|
123
|
+
# Zoom magnification to use when in normal view,
|
124
|
+
# representing percent values. This attribute is
|
125
|
+
# restricted to values ranging from 10 to 400.
|
126
|
+
# Horizontal & Vertical scale together.
|
127
|
+
# Applies for worksheets only; zero implies the
|
128
|
+
# automatic setting.
|
129
|
+
# @see type
|
130
|
+
# @return [Integer]
|
131
|
+
# default 0
|
132
|
+
attr_reader :zoom_scale_normal
|
133
|
+
|
134
|
+
|
135
|
+
# Zoom Scale Page Layout View
|
136
|
+
# Zoom magnification to use when in page layout
|
137
|
+
# view, representing percent values. This attribute
|
138
|
+
# is restricted to values ranging from 10 to 400.
|
139
|
+
# Horizontal & Vertical scale together.
|
140
|
+
# Applies for worksheets only; zero implies
|
141
|
+
# the automatic setting.
|
142
|
+
# @see type
|
143
|
+
# @return [Integer]
|
144
|
+
# default 0
|
145
|
+
attr_reader :zoom_scale_page_layout_view
|
146
|
+
|
147
|
+
|
148
|
+
# Zoom Scale Page Break Preview
|
149
|
+
# Zoom magnification to use when in page break
|
150
|
+
# preview, representing percent values. This
|
151
|
+
# attribute is restricted to values ranging
|
152
|
+
# from 10 to 400. Horizontal & Vertical scale
|
153
|
+
# together.
|
154
|
+
# Applies for worksheet only; zero implies
|
155
|
+
# the automatic setting.
|
156
|
+
# @see type
|
157
|
+
# @return [Integer]
|
158
|
+
# default 0
|
159
|
+
attr_reader :zoom_scale_sheet_layout_view
|
160
|
+
|
161
|
+
# Adds a new selection
|
162
|
+
# param [Symbol] pane
|
163
|
+
# param [Hash] options
|
164
|
+
# return [Selection]
|
165
|
+
def add_selection(pane, options = {})
|
166
|
+
@selections[pane] = Selection.new(options.merge(:pane => pane))
|
167
|
+
end
|
168
|
+
|
169
|
+
# @see color_id
|
170
|
+
def color_id=(v); Axlsx::validate_unsigned_int(v); @color_id = v end
|
171
|
+
|
172
|
+
# @see top_left_cell
|
173
|
+
def top_left_cell=(v)
|
174
|
+
cell = (v.class == Axlsx::Cell ? v.r_abs : v)
|
175
|
+
Axlsx::validate_string(cell)
|
176
|
+
@top_left_cell = cell
|
177
|
+
end
|
178
|
+
|
179
|
+
# @see view
|
180
|
+
def view=(v); Axlsx::validate_sheet_view_type(v); @view = v end
|
181
|
+
|
182
|
+
# @see workbook_view_id
|
183
|
+
def workbook_view_id=(v); Axlsx::validate_unsigned_int(v); @workbook_view_id = v end
|
184
|
+
|
185
|
+
# @see zoom_scale
|
186
|
+
def zoom_scale=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale = v end
|
187
|
+
|
188
|
+
# @see zoom_scale_normal
|
189
|
+
def zoom_scale_normal=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_normal = v end
|
190
|
+
|
191
|
+
# @see zoom_scale_page_layout_view
|
192
|
+
def zoom_scale_page_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
|
193
|
+
|
194
|
+
# @see zoom_scale_sheet_layout_view
|
195
|
+
def zoom_scale_sheet_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
|
196
|
+
|
197
|
+
# Serializes the data validation
|
198
|
+
# @param [String] str
|
199
|
+
# @return [String]
|
200
|
+
def to_xml_string(str = '')
|
201
|
+
str << '<sheetViews>'
|
202
|
+
str << '<sheetView '
|
203
|
+
serialized_attributes str
|
204
|
+
str << '>'
|
205
|
+
@pane.to_xml_string(str) if @pane
|
206
|
+
@selections.each do |key, selection|
|
207
|
+
selection.to_xml_string(str)
|
208
|
+
end
|
209
|
+
str << '</sheetView>'
|
210
|
+
str << '</sheetViews>'
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
# Table
|
4
|
+
# @note Worksheet#add_table is the recommended way to create tables for your worksheets.
|
5
|
+
# @see README for examples
|
6
|
+
class Table
|
7
|
+
|
8
|
+
include Axlsx::OptionsParser
|
9
|
+
|
10
|
+
# Creates a new Table object
|
11
|
+
# @param [String] ref The reference to the table data like 'A1:G24'.
|
12
|
+
# @param [Worksheet] sheet The sheet containing the table data.
|
13
|
+
# @option options [Cell, String] name
|
14
|
+
# @option options [TableStyle] style
|
15
|
+
def initialize(ref, sheet, options={})
|
16
|
+
@ref = ref
|
17
|
+
@sheet = sheet
|
18
|
+
@style = nil
|
19
|
+
@sheet.workbook.tables << self
|
20
|
+
@table_style_info = TableStyleInfo.new(options[:style_info]) if options[:style_info]
|
21
|
+
@name = "Table#{index+1}"
|
22
|
+
parse_options options
|
23
|
+
yield self if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
# The reference to the table data
|
27
|
+
# @return [String]
|
28
|
+
attr_reader :ref
|
29
|
+
|
30
|
+
# The name of the table.
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :name
|
33
|
+
|
34
|
+
# The style for the table.
|
35
|
+
# @return [TableStyle]
|
36
|
+
attr_reader :style
|
37
|
+
|
38
|
+
# The index of this chart in the workbooks charts collection
|
39
|
+
# @return [Integer]
|
40
|
+
def index
|
41
|
+
@sheet.workbook.tables.index(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
# The part name for this table
|
45
|
+
# @return [String]
|
46
|
+
def pn
|
47
|
+
"#{TABLE_PN % (index+1)}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# The relationship id for this table.
|
51
|
+
# @see Relationship#Id
|
52
|
+
# @return [String]
|
53
|
+
def rId
|
54
|
+
@sheet.relationships.for(self).Id
|
55
|
+
end
|
56
|
+
|
57
|
+
# The name of the Table.
|
58
|
+
# @param [String, Cell] v
|
59
|
+
# @return [Title]
|
60
|
+
def name=(v)
|
61
|
+
DataTypeValidator.validate :table_name, [String], v
|
62
|
+
if v.is_a?(String)
|
63
|
+
@name = v
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# TableStyleInfo for the table.
|
68
|
+
# initialization can be fed via the :style_info option
|
69
|
+
def table_style_info
|
70
|
+
@table_style_info ||= TableStyleInfo.new
|
71
|
+
end
|
72
|
+
|
73
|
+
# Serializes the object
|
74
|
+
# @param [String] str
|
75
|
+
# @return [String]
|
76
|
+
def to_xml_string(str = '')
|
77
|
+
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
78
|
+
str << ('<table xmlns="' << XML_NS << '" id="' << (index+1).to_s << '" name="' << @name << '" displayName="' << @name.gsub(/\s/,'_') << '" ')
|
79
|
+
str << ('ref="' << @ref << '" totalsRowShown="0">')
|
80
|
+
str << ('<autoFilter ref="' << @ref << '"/>')
|
81
|
+
str << ('<tableColumns count="' << header_cells.length.to_s << '">')
|
82
|
+
header_cells.each_with_index do |cell,index|
|
83
|
+
str << ('<tableColumn id ="' << (index+1).to_s << '" name="' << cell.value << '"/>')
|
84
|
+
end
|
85
|
+
str << '</tableColumns>'
|
86
|
+
table_style_info.to_xml_string(str)
|
87
|
+
str << '</table>'
|
88
|
+
end
|
89
|
+
|
90
|
+
# The style for the table.
|
91
|
+
# TODO
|
92
|
+
# def style=(v) DataTypeValidator.validate "Table.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
# get the header cells (hackish)
|
97
|
+
def header_cells
|
98
|
+
header = @ref.gsub(/^(\w+?)(\d+)\:(\w+?)\d+$/, '\1\2:\3\2')
|
99
|
+
@sheet[header]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Axlsx
|
2
|
+
|
3
|
+
# The table style info class manages style attributes for defined tables in
|
4
|
+
# a worksheet
|
5
|
+
class TableStyleInfo
|
6
|
+
include Axlsx::OptionsParser
|
7
|
+
include Axlsx::SerializedAttributes
|
8
|
+
include Axlsx::Accessors
|
9
|
+
# creates a new TableStyleInfo instance
|
10
|
+
# @param [Hash] options
|
11
|
+
# @option [Boolean] show_first_column indicates if the first column should
|
12
|
+
# be shown
|
13
|
+
# @option [Boolean] show_last_column indicates if the last column should
|
14
|
+
# be shown
|
15
|
+
# @option [Boolean] show_column_stripes indicates if column stripes should
|
16
|
+
# be shown
|
17
|
+
# @option [Boolean] show_row_stripes indicates if row stripes should be shown
|
18
|
+
# @option [String] name The name of the style to apply to your table.
|
19
|
+
# Only predefined styles are currently supported.
|
20
|
+
# @see Annex G. (normative) Predefined SpreadsheetML Style Definitions in part 1 of the specification.
|
21
|
+
def initialize(options = {})
|
22
|
+
initialize_defaults
|
23
|
+
@name = 'TableStyleMedium9'
|
24
|
+
parse_options options
|
25
|
+
end
|
26
|
+
|
27
|
+
# boolean attributes for this object
|
28
|
+
boolean_attr_accessor :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes
|
29
|
+
serializable_attributes :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes,
|
30
|
+
:name
|
31
|
+
|
32
|
+
# Initialize all the values to false as Excel requires them to
|
33
|
+
# explicitly be disabled or all will show.
|
34
|
+
def initialize_defaults
|
35
|
+
%w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
|
36
|
+
self.send("#{attr}=", 0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# The name of the table style.
|
41
|
+
attr_accessor :name
|
42
|
+
|
43
|
+
# seralizes this object to an xml string
|
44
|
+
# @param [String] str the string to contact this objects serialization to.
|
45
|
+
def to_xml_string(str = '')
|
46
|
+
serialized_tag('tableStyleInfo', str)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Axlsx
|
2
|
+
|
3
|
+
# A simple, self serializing class for storing tables
|
4
|
+
class Tables < SimpleTypedList
|
5
|
+
|
6
|
+
# creates a new Tables object
|
7
|
+
def initialize(worksheet)
|
8
|
+
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
9
|
+
super Table
|
10
|
+
@worksheet = worksheet
|
11
|
+
end
|
12
|
+
|
13
|
+
# The worksheet that owns this collection of tables
|
14
|
+
# @return [Worksheet]
|
15
|
+
attr_reader :worksheet
|
16
|
+
|
17
|
+
# returns the relationships required by this collection
|
18
|
+
def relationships
|
19
|
+
return [] if empty?
|
20
|
+
map{ |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml_string(str = "")
|
24
|
+
return if empty?
|
25
|
+
str << "<tableParts count='#{size}'>"
|
26
|
+
each { |table| str << "<tablePart r:id='#{table.rId}'/>" }
|
27
|
+
str << '</tableParts>'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,798 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
|
4
|
+
# The Worksheet class represents a worksheet in the workbook.
|
5
|
+
class Worksheet
|
6
|
+
include Axlsx::OptionsParser
|
7
|
+
include Axlsx::SerializedAttributes
|
8
|
+
# definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count.
|
9
|
+
# This is used for autowidth calculations
|
10
|
+
THIN_CHARS = '^.acfijklrstxzFIJL()-'.freeze
|
11
|
+
|
12
|
+
# Creates a new worksheet.
|
13
|
+
# @note the recommended way to manage worksheets is Workbook#add_worksheet
|
14
|
+
# @see Workbook#add_worksheet
|
15
|
+
# @option options [String] name The name of this worksheet.
|
16
|
+
# @option options [Hash] page_margins A hash containing page margins for this worksheet. @see PageMargins
|
17
|
+
# @option options [Hash] print_options A hash containing print options for this worksheet. @see PrintOptions
|
18
|
+
# @option options [Hash] header_footer A hash containing header/footer options for this worksheet. @see HeaderFooter
|
19
|
+
# @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet.
|
20
|
+
def initialize(wb, options={})
|
21
|
+
self.workbook = wb
|
22
|
+
@sheet_protection = nil
|
23
|
+
initialize_page_options(options)
|
24
|
+
parse_options options
|
25
|
+
@workbook.worksheets << self
|
26
|
+
@sheet_id = index + 1
|
27
|
+
yield self if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
serializable_attributes :sheet_id, :name, :state
|
31
|
+
|
32
|
+
# Initalizes page margin, setup and print options
|
33
|
+
# @param [Hash] options Options passed in from the initializer
|
34
|
+
def initialize_page_options(options)
|
35
|
+
@page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
|
36
|
+
@page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
|
37
|
+
@print_options = PrintOptions.new options[:print_options] if options[:print_options]
|
38
|
+
@header_footer = HeaderFooter.new options[:header_footer] if options[:header_footer]
|
39
|
+
@row_breaks = RowBreaks.new
|
40
|
+
@col_breaks = ColBreaks.new
|
41
|
+
end
|
42
|
+
|
43
|
+
# The name of the worksheet
|
44
|
+
# @return [String]
|
45
|
+
def name
|
46
|
+
@name ||= "Sheet" + (index+1).to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
# Specifies the visible state of this sheet. Allowed states are
|
50
|
+
# :visible, :hidden or :very_hidden. The default value is :visible.
|
51
|
+
#
|
52
|
+
# Worksheets in the :hidden state can be shown using the sheet formatting properties in excel.
|
53
|
+
# :very_hidden sheets should be inaccessible to end users.
|
54
|
+
# @param [Symbol] sheet_state The visible state for this sheet.
|
55
|
+
def state=(sheet_state)
|
56
|
+
RestrictionValidator.validate :worksheet_state, [:visible, :hidden, :very_hidden], sheet_state
|
57
|
+
@state = sheet_state
|
58
|
+
end
|
59
|
+
|
60
|
+
# The visibility of this sheet
|
61
|
+
def state
|
62
|
+
@state ||= :visible
|
63
|
+
end
|
64
|
+
|
65
|
+
# The sheet calculation properties
|
66
|
+
# @return [SheetCalcPr]
|
67
|
+
def sheet_calc_pr
|
68
|
+
@sheet_calc_pr ||= SheetCalcPr.new
|
69
|
+
end
|
70
|
+
|
71
|
+
# The sheet protection object for this workbook
|
72
|
+
# @return [SheetProtection]
|
73
|
+
# @see SheetProtection
|
74
|
+
def sheet_protection
|
75
|
+
@sheet_protection ||= SheetProtection.new
|
76
|
+
yield @sheet_protection if block_given?
|
77
|
+
@sheet_protection
|
78
|
+
end
|
79
|
+
|
80
|
+
# The sheet view object for this worksheet
|
81
|
+
# @return [SheetView]
|
82
|
+
# @see [SheetView]
|
83
|
+
def sheet_view
|
84
|
+
@sheet_view ||= SheetView.new
|
85
|
+
yield @sheet_view if block_given?
|
86
|
+
@sheet_view
|
87
|
+
end
|
88
|
+
|
89
|
+
# The sheet format pr for this worksheet
|
90
|
+
# @return [SheetFormatPr]
|
91
|
+
# @see [SheetFormatPr]
|
92
|
+
def sheet_format_pr
|
93
|
+
@sheet_format_pr ||= SheetFormatPr.new
|
94
|
+
yield @sheet_format_pr if block_given?
|
95
|
+
@sheet_format_pr
|
96
|
+
end
|
97
|
+
|
98
|
+
# The workbook that owns this worksheet
|
99
|
+
# @return [Workbook]
|
100
|
+
attr_reader :workbook
|
101
|
+
|
102
|
+
# The tables in this worksheet
|
103
|
+
# @return [Array] of Table
|
104
|
+
def tables
|
105
|
+
@tables ||= Tables.new self
|
106
|
+
end
|
107
|
+
|
108
|
+
# The pivot tables in this worksheet
|
109
|
+
# @return [Array] of Table
|
110
|
+
def pivot_tables
|
111
|
+
@pivot_tables ||= PivotTables.new self
|
112
|
+
end
|
113
|
+
|
114
|
+
# A collection of column breaks added to this worksheet
|
115
|
+
# @note Please do not use this directly. Instead use
|
116
|
+
# add_page_break
|
117
|
+
# @see Worksheet#add_page_break
|
118
|
+
def col_breaks
|
119
|
+
@col_breaks ||= ColBreaks.new
|
120
|
+
end
|
121
|
+
|
122
|
+
# A collection of row breaks added to this worksheet
|
123
|
+
# @note Please do not use this directly. Instead use
|
124
|
+
# add_page_break
|
125
|
+
# @see Worksheet#add_page_break
|
126
|
+
def row_breaks
|
127
|
+
@row_breaks ||= RowBreaks.new
|
128
|
+
end
|
129
|
+
|
130
|
+
# A typed collection of hyperlinks associated with this worksheet
|
131
|
+
# @return [WorksheetHyperlinks]
|
132
|
+
def hyperlinks
|
133
|
+
@hyperlinks ||= WorksheetHyperlinks.new self
|
134
|
+
end
|
135
|
+
|
136
|
+
# The a shortcut to the worksheet_comments list of comments
|
137
|
+
# @return [Array|SimpleTypedList]
|
138
|
+
def comments
|
139
|
+
worksheet_comments.comments if worksheet_comments.has_comments?
|
140
|
+
end
|
141
|
+
|
142
|
+
# The rows in this worksheet
|
143
|
+
# @note The recommended way to manage rows is Worksheet#add_row
|
144
|
+
# @return [SimpleTypedList]
|
145
|
+
# @see Worksheet#add_row
|
146
|
+
def rows
|
147
|
+
@rows ||= SimpleTypedList.new Row
|
148
|
+
end
|
149
|
+
|
150
|
+
# returns the sheet data as columns
|
151
|
+
# If you pass a block, it will be evaluated whenever a row does not have a
|
152
|
+
# cell at a specific index. The block will be called with the row and column
|
153
|
+
# index in the missing cell was found.
|
154
|
+
# @example
|
155
|
+
# cols { |row_index, column_index| p "warn - row #{row_index} is does not have a cell at #{column_index}
|
156
|
+
def cols(&block)
|
157
|
+
@rows.transpose(&block)
|
158
|
+
end
|
159
|
+
|
160
|
+
# A range that excel will apply an auto-filter to "A1:B3"
|
161
|
+
# This will turn filtering on for the cells in the range.
|
162
|
+
# The first row is considered the header, while subsequent rows are considered to be data.
|
163
|
+
# @return String
|
164
|
+
def auto_filter
|
165
|
+
@auto_filter ||= AutoFilter.new self
|
166
|
+
end
|
167
|
+
|
168
|
+
# Indicates if the worksheet will be fit by witdh or height to a specific number of pages.
|
169
|
+
# To alter the width or height for page fitting, please use page_setup.fit_to_widht or page_setup.fit_to_height.
|
170
|
+
# If you want the worksheet to fit on more pages (e.g. 2x2), set {PageSetup#fit_to_width} and {PageSetup#fit_to_height} accordingly.
|
171
|
+
# @return Boolean
|
172
|
+
# @see #page_setup
|
173
|
+
def fit_to_page?
|
174
|
+
return false unless self.instance_values.keys.include?('page_setup')
|
175
|
+
page_setup.fit_to_page?
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
# Column info for the sheet
|
180
|
+
# @return [SimpleTypedList]
|
181
|
+
def column_info
|
182
|
+
@column_info ||= Cols.new self
|
183
|
+
end
|
184
|
+
|
185
|
+
# Page margins for printing the worksheet.
|
186
|
+
# @example
|
187
|
+
# wb = Axlsx::Package.new.workbook
|
188
|
+
# # using options when creating the worksheet.
|
189
|
+
# ws = wb.add_worksheet :page_margins => {:left => 1.9, :header => 0.1}
|
190
|
+
#
|
191
|
+
# # use the set method of the page_margins object
|
192
|
+
# ws.page_margins.set(:bottom => 3, :footer => 0.7)
|
193
|
+
#
|
194
|
+
# # set page margins in a block
|
195
|
+
# ws.page_margins do |margins|
|
196
|
+
# margins.right = 6
|
197
|
+
# margins.top = 0.2
|
198
|
+
# end
|
199
|
+
# @see PageMargins#initialize
|
200
|
+
# @return [PageMargins]
|
201
|
+
def page_margins
|
202
|
+
@page_margins ||= PageMargins.new
|
203
|
+
yield @page_margins if block_given?
|
204
|
+
@page_margins
|
205
|
+
end
|
206
|
+
|
207
|
+
# Page setup settings for printing the worksheet.
|
208
|
+
# @example
|
209
|
+
# wb = Axlsx::Package.new.workbook
|
210
|
+
#
|
211
|
+
# # using options when creating the worksheet.
|
212
|
+
# ws = wb.add_worksheet :page_setup => {:fit_to_width => 2, :orientation => :landscape}
|
213
|
+
#
|
214
|
+
# # use the set method of the page_setup object
|
215
|
+
# ws.page_setup.set(:paper_width => "297mm", :paper_height => "210mm")
|
216
|
+
#
|
217
|
+
# # setup page in a block
|
218
|
+
# ws.page_setup do |page|
|
219
|
+
# page.scale = 80
|
220
|
+
# page.orientation = :portrait
|
221
|
+
# end
|
222
|
+
# @see PageSetup#initialize
|
223
|
+
# @return [PageSetup]
|
224
|
+
def page_setup
|
225
|
+
@page_setup ||= PageSetup.new
|
226
|
+
yield @page_setup if block_given?
|
227
|
+
@page_setup
|
228
|
+
end
|
229
|
+
|
230
|
+
# Options for printing the worksheet.
|
231
|
+
# @example
|
232
|
+
# wb = Axlsx::Package.new.workbook
|
233
|
+
# # using options when creating the worksheet.
|
234
|
+
# ws = wb.add_worksheet :print_options => {:grid_lines => true, :horizontal_centered => true}
|
235
|
+
#
|
236
|
+
# # use the set method of the page_margins object
|
237
|
+
# ws.print_options.set(:headings => true)
|
238
|
+
#
|
239
|
+
# # set page margins in a block
|
240
|
+
# ws.print_options do |options|
|
241
|
+
# options.horizontal_centered = true
|
242
|
+
# options.vertical_centered = true
|
243
|
+
# end
|
244
|
+
# @see PrintOptions#initialize
|
245
|
+
# @return [PrintOptions]
|
246
|
+
def print_options
|
247
|
+
@print_options ||= PrintOptions.new
|
248
|
+
yield @print_options if block_given?
|
249
|
+
@print_options
|
250
|
+
end
|
251
|
+
|
252
|
+
# Options for headers and footers.
|
253
|
+
# @example
|
254
|
+
# wb = Axlsx::Package.new.workbook
|
255
|
+
# # would generate something like: "file.xlsx : sheet_name 2 of 7 date with timestamp"
|
256
|
+
# header = {:different_odd_ => false, :odd_header => "&L&F : &A&C&Pof%N%R%D %T"}
|
257
|
+
# ws = wb.add_worksheet :header_footer => header
|
258
|
+
#
|
259
|
+
# @see HeaderFooter#initialize
|
260
|
+
# @return [HeaderFooter]
|
261
|
+
def header_footer
|
262
|
+
@header_footer ||= HeaderFooter.new
|
263
|
+
yield @header_footer if block_given?
|
264
|
+
@header_footer
|
265
|
+
end
|
266
|
+
|
267
|
+
# convinience method to access all cells in this worksheet
|
268
|
+
# @return [Array] cells
|
269
|
+
def cells
|
270
|
+
rows.flatten
|
271
|
+
end
|
272
|
+
|
273
|
+
# Creates merge information for this worksheet.
|
274
|
+
# Cells can be merged by calling the merge_cells method on a worksheet.
|
275
|
+
# @example This would merge the three cells C1..E1 #
|
276
|
+
# worksheet.merge_cells "C1:E1"
|
277
|
+
# # you can also provide an array of cells to be merged
|
278
|
+
# worksheet.merge_cells worksheet.rows.first.cells[(2..4)]
|
279
|
+
# #alternatively you can do it from a single cell
|
280
|
+
# worksheet["C1"].merge worksheet["E1"]
|
281
|
+
# @param [Array, string] cells
|
282
|
+
def merge_cells(cells)
|
283
|
+
merged_cells.add cells
|
284
|
+
end
|
285
|
+
|
286
|
+
# Adds a new protected cell range to the worksheet. Note that protected ranges are only in effect when sheet protection is enabled.
|
287
|
+
# @param [String|Array] cells The string reference for the cells to protect or an array of cells.
|
288
|
+
# @return [ProtectedRange]
|
289
|
+
# @note When using an array of cells, a contiguous range is created from the minimum top left to the maximum top bottom of the cells provided.
|
290
|
+
def protect_range(cells)
|
291
|
+
protected_ranges.add_range(cells)
|
292
|
+
end
|
293
|
+
|
294
|
+
# The dimensions of a worksheet. This is not actually a required element by the spec,
|
295
|
+
# but at least a few other document readers expect this for conversion
|
296
|
+
# @return [Dimension]
|
297
|
+
def dimension
|
298
|
+
@dimension ||= Dimension.new self
|
299
|
+
end
|
300
|
+
|
301
|
+
# The sheet properties for this workbook.
|
302
|
+
# Currently only pageSetUpPr -> fitToPage is implemented
|
303
|
+
# @return [SheetPr]
|
304
|
+
def sheet_pr
|
305
|
+
@sheet_pr ||= SheetPr.new self
|
306
|
+
end
|
307
|
+
|
308
|
+
# Indicates if gridlines should be shown in the sheet.
|
309
|
+
# This is true by default.
|
310
|
+
# @return [Boolean]
|
311
|
+
# @deprecated Use SheetView#show_grid_lines= instead.
|
312
|
+
def show_gridlines=(v)
|
313
|
+
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
|
314
|
+
Axlsx::validate_boolean v
|
315
|
+
sheet_view.show_grid_lines = v
|
316
|
+
end
|
317
|
+
|
318
|
+
# @see selected
|
319
|
+
# @return [Boolean]
|
320
|
+
# @deprecated Use SheetView#tab_selected= instead.
|
321
|
+
def selected=(v)
|
322
|
+
warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
|
323
|
+
Axlsx::validate_boolean v
|
324
|
+
sheet_view.tab_selected = v
|
325
|
+
end
|
326
|
+
|
327
|
+
# Indicates if the worksheet should show gridlines or not
|
328
|
+
# @return Boolean
|
329
|
+
# @deprecated Use SheetView#show_grid_lines instead.
|
330
|
+
def show_gridlines
|
331
|
+
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
|
332
|
+
sheet_view.show_grid_lines
|
333
|
+
end
|
334
|
+
|
335
|
+
# Indicates if the worksheet is selected in the workbook
|
336
|
+
# It is possible to have more than one worksheet selected, however it might cause issues
|
337
|
+
# in some older versions of excel when using copy and paste.
|
338
|
+
# @return Boolean
|
339
|
+
# @deprecated Use SheetView#tab_selected instead.
|
340
|
+
def selected
|
341
|
+
warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
|
342
|
+
sheet_view.tab_selected
|
343
|
+
end
|
344
|
+
|
345
|
+
# (see #fit_to_page)
|
346
|
+
# @return [Boolean]
|
347
|
+
def fit_to_page=(v)
|
348
|
+
warn('axlsx::DEPRECIATED: Worksheet#fit_to_page has been depreciated. This value will automatically be set for you when you use PageSetup#fit_to.')
|
349
|
+
fit_to_page?
|
350
|
+
end
|
351
|
+
|
352
|
+
# The name of the worksheet
|
353
|
+
# The name of a worksheet must be unique in the workbook, and must not exceed 31 characters
|
354
|
+
# @param [String] name
|
355
|
+
def name=(name)
|
356
|
+
validate_sheet_name name
|
357
|
+
@name=Axlsx::coder.encode(name)
|
358
|
+
end
|
359
|
+
|
360
|
+
# The auto filter range for the worksheet
|
361
|
+
# @param [String] v
|
362
|
+
# @see auto_filter
|
363
|
+
def auto_filter=(v)
|
364
|
+
DataTypeValidator.validate :worksheet_auto_filter, String, v
|
365
|
+
auto_filter.range = v
|
366
|
+
end
|
367
|
+
|
368
|
+
# Accessor for controlling whether leading and trailing spaces in cells are
|
369
|
+
# preserved or ignored. The default is to preserve spaces.
|
370
|
+
attr_accessor :preserve_spaces
|
371
|
+
|
372
|
+
# The part name of this worksheet
|
373
|
+
# @return [String]
|
374
|
+
def pn
|
375
|
+
"#{WORKSHEET_PN % (index+1)}"
|
376
|
+
end
|
377
|
+
|
378
|
+
# The relationship part name of this worksheet
|
379
|
+
# @return [String]
|
380
|
+
def rels_pn
|
381
|
+
"#{WORKSHEET_RELS_PN % (index+1)}"
|
382
|
+
end
|
383
|
+
|
384
|
+
# The relationship id of this worksheet.
|
385
|
+
# @return [String]
|
386
|
+
# @see Relationship#Id
|
387
|
+
def rId
|
388
|
+
@workbook.relationships.for(self).Id
|
389
|
+
end
|
390
|
+
|
391
|
+
# The index of this worksheet in the owning Workbook's worksheets list.
|
392
|
+
# @return [Integer]
|
393
|
+
def index
|
394
|
+
@workbook.worksheets.index(self)
|
395
|
+
end
|
396
|
+
|
397
|
+
# The drawing associated with this worksheet.
|
398
|
+
# @note the recommended way to work with drawings and charts is Worksheet#add_chart
|
399
|
+
# @return [Drawing]
|
400
|
+
# @see Worksheet#add_chart
|
401
|
+
def drawing
|
402
|
+
worksheet_drawing.drawing
|
403
|
+
end
|
404
|
+
|
405
|
+
# Adds a row to the worksheet and updates auto fit data.
|
406
|
+
# @example - put a vanilla row in your spreadsheet
|
407
|
+
# ws.add_row [1, 'fish on my pl', '8']
|
408
|
+
#
|
409
|
+
# @example - specify a fixed width for a column in your spreadsheet
|
410
|
+
# # The first column will ignore the content of this cell when calculating column autowidth.
|
411
|
+
# # The second column will include this text in calculating the columns autowidth
|
412
|
+
# # The third cell will set a fixed with of 80 for the column.
|
413
|
+
# # If you need to un-fix a column width, use :auto. That will recalculate the column width based on all content in the column
|
414
|
+
#
|
415
|
+
# ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :widths=>[:ignore, :auto, 80]
|
416
|
+
#
|
417
|
+
# @example - specify a fixed height for a row
|
418
|
+
# ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :height => 40
|
419
|
+
#
|
420
|
+
# @example - create and use a style for all cells in the row
|
421
|
+
# blue = ws.styles.add_style :color => "#00FF00"
|
422
|
+
# ws.add_row [1, 2, 3], :style=>blue
|
423
|
+
#
|
424
|
+
# @example - only style some cells
|
425
|
+
# blue = ws.styles.add_style :color => "#00FF00"
|
426
|
+
# red = ws.styles.add_style :color => "#FF0000"
|
427
|
+
# big = ws.styles.add_style :sz => 40
|
428
|
+
# ws.add_row ["red fish", "blue fish", "one fish", "two fish"], :style=>[red, blue, nil, big] # the last nil is optional
|
429
|
+
#
|
430
|
+
#
|
431
|
+
# @example - force the second cell to be a float value
|
432
|
+
# ws.add_row [3, 4, 5], :types => [nil, :float]
|
433
|
+
#
|
434
|
+
# @example - use << alias
|
435
|
+
# ws << [3, 4, 5], :types => [nil, :float]
|
436
|
+
#
|
437
|
+
# @see Worksheet#column_widths
|
438
|
+
# @return [Row]
|
439
|
+
# @option options [Array] values
|
440
|
+
# @option options [Array, Symbol] types
|
441
|
+
# @option options [Array, Integer] style
|
442
|
+
# @option options [Array] widths each member of the widths array will affect how auto_fit behavies.
|
443
|
+
# @option options [Float] height the row's height (in points)
|
444
|
+
def add_row(values=[], options={})
|
445
|
+
row = Row.new(self, values, options)
|
446
|
+
update_column_info row, options.delete(:widths)
|
447
|
+
yield row if block_given?
|
448
|
+
row
|
449
|
+
end
|
450
|
+
|
451
|
+
alias :<< :add_row
|
452
|
+
|
453
|
+
# Add conditional formatting to this worksheet.
|
454
|
+
#
|
455
|
+
# @param [String] cells The range to apply the formatting to
|
456
|
+
# @param [Array|Hash] rules An array of hashes (or just one) to create Conditional formatting rules from.
|
457
|
+
# @example This would format column A whenever it is FALSE.
|
458
|
+
# # for a longer example, see examples/example_conditional_formatting.rb (link below)
|
459
|
+
# worksheet.add_conditional_formatting( "A1:A1048576", { :type => :cellIs, :operator => :equal, :formula => "FALSE", :dxfId => 1, :priority => 1 }
|
460
|
+
#
|
461
|
+
# @see ConditionalFormattingRule#initialize
|
462
|
+
# @see file:examples/example_conditional_formatting.rb
|
463
|
+
def add_conditional_formatting(cells, rules)
|
464
|
+
cf = ConditionalFormatting.new( :sqref => cells )
|
465
|
+
cf.add_rules rules
|
466
|
+
conditional_formattings << cf
|
467
|
+
conditional_formattings
|
468
|
+
end
|
469
|
+
|
470
|
+
# Add data validation to this worksheet.
|
471
|
+
#
|
472
|
+
# @param [String] cells The cells the validation will apply to.
|
473
|
+
# @param [hash] data_validation options defining the validation to apply.
|
474
|
+
# @see examples/data_validation.rb for an example
|
475
|
+
def add_data_validation(cells, data_validation)
|
476
|
+
dv = DataValidation.new(data_validation)
|
477
|
+
dv.sqref = cells
|
478
|
+
data_validations << dv
|
479
|
+
end
|
480
|
+
|
481
|
+
# Adds a new hyperlink to the worksheet
|
482
|
+
# @param [Hash] options for the hyperlink
|
483
|
+
# @see WorksheetHyperlink for a list of options
|
484
|
+
# @return [WorksheetHyperlink]
|
485
|
+
def add_hyperlink(options={})
|
486
|
+
hyperlinks.add(options)
|
487
|
+
end
|
488
|
+
|
489
|
+
# Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details.
|
490
|
+
# @param [Class] chart_type
|
491
|
+
# @option options [Array] start_at
|
492
|
+
# @option options [Array] end_at
|
493
|
+
# @option options [Cell, String] title
|
494
|
+
# @option options [Boolean] show_legend
|
495
|
+
# @option options [Integer] style
|
496
|
+
# @note each chart type also specifies additional options
|
497
|
+
# @see Chart
|
498
|
+
# @see Pie3DChart
|
499
|
+
# @see Bar3DChart
|
500
|
+
# @see Line3DChart
|
501
|
+
# @see README for examples
|
502
|
+
def add_chart(chart_type, options={})
|
503
|
+
chart = worksheet_drawing.add_chart(chart_type, options)
|
504
|
+
yield chart if block_given?
|
505
|
+
chart
|
506
|
+
end
|
507
|
+
|
508
|
+
# needs documentation
|
509
|
+
def add_table(ref, options={})
|
510
|
+
tables << Table.new(ref, self, options)
|
511
|
+
yield tables.last if block_given?
|
512
|
+
tables.last
|
513
|
+
end
|
514
|
+
|
515
|
+
def add_pivot_table(ref, range, options={})
|
516
|
+
pivot_tables << PivotTable.new(ref, range, self, options)
|
517
|
+
yield pivot_tables.last if block_given?
|
518
|
+
pivot_tables.last
|
519
|
+
end
|
520
|
+
|
521
|
+
# Shortcut to worsksheet_comments#add_comment
|
522
|
+
def add_comment(options={})
|
523
|
+
worksheet_comments.add_comment(options)
|
524
|
+
end
|
525
|
+
|
526
|
+
# Adds a media item to the worksheets drawing
|
527
|
+
# @option [Hash] options options passed to drawing.add_image
|
528
|
+
def add_image(options={})
|
529
|
+
image = worksheet_drawing.add_image(options)
|
530
|
+
yield image if block_given?
|
531
|
+
image
|
532
|
+
end
|
533
|
+
|
534
|
+
# Adds a page break (row break) to the worksheet
|
535
|
+
# @param cell A Cell object or excel style string reference indicating where the break
|
536
|
+
# should be added to the sheet.
|
537
|
+
# @example
|
538
|
+
# ws.add_page_break("A4")
|
539
|
+
def add_page_break(cell)
|
540
|
+
DataTypeValidator.validate :worksheet_page_break, [String, Cell], cell
|
541
|
+
column_index, row_index = if cell.is_a?(String)
|
542
|
+
Axlsx.name_to_indices(cell)
|
543
|
+
else
|
544
|
+
cell.pos
|
545
|
+
end
|
546
|
+
if column_index > 0
|
547
|
+
col_breaks.add_break(:id => column_index)
|
548
|
+
end
|
549
|
+
row_breaks.add_break(:id => row_index)
|
550
|
+
end
|
551
|
+
|
552
|
+
# This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go.
|
553
|
+
# Note that you must call column_widths AFTER adding data, otherwise the width will not be set successfully.
|
554
|
+
# Setting a fixed column width to nil will revert the behaviour back to calculating the width for you on the next call to add_row.
|
555
|
+
# @example This would set the first and third column widhts but leave the second column in autofit state.
|
556
|
+
# ws.column_widths 7.2, nil, 3
|
557
|
+
# @note For updating only a single column it is probably easier to just set the width of the ws.column_info[col_index].width directly
|
558
|
+
# @param [Integer|Float|Fixnum|nil] widths
|
559
|
+
def column_widths(*widths)
|
560
|
+
widths.each_with_index do |value, index|
|
561
|
+
next if value == nil
|
562
|
+
Axlsx::validate_unsigned_numeric(value) unless value == nil
|
563
|
+
find_or_create_column_info(index).width = value
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
# Set the style for cells in a specific column
|
568
|
+
# @param [Integer] index the index of the column
|
569
|
+
# @param [Integer] style the cellXfs index
|
570
|
+
# @param [Hash] options
|
571
|
+
# @option [Integer] :row_offset only cells after this column will be updated.
|
572
|
+
# @note You can also specify the style for specific columns in the call to add_row by using an array for the :styles option
|
573
|
+
# @see Worksheet#add_row
|
574
|
+
# @see README.md for an example
|
575
|
+
def col_style(index, style, options={})
|
576
|
+
offset = options.delete(:row_offset) || 0
|
577
|
+
cells = @rows[(offset..-1)].map { |row| row[index] }.flatten.compact
|
578
|
+
cells.each { |cell| cell.style = style }
|
579
|
+
end
|
580
|
+
|
581
|
+
# Set the style for cells in a specific row
|
582
|
+
# @param [Integer] index or range of indexes in the table
|
583
|
+
# @param [Integer] style the cellXfs index
|
584
|
+
# @param [Hash] options the options used when applying the style
|
585
|
+
# @option [Integer] :col_offset only cells after this column will be updated.
|
586
|
+
# @note You can also specify the style in the add_row call
|
587
|
+
# @see Worksheet#add_row
|
588
|
+
# @see README.md for an example
|
589
|
+
def row_style(index, style, options={})
|
590
|
+
offset = options.delete(:col_offset) || 0
|
591
|
+
cells = cols[(offset..-1)].map { |column| column[index] }.flatten.compact
|
592
|
+
cells.each { |cell| cell.style = style }
|
593
|
+
end
|
594
|
+
|
595
|
+
# Returns a sheet node serialization for this sheet in the workbook.
|
596
|
+
def to_sheet_node_xml_string(str='')
|
597
|
+
add_autofilter_defined_name_to_workbook
|
598
|
+
str << '<sheet '
|
599
|
+
serialized_attributes str
|
600
|
+
str << ('r:id="' << rId << '"></sheet>')
|
601
|
+
end
|
602
|
+
|
603
|
+
# Serializes the worksheet object to an xml string
|
604
|
+
# This intentionally does not use nokogiri for performance reasons
|
605
|
+
# @return [String]
|
606
|
+
def to_xml_string str=''
|
607
|
+
add_autofilter_defined_name_to_workbook
|
608
|
+
auto_filter.apply if auto_filter.range
|
609
|
+
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
610
|
+
str << worksheet_node
|
611
|
+
serializable_parts.each do |item|
|
612
|
+
item.to_xml_string(str) if item
|
613
|
+
end
|
614
|
+
str << '</worksheet>'
|
615
|
+
end
|
616
|
+
|
617
|
+
# The worksheet relationships. This is managed automatically by the worksheet
|
618
|
+
# @return [Relationships]
|
619
|
+
def relationships
|
620
|
+
r = Relationships.new
|
621
|
+
r + [tables.relationships,
|
622
|
+
worksheet_comments.relationships,
|
623
|
+
hyperlinks.relationships,
|
624
|
+
worksheet_drawing.relationship,
|
625
|
+
pivot_tables.relationships].flatten.compact || []
|
626
|
+
r
|
627
|
+
end
|
628
|
+
|
629
|
+
# Returns the cell or cells defined using excel style A1:B3 references.
|
630
|
+
# @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber
|
631
|
+
# @return [Cell, Array]
|
632
|
+
def [] (cell_def)
|
633
|
+
return rows[cell_def] if cell_def.is_a?(Integer)
|
634
|
+
parts = cell_def.split(':').map{ |part| name_to_cell part }
|
635
|
+
if parts.size == 1
|
636
|
+
parts.first
|
637
|
+
else
|
638
|
+
range(*parts)
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
642
|
+
# returns the column and row index for a named based cell
|
643
|
+
# @param [String] name The cell or cell range to return. "A1" will return the first cell of the first row.
|
644
|
+
# @return [Cell]
|
645
|
+
def name_to_cell(name)
|
646
|
+
col_index, row_index = *Axlsx::name_to_indices(name)
|
647
|
+
r = rows[row_index]
|
648
|
+
r[col_index] if r
|
649
|
+
end
|
650
|
+
|
651
|
+
# shortcut method to access styles direclty from the worksheet
|
652
|
+
# This lets us do stuff like:
|
653
|
+
# @example
|
654
|
+
# p = Axlsx::Package.new
|
655
|
+
# p.workbook.add_worksheet(:name => 'foo') do |sheet|
|
656
|
+
# my_style = sheet.styles.add_style { :bg_color => "FF0000" }
|
657
|
+
# sheet.add_row ['Oh No!'], :styles => my_style
|
658
|
+
# end
|
659
|
+
# p.serialize 'foo.xlsx'
|
660
|
+
def styles
|
661
|
+
@styles ||= self.workbook.styles
|
662
|
+
end
|
663
|
+
|
664
|
+
# shortcut level to specify the outline level for a series of rows
|
665
|
+
# Oulining is what lets you add collapse and expand to a data set.
|
666
|
+
# @param [Integer] start_index The zero based index of the first row of outlining.
|
667
|
+
# @param [Integer] end_index The zero based index of the last row to be outlined
|
668
|
+
# @param [integer] level The level of outline to apply
|
669
|
+
# @param [Integer] collapsed The initial collapsed state of the outline group
|
670
|
+
def outline_level_rows(start_index, end_index, level = 1, collapsed = true)
|
671
|
+
outline rows, (start_index..end_index), level, collapsed
|
672
|
+
end
|
673
|
+
|
674
|
+
# shortcut level to specify the outline level for a series of columns
|
675
|
+
# Oulining is what lets you add collapse and expand to a data set.
|
676
|
+
# @param [Integer] start_index The zero based index of the first column of outlining.
|
677
|
+
# @param [Integer] end_index The zero based index of the last column to be outlined
|
678
|
+
# @param [integer] level The level of outline to apply
|
679
|
+
# @param [Integer] collapsed The initial collapsed state of the outline group
|
680
|
+
def outline_level_columns(start_index, end_index, level = 1, collapsed = true)
|
681
|
+
outline column_info, (start_index..end_index), level, collapsed
|
682
|
+
end
|
683
|
+
|
684
|
+
private
|
685
|
+
|
686
|
+
def xml_space
|
687
|
+
workbook.xml_space
|
688
|
+
end
|
689
|
+
|
690
|
+
def outline(collection, range, level = 1, collapsed = true)
|
691
|
+
range.each do |index|
|
692
|
+
unless (item = collection[index]).nil?
|
693
|
+
item.outline_level = level
|
694
|
+
item.hidden = collapsed
|
695
|
+
end
|
696
|
+
sheet_view.show_outline_symbols = true
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
def validate_sheet_name(name)
|
701
|
+
DataTypeValidator.validate :worksheet_name, String, name
|
702
|
+
raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.size > 31
|
703
|
+
raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
|
704
|
+
name = Axlsx::coder.encode(name)
|
705
|
+
sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }
|
706
|
+
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
|
707
|
+
end
|
708
|
+
|
709
|
+
def serializable_parts
|
710
|
+
[sheet_pr, dimension, sheet_view, sheet_format_pr, column_info,
|
711
|
+
sheet_data, sheet_calc_pr, @sheet_protection, protected_ranges,
|
712
|
+
auto_filter, merged_cells, conditional_formattings,
|
713
|
+
data_validations, hyperlinks, print_options, page_margins,
|
714
|
+
page_setup, header_footer, row_breaks, col_breaks, worksheet_drawing, worksheet_comments,
|
715
|
+
tables]
|
716
|
+
end
|
717
|
+
|
718
|
+
def range(*cell_def)
|
719
|
+
first, last = cell_def
|
720
|
+
cells = []
|
721
|
+
rows[(first.row.row_index..last.row.row_index)].each do |r|
|
722
|
+
r[(first.index..last.index)].each do |c|
|
723
|
+
cells << c
|
724
|
+
end
|
725
|
+
end
|
726
|
+
cells
|
727
|
+
end
|
728
|
+
|
729
|
+
# A collection of protected ranges in the worksheet
|
730
|
+
# @note The recommended way to manage protected ranges is with Worksheet#protect_range
|
731
|
+
# @see Worksheet#protect_range
|
732
|
+
# @return [SimpleTypedList] The protected ranges for this worksheet
|
733
|
+
def protected_ranges
|
734
|
+
@protected_ranges ||= ProtectedRanges.new self
|
735
|
+
# SimpleTypedList.new ProtectedRange
|
736
|
+
end
|
737
|
+
|
738
|
+
# conditional formattings
|
739
|
+
# @return [Array]
|
740
|
+
def conditional_formattings
|
741
|
+
@conditional_formattings ||= ConditionalFormattings.new self
|
742
|
+
end
|
743
|
+
|
744
|
+
# data validations array
|
745
|
+
# @return [Array]
|
746
|
+
def data_validations
|
747
|
+
@data_validations ||= DataValidations.new self
|
748
|
+
end
|
749
|
+
|
750
|
+
# merged cells array
|
751
|
+
# @return [Array]
|
752
|
+
def merged_cells
|
753
|
+
@merged_cells ||= MergedCells.new self
|
754
|
+
end
|
755
|
+
|
756
|
+
|
757
|
+
# Helper method for parsingout the root node for worksheet
|
758
|
+
# @return [String]
|
759
|
+
def worksheet_node
|
760
|
+
"<worksheet xmlns=\"#{XML_NS}\" xmlns:r=\"#{XML_NS_R}\" xml:space=\"#{xml_space}\">"
|
761
|
+
end
|
762
|
+
|
763
|
+
def sheet_data
|
764
|
+
@sheet_data ||= SheetData.new self
|
765
|
+
end
|
766
|
+
|
767
|
+
def worksheet_drawing
|
768
|
+
@worksheet_drawing ||= WorksheetDrawing.new self
|
769
|
+
end
|
770
|
+
|
771
|
+
# The comments associated with this worksheet
|
772
|
+
# @return [SimpleTypedList]
|
773
|
+
def worksheet_comments
|
774
|
+
@worksheet_comments ||= WorksheetComments.new self
|
775
|
+
end
|
776
|
+
|
777
|
+
def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
|
778
|
+
|
779
|
+
def update_column_info(cells, widths=nil)
|
780
|
+
cells.each_with_index do |cell, index|
|
781
|
+
width = widths ? widths[index] : nil
|
782
|
+
col = find_or_create_column_info(index)
|
783
|
+
next if width == :ignore
|
784
|
+
col.update_width(cell, width, workbook.use_autowidth)
|
785
|
+
end
|
786
|
+
end
|
787
|
+
|
788
|
+
def find_or_create_column_info(index)
|
789
|
+
column_info[index] ||= Col.new(index + 1, index + 1)
|
790
|
+
end
|
791
|
+
|
792
|
+
def add_autofilter_defined_name_to_workbook
|
793
|
+
return if !auto_filter.range
|
794
|
+
workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1
|
795
|
+
end
|
796
|
+
|
797
|
+
end
|
798
|
+
end
|