README.md in rxl-0.3.0 vs README.md in rxl-0.4.0
- old
+ new
@@ -130,12 +130,10 @@
}
```
### Write to file
-Any exception is swallowed and returned.
-
To write a file pass the filename and hash:
```ruby
Rxl.write_file('path/to/save.xlsx', hash_workbook)
```
@@ -150,43 +148,10 @@
}
}
}
```
-### Write to file as tables
-
-Any exception is swallowed and returned.
-
-To write a file as pass the filename and hash:
-
-```ruby
-Rxl.write_file_as_tables('path/to/save.xlsx', hash_tables, order)
-```
-
-The worsheets' top row will be populated with values specified in the `order` array. Those array items will also be used to extract the current row from the current hash.
-
-* use `nil` in the `order` array to leave blank columns (including blank header)
-* string or symbol keys can be used, so long as the key in order is the same as in the hashes
-
-The format of the excel hash_workbook has sheet names as keys and hashes of rows as values:
-
-```ruby
-order = %i[header_a header_b]
-hash_tables = {
- 'Sheet1' => [
- {
- header_a: 'some_value',
- header_b: 'other_value'
- },
- {
- header_a: 'some_value',
- header_b: 'other_value'
- }
- ]
-}
-```
-
#### Cell specification
All cells are written with the format set to general except those with a number format specified
Specify the number format according to https://support.office.com/en-us/article/number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68?ui=en-US&rs=en-US&ad=US
@@ -230,9 +195,79 @@
Other keys can be specified:
* v_align: :top, :centre or :bottom (default)
* h_align: :left (default), :centre or :right
TODO: add full description for hash_cell_to_rubyxl_cell and rubyxl_cell_to_hash_cell (and check they're as consistent as possible)
+
+### Write to file as tables
+
+To write a file as pass the filename and hash:
+
+```ruby
+Rxl.write_file_as_tables('path/to/save.xlsx', hash_tables, order)
+```
+
+The worksheets' top row will be populated with values specified in the `order` array. Those array items will also be used to extract the current row from the current hash.
+
+* use `nil` in the `order` array to leave blank columns (including blank header)
+* string or symbol keys can be used, so long as the key in order is the same as in the hashes
+
+The format of the excel hash_workbook has sheet names as keys and hashes of rows as values:
+
+```ruby
+order = %i[header_a header_b]
+hash_tables = {
+ 'Sheet1' => [
+ {
+ header_a: 'some_value',
+ header_b: 'other_value'
+ },
+ {
+ header_a: 'some_value',
+ header_b: 'other_value'
+ }
+ ]
+}
+```
+
+#### Formatting for tables
+
+Add formatting to tables by adding a `:formats` key to the top level hash.
+
+Inside the formatting hash add child hashes with keys for the relevant table.
+
+Within the table add hashes for each column with the key as the column letter and the value as a cell hash (excluding `:value`).
+
+Formatting for rows is not currently implemented.
+
+Additionally inside the table hash add a key `:headers` with a cell hash (excluding `:value`) to set formatting for the header row.
+
+```ruby
+order = %i[header_a header_b]
+hash_tables = {
+ formats: {
+ 'Sheet1' => {
+ headers: {
+ bold: true,
+ align: 'center'
+ },
+ 'B' => {
+ fill: 'feb302'
+ }
+ }
+ },
+ 'Sheet1' => [
+ {
+ 'col_1' => 'some_value',
+ 'col_2' => 'other_value'
+ },
+ {
+ 'col_1' => 'some_value',
+ 'col_2' => 'other_value'
+ }
+ ]
+}
+```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.