xlsx_composer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +76 -1
- data/lib/xlsx_composer/base.rb +2 -2
- data/lib/xlsx_composer/formatter.rb +1 -1
- data/lib/xlsx_composer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8a8b859d4ff8cf802aeb76d3e69f3393ed64663a7f849ed1b4a3792840b1970
|
|
4
|
+
data.tar.gz: 5ca4e3c5b0655a7c5afa666cb68a32396822606eddb18852478642a3565b24f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 697eac8a82072c7768bbf34d4d2aa4b28f9b2052e7cbdc1e88d419b100a7b34009e6530eaff8d2f37e27ce87f335aefa5f6e7bd89503d3a4d5aff97663458fb2
|
|
7
|
+
data.tar.gz: 72b044903424f8a6e5ec198d8966925c53612c92689b47d7d0dd4a576038bd66b27ccee4ecd0b1278ac9bdcb64db91e1c579a5f70eb18f85b9a673c27378bfae
|
data/CHANGELOG.md
CHANGED
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
- Cursor-based navigation helpers (`go_to`, `next_row`, `next_col`, etc.).
|
|
6
6
|
- Built-in reusable formats and per-class custom formats via `add_format`.
|
|
7
7
|
- Base composer class for worksheet templates.
|
|
8
|
+
|
|
9
|
+
## [0.1.1] - 2026-02-06
|
|
10
|
+
|
|
11
|
+
- Fixed a missing argument in the `bold_rotation_ninety` format definition.
|
|
12
|
+
- Exposed `composer_worksheet` reader on `XlsxComposer::Base` to allow safe composition of multiple services writing to the same worksheet.
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# XlsxComposer
|
|
2
2
|
|
|
3
|
-
**XlsxComposer** is a small Ruby library built on top of **WriteXLSX** that makes the creation of **complex and dynamic Excel spreadsheets** easier, more readable, and more maintainable.
|
|
3
|
+
**XlsxComposer** is a small Ruby library built on top of **WriteXLSX** that makes the creation of **complex and dynamic Excel spreadsheets** easier, more readable, and more maintainable through cursor-based navigation and composition.
|
|
4
4
|
|
|
5
5
|
It does **not** try to replace WriteXLSX.
|
|
6
6
|
Instead, it provides a higher-level abstraction focused on **navigation, composition, and formatting**, which are usually the hardest parts when spreadsheets stop being static.
|
|
@@ -118,6 +118,81 @@ end
|
|
|
118
118
|
The same template works regardless of how many years the contract has.
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
## Composing a worksheet using multiple templates
|
|
122
|
+
|
|
123
|
+
For more complex spreadsheets, it is common to split a single worksheet into
|
|
124
|
+
multiple logical sections, each one handled by a dedicated service or template.
|
|
125
|
+
|
|
126
|
+
XlsxComposer supports this by allowing multiple composers to write into the
|
|
127
|
+
same worksheet instance.
|
|
128
|
+
|
|
129
|
+
### Orchestrating a worksheet
|
|
130
|
+
|
|
131
|
+
The main composer is responsible for creating the worksheet and coordinating
|
|
132
|
+
the order in which sections are written.
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
class ReportWorksheet < XlsxComposer::Base
|
|
136
|
+
def initialize(workbook, report)
|
|
137
|
+
@report = report
|
|
138
|
+
super(workbook: workbook)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def worksheet_name
|
|
142
|
+
"Report"
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def run
|
|
146
|
+
write_header
|
|
147
|
+
write_summary
|
|
148
|
+
write_details
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
private
|
|
152
|
+
|
|
153
|
+
attr_reader :report
|
|
154
|
+
|
|
155
|
+
def write_header
|
|
156
|
+
HeaderSection.new(composer_worksheet, report).run
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def write_summary
|
|
160
|
+
SummarySection.new(composer_worksheet, report).run
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def write_details
|
|
164
|
+
DetailsSection.new(composer_worksheet, report).run
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Writing a section using an existing worksheet
|
|
170
|
+
|
|
171
|
+
Each section receives the same `XlsxComposer::Worksheet` instance and writes
|
|
172
|
+
to it using the same cursor-based API.
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
class HeaderSection < XlsxComposer::Base
|
|
176
|
+
def initialize(worksheet, report)
|
|
177
|
+
@report = report
|
|
178
|
+
super(worksheet: worksheet)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def run
|
|
182
|
+
go_to("1", "A")
|
|
183
|
+
write_row(["Report title"], bold)
|
|
184
|
+
|
|
185
|
+
next_row
|
|
186
|
+
write_row([report.title])
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
private
|
|
190
|
+
|
|
191
|
+
attr_reader :report
|
|
192
|
+
end
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
|
|
121
196
|
## Formatting
|
|
122
197
|
|
|
123
198
|
### Built-in formats
|
data/lib/xlsx_composer/base.rb
CHANGED
|
@@ -27,6 +27,8 @@ module XlsxComposer
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
attr_reader :composer_worksheet
|
|
31
|
+
|
|
30
32
|
def initialize(workbook: nil, worksheet: nil)
|
|
31
33
|
raise ArgumentError, "Provide workbook: or worksheet:" if workbook.nil? && worksheet.nil?
|
|
32
34
|
|
|
@@ -50,8 +52,6 @@ module XlsxComposer
|
|
|
50
52
|
|
|
51
53
|
private
|
|
52
54
|
|
|
53
|
-
attr_reader :composer_worksheet
|
|
54
|
-
|
|
55
55
|
def define_class_formats!
|
|
56
56
|
self.class.extra_formats.each do |name, spec|
|
|
57
57
|
args = spec.is_a?(Proc) ? instance_exec(&spec) : spec
|
|
@@ -10,7 +10,7 @@ module XlsxComposer
|
|
|
10
10
|
|
|
11
11
|
def bold_percent = format(:percent_bold, bold: 1, num_format: "0%")
|
|
12
12
|
|
|
13
|
-
def bold_rotation_ninety = format(bold: 1, rotation: 90, align: "vcenter")
|
|
13
|
+
def bold_rotation_ninety = format(:bold_rotation_ninety, bold: 1, rotation: 90, align: "vcenter")
|
|
14
14
|
|
|
15
15
|
def thousands_mark = format(:thousands_mark, num_format: "#,##0")
|
|
16
16
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xlsx_composer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hugo Passos
|
|
@@ -94,5 +94,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
94
|
requirements: []
|
|
95
95
|
rubygems_version: 4.0.3
|
|
96
96
|
specification_version: 4
|
|
97
|
-
summary: A composition layer on top of WriteXLSX for dynamic spreadsheets
|
|
97
|
+
summary: A cursor-based composition layer on top of WriteXLSX for dynamic Excel spreadsheets
|
|
98
98
|
test_files: []
|