README.md in spreadsheet_architect-4.2.0 vs README.md in spreadsheet_architect-5.0.0

- old
+ new

@@ -89,11 +89,11 @@ ```ruby Post.to_xlsx(instances: posts, spreadsheet_columns: :my_special_method) ``` -Alternatively, you can pass a Proc/lambda to the `spreadsheet_columns` option. For those purists that really dont want to define any extra `spreadsheet_columns` instance method on your model, this option can help you work with that methodology. +Alternatively, you can pass a Proc to the `spreadsheet_columns` option. For those purists that really dont want to define any extra `spreadsheet_columns` instance method on your model, this option can help you work with that methodology. ```ruby Post.to_xlsx(instances: posts, spreadsheet_columns: Proc.new{|instance| [ ['Title', :title], @@ -101,11 +101,12 @@ ['Author', (instance.author.name if instance.author)], ['Published?', (instance.published ? 'Yes' : 'No')], :published_at, # uses the method name as header title Einstance. 'Published At' ['# of Views', :number_of_views, :float], ['Rating', :rating], - ['Category/Tags', "#{instance.category.name} - #{instance.tags.collect(&:name).join(', ')}"] + ['Category/Tags', "#{instance.category.name} - #{instance.tags.collect(&:name).join(', ')}"], + ['URL', :url, (val.start_with?("http") ? :hyperlink : :string)], ] }) ``` # Sending & Saving Spreadsheets @@ -187,24 +188,20 @@ File.open('path/to/multi_sheet_file.xlsx', 'w+b') do |f| f.write axlsx_package.to_stream.read end ``` -See this file for more details: [test/unit/multi_sheet_test.rb](./test/unit/multi_sheet_test.rb) - ### ODS ```ruby ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data}) ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data}, ods_spreadsheet) File.open('path/to/multi_sheet_file.ods', 'w+b') do |f| - f.write ods_spreadsheet + f.write ods_spreadsheet.bytes end ``` -See this file for more details: [test/unit/multi_sheet_test.rb](./test/unit/multi_sheet_test.rb) - # Methods ## `to_xlsx(options={})` |Option|Default|Notes| @@ -219,15 +216,17 @@ |**column_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)| |**range_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)| |**conditional_row_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb). The if/unless proc will called with the following args: `row_index`, `row_data`| |**merges**<br>*Array*||Merge cells. [See this example for usage](./test/unit/kitchen_sink_test.rb). Warning merges cannot overlap eachother, if you attempt to do so Excel will claim your spreadsheet is corrupt and refuse to open your spreadsheet.| |**borders**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)| -|**column_types**<br>*Array*||Valid types for XLSX are :string, :integer, :float, :date, :time, :boolean, nil = auto determine.| +|**column_types**<br>*Array*||Valid types for XLSX are :string, :integer, :float, :date, :time, :boolean, :hyperlink, nil = auto determine. You may also pass a Proc which evaluates to any of the valid types, for example `->(cell_val){ cell_val.start_with?('http') ? :hyperlink : :string }`| |**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.| |**freeze_headers**<br>*Boolean*||Make all header rows frozen/fixed so they do not scroll.| -|**freeze**<br>*Hash*|`{rows: (1..4), columns: :all}`|Make all specified rows and columns frozen/fixed so they do not scroll.| +|**freeze**<br>*Hash*||Make all specified row and/or column frozen/fixed so they do not scroll. See [example usage](./test/unit/xlsx_freeze_test.rb)| |**skip_defaults**<br>*Boolean*|`false`|Removes defaults and default styles. Particularily useful for heavily customized spreadsheets where the default styles get in the way.| +|**escape_formulas**<br>*Boolean* or *Array*|`true`|Pass a single boolean to apply to all cells, or an array of booleans to control column-by-column. Advisable to be set true when involved with untrusted user input. See [an example of the underlying functionality](https://github.com/caxlsx/caxlsx/blob/master/examples/escape_formula_example.md). NOTE: Header row cells are not escaped. | +|**use_zero_based_row_index**<br>*Boolean*|`false`|Allows you to use zero-based row indexes when defining `range_styles`, `merges`, etc. Recomended to set this option for the whole project rather than per call. The original reason it was designed to be 1-based is because spreadsheet row numbers actually start with 1.| ## `to_axlsx_spreadsheet(options={}, axlsx_package_to_join=nil)` Same options as `to_xlsx` ## `to_ods(options={})` @@ -239,11 +238,11 @@ |**spreadsheet_columns**<br>*Proc/Symbol/String*| Use this option to override or define the spreadsheet columns. Normally, if this option is not specified and are using the instances option/ActiveRecord relation, it uses the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If neither of those and is an ActiveRecord model, then it will falls back to the models `self.column_names` | Cannot be used with the `:data` option.<br><br>If a Proc value is passed it will be evaluated on the instance object.<br><br>If a Symbol or String value is passed then it will search the instance for a method name that matches and call it. | |**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. | |**sheet_name**<br>*String*|`Sheet1`|| |**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options| |**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options| -|**column_types**<br>*Array*||Valid types for ODS are :string, :float, :date, :time, :boolean, nil = auto determine. Due to [RODF Issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string | +|**column_types**<br>*Array*||Valid types for ODS are :string, :float, :date, :time, :boolean, :hyperlink, nil = auto determine. Due to [RODF Issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string. You may also pass a Proc which evaluates to any of the valid types, for example `->(cell_val){ cell_val.start_with?('http') ? :hyperlink : :string }` | |**skip_defaults**<br>*Boolean*|`false`|Skip defaults and default styles. Particularily useful for heavily customized spreadsheets where the default styles get in the way.| ## `to_rodf_spreadsheet(options={}, spreadsheet_to_join=nil)` Same options as `to_ods` @@ -301,10 +300,11 @@ range_styles: [], conditional_row_styles: [], merges: [], borders: [], column_types: [], + use_zero_based_row_index: false, } ``` # Kitchen Sink Examples with Styling for XLSX and ODS See this example: [test/unit/kitchen_sink_test.rb](./test/unit/kitchen_sink_test.rb) @@ -327,9 +327,5 @@ At this time the spreadsheets generated by the test suite are manually inspected. After running the tests, the test output can be viewed at `tmp/#{alxsx_version}/*` # Credits Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger) - -For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com) - -[![Solid Foundation Web Development Logo](https://solidfoundationwebdev.com/logo-sm.png)](https://solidfoundationwebdev.com)