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,35 @@
|
|
1
|
+
module Axlsx
|
2
|
+
|
3
|
+
# The Break class stores the details for row and column page breaks.
|
4
|
+
# @see RowBreaks, ColBreaks
|
5
|
+
class Break
|
6
|
+
|
7
|
+
include Axlsx::OptionsParser
|
8
|
+
include Axlsx::Accessors
|
9
|
+
include Axlsx::SerializedAttributes
|
10
|
+
|
11
|
+
# Creates a new Break object
|
12
|
+
# @param options A hash of attribute options for this break.
|
13
|
+
# @option options [Integer] id Zero-based row or column Id of the page break. Breaks occur above the specified row and left of the specified column.
|
14
|
+
# @option options [Integer] min Zero-based index of start row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
|
15
|
+
# @option options [Integer] max Zero-based index of end row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
|
16
|
+
# @option options [Boolean] man Manual Break flag. 1 means the break is a manually inserted break.
|
17
|
+
# @option option [Boolean] pt Flag indicating that a PivotTable created this break.
|
18
|
+
def initialize(options={})
|
19
|
+
parse_options options
|
20
|
+
yield self if block_given?
|
21
|
+
end
|
22
|
+
|
23
|
+
unsigned_int_attr_accessor :id, :min, :max
|
24
|
+
|
25
|
+
boolean_attr_accessor :man, :pt
|
26
|
+
|
27
|
+
serializable_attributes :id, :min, :max, :man, :pt
|
28
|
+
|
29
|
+
# serializes the break to xml
|
30
|
+
def to_xml_string(str='')
|
31
|
+
serialized_tag('brk', str)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,475 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'cgi'
|
3
|
+
module Axlsx
|
4
|
+
# A cell in a worksheet.
|
5
|
+
# Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
|
6
|
+
# @note The recommended way to generate cells is via Worksheet#add_row
|
7
|
+
#
|
8
|
+
# @see Worksheet#add_row
|
9
|
+
class Cell
|
10
|
+
|
11
|
+
include Axlsx::OptionsParser
|
12
|
+
|
13
|
+
# @param [Row] row The row this cell belongs to.
|
14
|
+
# @param [Any] value The value associated with this cell.
|
15
|
+
# @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
|
16
|
+
# @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
|
17
|
+
# @option options [String] font_name
|
18
|
+
# @option options [Integer] charset
|
19
|
+
# @option options [String] family
|
20
|
+
# @option options [Boolean] b
|
21
|
+
# @option options [Boolean] i
|
22
|
+
# @option options [Boolean] strike
|
23
|
+
# @option options [Boolean] outline
|
24
|
+
# @option options [Boolean] shadow
|
25
|
+
# @option options [Boolean] condense
|
26
|
+
# @option options [Boolean] extend
|
27
|
+
# @option options [Boolean] u
|
28
|
+
# @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
|
29
|
+
# @option options [Integer] sz
|
30
|
+
# @option options [String] color an 8 letter rgb specification
|
31
|
+
# @option options [Number] formula_value The value to cache for a formula cell.
|
32
|
+
# @option options [Symbol] scheme must be one of :none, major, :minor
|
33
|
+
def initialize(row, value = nil, options = {})
|
34
|
+
@row = row
|
35
|
+
# Do not use instance vars if not needed to use less RAM
|
36
|
+
# And do not call parse_options on frequently used options
|
37
|
+
# to get less GC cycles
|
38
|
+
type = options.delete(:type) || cell_type_from_value(value)
|
39
|
+
self.type = type unless type == :string
|
40
|
+
|
41
|
+
|
42
|
+
val = options.delete(:style)
|
43
|
+
self.style = val unless val.nil? || val == 0
|
44
|
+
val = options.delete(:formula_value)
|
45
|
+
self.formula_value = val unless val.nil?
|
46
|
+
|
47
|
+
parse_options(options)
|
48
|
+
|
49
|
+
self.value = value
|
50
|
+
value.cell = self if contains_rich_text?
|
51
|
+
end
|
52
|
+
|
53
|
+
# this is the cached value for formula cells. If you want the values to render in iOS/Mac OSX preview
|
54
|
+
# you need to set this.
|
55
|
+
attr_accessor :formula_value
|
56
|
+
|
57
|
+
# An array of available inline styes.
|
58
|
+
# TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
|
59
|
+
# then move it out to a module so we can re-use in in other classes.
|
60
|
+
# needs to define bla=(v) and bla methods on the class that hook into a
|
61
|
+
# set_attr method that kicks the suplied validator and updates the instance_variable
|
62
|
+
# for the key
|
63
|
+
INLINE_STYLES = [:value, :type, :font_name, :charset,
|
64
|
+
:family, :b, :i, :strike, :outline,
|
65
|
+
:shadow, :condense, :extend, :u,
|
66
|
+
:vertAlign, :sz, :color, :scheme].freeze
|
67
|
+
|
68
|
+
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
|
69
|
+
:string, :boolean, :iso_8601].freeze
|
70
|
+
|
71
|
+
# The index of the cellXfs item to be applied to this cell.
|
72
|
+
# @return [Integer]
|
73
|
+
# @see Axlsx::Styles
|
74
|
+
def style
|
75
|
+
defined?(@style) ? @style : 0
|
76
|
+
end
|
77
|
+
|
78
|
+
# The row this cell belongs to.
|
79
|
+
# @return [Row]
|
80
|
+
attr_reader :row
|
81
|
+
|
82
|
+
# The cell's data type. Currently only six types are supported, :date, :time, :float, :integer, :string and :boolean.
|
83
|
+
# Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
|
84
|
+
# automatically determed.
|
85
|
+
# @see Cell#cell_type_from_value
|
86
|
+
# @return [Symbol] The type of data this cell's value is cast to.
|
87
|
+
# @raise [ArgumentExeption] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean]
|
88
|
+
# @note
|
89
|
+
# If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied.
|
90
|
+
# :string to :integer or :float, type conversions always return 0 or 0.0
|
91
|
+
# :string, :integer, or :float to :time conversions always return the original value as a string and set the cells type to :string.
|
92
|
+
# No support is currently implemented for parsing time strings.
|
93
|
+
def type
|
94
|
+
defined?(@type) ? @type : :string
|
95
|
+
end
|
96
|
+
|
97
|
+
# @see type
|
98
|
+
def type=(v)
|
99
|
+
RestrictionValidator.validate :cell_type, CELL_TYPES, v
|
100
|
+
@type = v
|
101
|
+
self.value = @value unless !defined?(@value) || @value.nil?
|
102
|
+
end
|
103
|
+
|
104
|
+
# The value of this cell.
|
105
|
+
# @return [String, Integer, Float, Time, Boolean] casted value based on cell's type attribute.
|
106
|
+
attr_reader :value
|
107
|
+
|
108
|
+
# @see value
|
109
|
+
def value=(v)
|
110
|
+
#TODO: consider doing value based type determination first?
|
111
|
+
@value = cast_value(v)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Indicates that the cell has one or more of the custom cell styles applied.
|
115
|
+
# @return [Boolean]
|
116
|
+
def is_text_run?
|
117
|
+
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
|
118
|
+
end
|
119
|
+
|
120
|
+
def contains_rich_text?
|
121
|
+
type == :richtext
|
122
|
+
end
|
123
|
+
|
124
|
+
# Indicates if the cell is good for shared string table
|
125
|
+
def plain_string?
|
126
|
+
type == :string && # String typed
|
127
|
+
!is_text_run? && # No inline styles
|
128
|
+
!@value.nil? && # Not nil
|
129
|
+
!@value.empty? && # Not empty
|
130
|
+
!@value.start_with?(?=) # Not a formula
|
131
|
+
end
|
132
|
+
|
133
|
+
# The inline font_name property for the cell
|
134
|
+
# @return [String]
|
135
|
+
attr_reader :font_name
|
136
|
+
# @see font_name
|
137
|
+
def font_name=(v) set_run_style :validate_string, :font_name, v; end
|
138
|
+
|
139
|
+
# The inline charset property for the cell
|
140
|
+
# As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
|
141
|
+
# 0  ANSI_CHARSET
|
142
|
+
# 1 DEFAULT_CHARSET
|
143
|
+
# 2 SYMBOL_CHARSET
|
144
|
+
# 77 MAC_CHARSET
|
145
|
+
# 128 SHIFTJIS_CHARSET
|
146
|
+
# 129  HANGUL_CHARSET
|
147
|
+
# 130  JOHAB_CHARSET
|
148
|
+
# 134  GB2312_CHARSET
|
149
|
+
# 136  CHINESEBIG5_CHARSET
|
150
|
+
# 161  GREEK_CHARSET
|
151
|
+
# 162  TURKISH_CHARSET
|
152
|
+
# 163  VIETNAMESE_CHARSET
|
153
|
+
# 177  HEBREW_CHARSET
|
154
|
+
# 178  ARABIC_CHARSET
|
155
|
+
# 186  BALTIC_CHARSET
|
156
|
+
# 204  RUSSIAN_CHARSET
|
157
|
+
# 222  THAI_CHARSET
|
158
|
+
# 238  EASTEUROPE_CHARSET
|
159
|
+
# 255  OEM_CHARSET
|
160
|
+
# @return [String]
|
161
|
+
attr_reader :charset
|
162
|
+
# @see charset
|
163
|
+
def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
|
164
|
+
|
165
|
+
# The inline family property for the cell
|
166
|
+
# @return [Integer]
|
167
|
+
# 1 Roman
|
168
|
+
# 2 Swiss
|
169
|
+
# 3 Modern
|
170
|
+
# 4 Script
|
171
|
+
# 5 Decorative
|
172
|
+
attr_reader :family
|
173
|
+
# @see family
|
174
|
+
def family=(v)
|
175
|
+
set_run_style :validate_family, :family, v.to_i
|
176
|
+
end
|
177
|
+
|
178
|
+
# The inline bold property for the cell
|
179
|
+
# @return [Boolean]
|
180
|
+
attr_reader :b
|
181
|
+
# @see b
|
182
|
+
def b=(v) set_run_style :validate_boolean, :b, v; end
|
183
|
+
|
184
|
+
# The inline italic property for the cell
|
185
|
+
# @return [Boolean]
|
186
|
+
attr_reader :i
|
187
|
+
# @see i
|
188
|
+
def i=(v) set_run_style :validate_boolean, :i, v; end
|
189
|
+
|
190
|
+
# The inline strike property for the cell
|
191
|
+
# @return [Boolean]
|
192
|
+
attr_reader :strike
|
193
|
+
# @see strike
|
194
|
+
def strike=(v) set_run_style :validate_boolean, :strike, v; end
|
195
|
+
|
196
|
+
# The inline outline property for the cell
|
197
|
+
# @return [Boolean]
|
198
|
+
attr_reader :outline
|
199
|
+
# @see outline
|
200
|
+
def outline=(v) set_run_style :validate_boolean, :outline, v; end
|
201
|
+
|
202
|
+
# The inline shadow property for the cell
|
203
|
+
# @return [Boolean]
|
204
|
+
attr_reader :shadow
|
205
|
+
# @see shadow
|
206
|
+
def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
|
207
|
+
|
208
|
+
# The inline condense property for the cell
|
209
|
+
# @return [Boolean]
|
210
|
+
attr_reader :condense
|
211
|
+
# @see condense
|
212
|
+
def condense=(v) set_run_style :validate_boolean, :condense, v; end
|
213
|
+
|
214
|
+
# The inline extend property for the cell
|
215
|
+
# @return [Boolean]
|
216
|
+
attr_reader :extend
|
217
|
+
# @see extend
|
218
|
+
def extend=(v) set_run_style :validate_boolean, :extend, v; end
|
219
|
+
|
220
|
+
# The inline underline property for the cell.
|
221
|
+
# It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
|
222
|
+
# @return [Boolean]
|
223
|
+
# @return [String]
|
224
|
+
# @note true is for backwards compatability and is reassigned to :single
|
225
|
+
attr_reader :u
|
226
|
+
# @see u
|
227
|
+
def u=(v)
|
228
|
+
v = :single if (v == true || v == 1 || v == :true || v == 'true')
|
229
|
+
set_run_style :validate_cell_u, :u, v
|
230
|
+
end
|
231
|
+
|
232
|
+
# The inline color property for the cell
|
233
|
+
# @return [Color]
|
234
|
+
attr_reader :color
|
235
|
+
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
|
236
|
+
def color=(v)
|
237
|
+
@color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
|
238
|
+
@is_text_run = true
|
239
|
+
end
|
240
|
+
|
241
|
+
# The inline sz property for the cell
|
242
|
+
# @return [Inteter]
|
243
|
+
attr_reader :sz
|
244
|
+
# @see sz
|
245
|
+
def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
|
246
|
+
|
247
|
+
# The inline vertical alignment property for the cell
|
248
|
+
# this must be one of [:baseline, :subscript, :superscript]
|
249
|
+
# @return [Symbol]
|
250
|
+
attr_reader :vertAlign
|
251
|
+
# @see vertAlign
|
252
|
+
def vertAlign=(v)
|
253
|
+
RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
|
254
|
+
set_run_style nil, :vertAlign, v
|
255
|
+
end
|
256
|
+
|
257
|
+
# The inline scheme property for the cell
|
258
|
+
# this must be one of [:none, major, minor]
|
259
|
+
# @return [Symbol]
|
260
|
+
attr_reader :scheme
|
261
|
+
# @see scheme
|
262
|
+
def scheme=(v)
|
263
|
+
RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
|
264
|
+
set_run_style nil, :scheme, v
|
265
|
+
end
|
266
|
+
|
267
|
+
# The Shared Strings Table index for this cell
|
268
|
+
# @return [Integer]
|
269
|
+
attr_reader :ssti
|
270
|
+
|
271
|
+
# @return [Integer] The index of the cell in the containing row.
|
272
|
+
def index
|
273
|
+
@row.index(self)
|
274
|
+
end
|
275
|
+
|
276
|
+
# @return [String] The alpha(column)numeric(row) reference for this sell.
|
277
|
+
# @example Relative Cell Reference
|
278
|
+
# ws.rows.first.cells.first.r #=> "A1"
|
279
|
+
def r
|
280
|
+
Axlsx::cell_r index, @row.row_index
|
281
|
+
end
|
282
|
+
|
283
|
+
# @return [String] The absolute alpha(column)numeric(row) reference for this sell.
|
284
|
+
# @example Absolute Cell Reference
|
285
|
+
# ws.rows.first.cells.first.r #=> "$A$1"
|
286
|
+
def r_abs
|
287
|
+
"$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}"
|
288
|
+
end
|
289
|
+
|
290
|
+
# @return [Integer] The cellXfs item index applied to this cell.
|
291
|
+
# @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
|
292
|
+
def style=(v)
|
293
|
+
Axlsx::validate_unsigned_int(v)
|
294
|
+
count = styles.cellXfs.size
|
295
|
+
raise ArgumentError, "Invalid cellXfs id" unless v < count
|
296
|
+
@style = v
|
297
|
+
end
|
298
|
+
|
299
|
+
# @return [Array] of x/y coordinates in the sheet for this cell.
|
300
|
+
def pos
|
301
|
+
[index, row.row_index]
|
302
|
+
end
|
303
|
+
|
304
|
+
# Merges all the cells in a range created between this cell and the cell or string name for a cell provided
|
305
|
+
# @see worksheet.merge_cells
|
306
|
+
# @param [Cell, String] target The last cell, or str ref for the cell in the merge range
|
307
|
+
def merge(target)
|
308
|
+
start, stop = if target.is_a?(String)
|
309
|
+
[self.r, target]
|
310
|
+
elsif(target.is_a?(Cell))
|
311
|
+
Axlsx.sort_cells([self, target]).map { |c| c.r }
|
312
|
+
end
|
313
|
+
self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
|
314
|
+
end
|
315
|
+
|
316
|
+
# Serializes the cell
|
317
|
+
# @param [Integer] r_index The row index for the cell
|
318
|
+
# @param [Integer] c_index The cell index in the row.
|
319
|
+
# @param [String] str The string index the cell content will be appended to. Defaults to empty string.
|
320
|
+
# @return [String] xml text for the cell
|
321
|
+
def to_xml_string(r_index, c_index, str = '')
|
322
|
+
CellSerializer.to_xml_string r_index, c_index, self, str
|
323
|
+
end
|
324
|
+
|
325
|
+
def is_formula?
|
326
|
+
type == :string && @value.to_s.start_with?(?=)
|
327
|
+
end
|
328
|
+
|
329
|
+
def is_array_formula?
|
330
|
+
type == :string && @value.to_s.start_with?('{=') && @value.to_s.end_with?('}')
|
331
|
+
end
|
332
|
+
|
333
|
+
# returns the absolute or relative string style reference for
|
334
|
+
# this cell.
|
335
|
+
# @param [Boolean] absolute -when false a relative reference will be
|
336
|
+
# returned.
|
337
|
+
# @return [String]
|
338
|
+
def reference(absolute=true)
|
339
|
+
absolute ? r_abs : r
|
340
|
+
end
|
341
|
+
|
342
|
+
# Creates a defined name in the workbook for this cell.
|
343
|
+
def name=(label)
|
344
|
+
row.worksheet.workbook.add_defined_name "#{row.worksheet.name}!#{r_abs}", name: label
|
345
|
+
@name = label
|
346
|
+
end
|
347
|
+
|
348
|
+
# returns the name of the cell
|
349
|
+
attr_reader :name
|
350
|
+
|
351
|
+
def autowidth
|
352
|
+
return if is_formula? || value.nil?
|
353
|
+
if contains_rich_text?
|
354
|
+
string_width('', font_size) + value.autowidth
|
355
|
+
elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
|
356
|
+
max_width = 0
|
357
|
+
value.to_s.split(/\r?\n/).each do |line|
|
358
|
+
width = string_width(line, font_size)
|
359
|
+
max_width = width if width > max_width
|
360
|
+
end
|
361
|
+
max_width
|
362
|
+
else
|
363
|
+
string_width(value, font_size)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
# Returns the sanatized value
|
368
|
+
# TODO find a better way to do this as it accounts for 30% of
|
369
|
+
# processing time in benchmarking...
|
370
|
+
def clean_value
|
371
|
+
if type == :string && !Axlsx::trust_input
|
372
|
+
Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
|
373
|
+
else
|
374
|
+
@value.to_s
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
private
|
379
|
+
|
380
|
+
def styles
|
381
|
+
row.worksheet.styles
|
382
|
+
end
|
383
|
+
|
384
|
+
# Returns the width of a string according to the current style
|
385
|
+
# This is still not perfect...
|
386
|
+
# - scaling is not linear as font sizes increase
|
387
|
+
def string_width(string, font_size)
|
388
|
+
font_scale = font_size / 10.0
|
389
|
+
(string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * (font_size/10.0)
|
390
|
+
end
|
391
|
+
|
392
|
+
# we scale the font size if bold style is applied to either the style font or
|
393
|
+
# the cell itself. Yes, it is a bit of a hack, but it is much better than using
|
394
|
+
# imagemagick and loading metrics for every character.
|
395
|
+
def font_size
|
396
|
+
return sz if sz
|
397
|
+
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
|
398
|
+
(font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
|
399
|
+
end
|
400
|
+
|
401
|
+
# Utility method for setting inline style attributes
|
402
|
+
def set_run_style(validator, attr, value)
|
403
|
+
return unless INLINE_STYLES.include?(attr.to_sym)
|
404
|
+
Axlsx.send(validator, value) unless validator.nil?
|
405
|
+
self.instance_variable_set :"@#{attr.to_s}", value
|
406
|
+
@is_text_run = true
|
407
|
+
end
|
408
|
+
|
409
|
+
# @see ssti
|
410
|
+
def ssti=(v)
|
411
|
+
Axlsx::validate_unsigned_int(v)
|
412
|
+
@ssti = v
|
413
|
+
end
|
414
|
+
|
415
|
+
# Determines the cell type based on the cell value.
|
416
|
+
# @note This is only used when a cell is created but no :type option is specified, the following rules apply:
|
417
|
+
# 1. If the value is an instance of Date, the type is set to :date
|
418
|
+
# 2. If the value is an instance of Time, the type is set to :time
|
419
|
+
# 3. If the value is an instance of TrueClass or FalseClass, the type is set to :boolean
|
420
|
+
# 4. :float and :integer types are determined by regular expression matching.
|
421
|
+
# 5. Anything that does not meet either of the above is determined to be :string.
|
422
|
+
# @return [Symbol] The determined type
|
423
|
+
def cell_type_from_value(v)
|
424
|
+
if v.is_a?(Date)
|
425
|
+
:date
|
426
|
+
elsif v.is_a?(Time)
|
427
|
+
:time
|
428
|
+
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
|
429
|
+
:boolean
|
430
|
+
elsif v.to_s =~ Axlsx::NUMERIC_REGEX
|
431
|
+
:integer
|
432
|
+
elsif v.to_s =~ Axlsx::FLOAT_REGEX
|
433
|
+
:float
|
434
|
+
elsif v.to_s =~ Axlsx::ISO_8601_REGEX
|
435
|
+
:iso_8601
|
436
|
+
elsif v.is_a? RichText
|
437
|
+
:richtext
|
438
|
+
else
|
439
|
+
:string
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
# Cast the value into this cells data type.
|
444
|
+
# @note
|
445
|
+
# About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
|
446
|
+
# @see Axlsx#date1904
|
447
|
+
def cast_value(v)
|
448
|
+
return v if v.is_a?(RichText) || v.nil?
|
449
|
+
case type
|
450
|
+
when :date
|
451
|
+
self.style = STYLE_DATE if self.style == 0
|
452
|
+
v
|
453
|
+
when :time
|
454
|
+
self.style = STYLE_DATE if self.style == 0
|
455
|
+
if !v.is_a?(Time) && v.respond_to?(:to_time)
|
456
|
+
v.to_time
|
457
|
+
else
|
458
|
+
v
|
459
|
+
end
|
460
|
+
when :float
|
461
|
+
v.to_f
|
462
|
+
when :integer
|
463
|
+
v.to_i
|
464
|
+
when :boolean
|
465
|
+
v ? 1 : 0
|
466
|
+
when :iso_8601
|
467
|
+
#consumer is responsible for ensuring the iso_8601 format when specifying this type
|
468
|
+
v
|
469
|
+
else
|
470
|
+
v.to_s
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
end
|
475
|
+
end
|