rubyXL Documentation

repository·master·Indexed 23 days ago

https://github.com/weshatheleopard/rubyxl

A Ruby gem for reading, writing, and modifying Excel (.xlsx) files using the Open XML format. It provides comprehensive tools for programmatic modifications to cells, styles, worksheet layouts, and workbook metadata, including support for font styling, cell borders, alignment, hyperlinks, and shared strings. The library also includes utilities for RGB/HLS color conversion, named range definition, and configuration of Chartsheet properties and data connections.

Tokens
6.8K
Snippets
4
Records
81
Agent score
78%

What's inside rubyXL

  1. How RelationshipSupport manages OOXML relationships

    master

    The RelationshipSupport module is a mixin used by OOXML objects to automate the loading and saving of _rels files. It works through several key mechanisms:

    1. Definition: Classes use define_relationship(klass, accessor) to register which class/accessor should be used when a specific relationship is encountered.
    2. Loading: When load_relationships(dir_path, base_file_name) is called, it loads the .rels file and iterates through the relationships. It then uses attach_relationship to map the loaded files back to the object.
    3. Attachment Logic:
      • If a specific accessor is defined, the related file is assigned to that accessor.
      • If the relationship is known but has no specific accessor, it is stored in generic_storage.
      • If the relationship type is unknown to the class, it is stored in generic_storage and a warning may be issued.
    4. Collection: The collect_related_objects method recursively gathers all related objects, including those in generic_storage and those managed by a relationship_container, to ensure the entire object tree is preserved during serialization.
  2. Include convenience methods for rubyXL

    master

    Starting with version 3.4.0, rubyXL separates the main data structure from convenience methods to reduce memory footprint. If you need access to specific features (like cell colors, fonts, or worksheet manipulations), you must explicitly require them.

    To include all convenience methods at once (higher RAM usage), use: require 'rubyXL/convenience_methods'.

    To include them individually for better memory efficiency, use:

    • require 'rubyXL/convenience_methods/cell'
    • require 'rubyXL/convenience_methods/color'
    • require 'rubyXL/convenience_methods/font'
    • require 'rubyXL/convenience_methods/workbook'
    • require 'rubyXL/convenience_methods/worksheet'
  3. Include convenience methods in rubyXL

    master

    Starting with version 3.4.0, the main data structure is separated from convenience methods to reduce memory footprint. If you need access to specific features (like cell colors, fonts, or worksheet manipulations), you must explicitly require them.

    To include all convenience methods at once (at the cost of higher RAM usage), use:

    require 'rubyXL/convenience_methods'

    Otherwise, you can include them individually:

    require 'rubyXL/convenience_methods/cell'
    require 'rubyXL/convenience_methods/color'
    require 'rubyXL/convenience_methods/font'
    require 'rubyXL/convenience_methods/workbook'
    require 'rubyXL/convenience_methods/worksheet'
  4. Modify cell alignment in a workbook

    master
    Use modify_alignment to change the alignment properties of a cell style. This method takes a style_index (the index of the existing XF/style) and a block. Inside the block, you can manipulate the RubyXL::Alignment object. The method automatically handles creating a new style (XF) and registering it in the workbook to ensure the changes are applied without affecting other cells sharing the old style.
  5. Configure Connection properties in rubyXL

    master
    The RubyXL::Connection class represents a data connection within a workbook. It allows you to define connection metadata such as the connection name, description, source files, and refresh behavior. It supports child nodes for specific connection types including OdbcOleDbProperties, OlapProperties, WebQueryProperties, TextImportSettings, and QueryParameters.