This Ruby script is designed to work with Excel documents, focusing on metaprogramming principles. The library allows users to interact with tables, assuming each table has a header row and an optional last row that can serve as a sum row.
- Retrieving Table Values
table.to_2d_array
- Accessing Rows
table.row(1)
- Implemented an each function to iterate over all cells in the table from left to right.
table.each { |row| puts row }
- Handling Merged Fields
Merged fields are automatically handled by the library. - Enhanced Syntax for Accessing and Setting Values
table['Name']
table['Name'][2]
table['Name', 2] = 'Value'
- Direct Column Access
table.Name
- Subtotal/Average Calculation
table.column.sum
table.column.avg
- Retrieving Row By Cell
table.Name.value
- Column Functions (map, select, reduce)
table.column.map { |x| x * 2}
table.column.select { |x| x > 2 }
table.column.reduce(0) { |sum, x| sum + x }
- Table Addition and Subtraction
table1 + table2
table1 - table2
- Ignoring Rows with Keywords
Rows containing "total" or "subtotal" are automatically ignored.