fast_xlsx 0.2.0-aarch64-linux → 0.4.0-aarch64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d720de6fee7241e2b2afa2bfe19fd3faa2ae5504c6c8f61bc6b33ac1327ac19b
4
- data.tar.gz: 37a01d4a4d4b2cfd3ba6a73bf7c07848f96376fa59fe1e0fe30ca97d3dc5a76a
3
+ metadata.gz: e7438a6f69df41153d85c357819655b1f6a22ee1dc73190fc32707b7e12b7a10
4
+ data.tar.gz: 5dffe1b70f6486c0bdb5d087b272e19c029f46f2b11c0fcf18babff2911f8557
5
5
  SHA512:
6
- metadata.gz: cf27645fa844dd17688ed73a2f2f4fa7aaa61dd3d374d2866614c36b31c71ee2a50307e605d3910820faee7fcea1a8cdbb14c7654204aca888907b29175c771d
7
- data.tar.gz: c02dd3ec356bc95e5c7c0eec55cd5cbe79abff5edbc30373b665ed783721f765dafdc152411cc3d815e3e163d61b65a2e840b9886f88e979dfa396ec23a03d6f
6
+ metadata.gz: 054da301b24d98a3b6e448e13f0c617fa27a4932b5f1d055b62b720b395fbeb2f98eba1ebb5fcb0e12b0a05bcbe1260dfdd042beb2567dda7c810c3f02b29fc6
7
+ data.tar.gz: 3c88b39a8a3f12aeb2b6012b74e175e5376708b70f57e259b753b2a1b005dd1885dd6150291012d2fd0475493366d1da12bf31391dd57f39204551fd078157c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-10-01
4
+
5
+ ### Changed
6
+
7
+ - Dates and times written without a format now get `yyyy-mm-dd` (`Date`) or `yyyy-mm-dd hh:mm:ss` (`Time`, `DateTime`) instead of showing as serial numbers. A cell's own format, its table column's and `column_format` still win. Applying the format makes writing date-heavy data about 15% slower, the same as passing a date format yourself.
8
+
9
+ ## [0.3.0] - 2026-10-01
10
+
11
+ ### Changed
12
+
13
+ - `to_xlsx` and `save` release Ruby's global lock while building and compressing the file, so other threads (e.g. in Puma or Sidekiq) keep running. An interrupt (Ctrl-C, `Timeout`, `Thread#raise`) takes effect once the save finishes.
14
+ - Saving is 20-30% faster: files are compressed with zlib-rs instead of C zlib (which also drops the `libz-sys` dependency). Adding rows is about 15% faster from building with link-time optimisation.
15
+
16
+ ### Added
17
+
18
+ - `write`, `write_comment`, `insert_image`, `insert_chart` and `freeze_panes` also take a cell reference such as `"B2"`. `write` is now native, which makes it about 15% faster.
19
+ - `Worksheet#zoom`, `#tab_color`, `#hide_gridlines`, `#activate`, `#hide`, and `#page_setup` (orientation, paper size, fit to pages, rows/columns repeated on every page, print area, printed gridlines).
20
+
21
+ ### Fixed
22
+
23
+ - A `merge_range` that overlaps an earlier merge raises before writing anything; before, it also blanked the earlier merge's value.
24
+
3
25
  ## [0.2.0] - 2026-10-01
4
26
 
5
27
  ### Added
data/README.md CHANGED
@@ -18,6 +18,7 @@ ws = wb.add_worksheet("Report") # later: wb.worksheet("Report")
18
18
  ws << ["id", "name", "created_at"] # append a row
19
19
  ws.concat(records.map { |r| [r.id, r.name, r.created_at] }) # append many rows in one call
20
20
  ws.write(0, 5, 42) # write a single cell (row, col, value)
21
+ ws.write("F1", 42) # or by its Excel reference
21
22
 
22
23
  wb.properties(title: "Q3 report", author: "Zac", keywords: "Confidential") # File > Info in Excel
23
24
  wb.save("report.xlsx") # or wb.to_xlsx => binary String
@@ -81,6 +82,8 @@ ws.write(1, 2, Date.today, date) # format one cell
81
82
 
82
83
  Per-side borders override `border`. Unknown options and invalid values raise `ArgumentError`.
83
84
 
85
+ Dates and times written without a format get `yyyy-mm-dd` or `yyyy-mm-dd hh:mm:ss`; a table column's format or `column_format` wins over that. A format you pass replaces it, so give date cells one with a `num_format` (e.g. `Format.new(bold: true, num_format: "yyyy-mm-dd")`), or Excel shows the serial number.
86
+
84
87
  ### Columns and filters
85
88
 
86
89
  ```ruby
@@ -91,6 +94,22 @@ ws.autofit # size other columns to the data written so fa
91
94
  ws.autofilter("A1:D101") # filter buttons on A1:D101
92
95
  ```
93
96
 
97
+ ### Sheet view and printing
98
+
99
+ ```ruby
100
+ ws.zoom(150) # 10..400 percent
101
+ ws.tab_color("#C00000")
102
+ ws.hide_gridlines
103
+ ws.activate # Excel opens on this sheet (un-hides it if hidden)
104
+ other.hide # the sheet Excel opens on can't be hidden: activate another one first
105
+
106
+ ws.page_setup(landscape: true, paper: :a4, # or :letter, :legal, :tabloid, :a3, :a5, Excel's paper number, 0 = printer default
107
+ fit_width: 1, # 1 page wide, as many pages tall as needed
108
+ repeat_rows: 0, # print the header row on every page (an index or a Range)
109
+ print_area: "A1:D100", # any cell range style
110
+ gridlines: true) # print the gridlines
111
+ ```
112
+
94
113
  ### Cell ranges
95
114
 
96
115
  `autofilter`, `merge_range`, `conditional_format`, `data_validation` and `add_table` take a range in any of these styles:
@@ -102,6 +121,8 @@ ws.autofilter(0..100, 0..3) # rows and columns, each an Integer or a Range
102
121
  ws.merge_range(0, 0..3, "Q3 report", title) # row 1, columns A–D
103
122
  ```
104
123
 
124
+ Methods that take one cell (`write`, `write_comment`, `insert_image`, `insert_chart`, `freeze_panes`) take `(row, col)` or a reference like `"B2"`.
125
+
105
126
  `autofit` only sees rows still in memory, so in `:constant` / `:low` memory mode it ignores rows already written to disk; set widths with `column_width` instead.
106
127
 
107
128
  ### Layout
@@ -231,8 +252,8 @@ Values are mapped by type:
231
252
  |---|---|
232
253
  | `Integer`, `Float`, any `Numeric` | number |
233
254
  | `String` | string |
234
- | `Time` | number (Excel serial date, local time) |
235
- | `Date`, `DateTime` | number (Excel serial date, own offset) |
255
+ | `Time`, `DateTime` | date and time (`yyyy-mm-dd hh:mm:ss` unless formatted), in its own offset |
256
+ | `Date` | date (`yyyy-mm-dd` unless formatted) |
236
257
  | `FastXlsx::Formula.new("SUM(A1:A9)")` | formula |
237
258
  | `FastXlsx::URL.new("https://…")`, `URL.new(url, text: "Title")` | hyperlink (optionally showing other text) |
238
259
  | `FastXlsx::RichString.new(["Total: ", bold], "1,234")` | text with a format per segment |
@@ -254,17 +275,17 @@ Apple Silicon, Ruby 4.0.5. Each library uses its own idiomatic row-append API; x
254
275
 
255
276
  | Library | Time | vs fastest | Ruby objects allocated |
256
277
  |---|---:|---:|---:|
257
- | **fast_xlsx** (`memory: :constant`) | **92 ms** | 1.0x | 7 |
258
- | **fast_xlsx** (`memory: :low`) | **101 ms** | 1.1x | 7 |
259
- | **fast_xlsx** | **102 ms** | 1.1x | 10 |
260
- | [xlsxtream](https://github.com/felixbuenemann/xlsxtream) 3.1 | 181 ms | 2.0x | 561,728 |
261
- | [fast_excel](https://github.com/Paxa/fast_excel) 0.5 (constant_memory) | 202 ms | 2.2x | 20,079 |
262
- | [fast_excel](https://github.com/Paxa/fast_excel) 0.5 | 240 ms | 2.6x | 320,076 |
263
- | [write_xlsx](https://github.com/cxn03651/write_xlsx) 1.15 | 610 ms | 6.7x | 1,483,899 |
264
- | [caxlsx](https://github.com/caxlsx/caxlsx) 4.5 | 678 ms | 7.4x | 745,122 |
265
- | [rubyXL](https://github.com/weshatheleopard/rubyXL) 3.4 | 2624 ms | 28.6x | 8,700,448 |
266
-
267
- All outputs are 702–750 KB.
278
+ | **fast_xlsx** (`memory: :constant`) | **77 ms** | 1.0x | 7 |
279
+ | **fast_xlsx** (`memory: :low`) | **86 ms** | 1.1x | 7 |
280
+ | **fast_xlsx** | **89 ms** | 1.1x | 10 |
281
+ | [xlsxtream](https://github.com/felixbuenemann/xlsxtream) 3.1 | 183 ms | 2.4x | 561,728 |
282
+ | [fast_excel](https://github.com/Paxa/fast_excel) 0.5 (constant_memory) | 200 ms | 2.6x | 20,079 |
283
+ | [fast_excel](https://github.com/Paxa/fast_excel) 0.5 | 238 ms | 3.1x | 320,076 |
284
+ | [write_xlsx](https://github.com/cxn03651/write_xlsx) 1.15 | 608 ms | 7.8x | 1,483,899 |
285
+ | [caxlsx](https://github.com/caxlsx/caxlsx) 4.5 | 689 ms | 8.9x | 745,122 |
286
+ | [rubyXL](https://github.com/weshatheleopard/rubyXL) 3.4 | 2755 ms | 35.6x | 8,700,448 |
287
+
288
+ All outputs are 689–750 KB.
268
289
 
269
290
  ### Memory
270
291
 
@@ -272,14 +293,18 @@ All outputs are 702–750 KB.
272
293
 
273
294
  | Library | Unique strings | Repeated strings |
274
295
  |---|---:|---:|
275
- | **fast_xlsx** (`memory: :constant`) | **+2 MB** | **+2 MB** |
276
- | **fast_xlsx** (`memory: :low`) | +62 MB | **+2 MB** |
277
- | **fast_xlsx** | +270 MB | +217 MB |
278
- | fast_excel 0.5 (constant_memory) | +10 MB | +10 MB |
279
- | fast_excel 0.5 | +183 MB | +151 MB |
296
+ | **fast_xlsx** (`memory: :constant`) | **+1 MB** | **+1 MB** |
297
+ | **fast_xlsx** (`memory: :low`) | +61 MB | **+1 MB** |
298
+ | **fast_xlsx** | +271 MB | +217 MB |
299
+ | fast_excel 0.5 (constant_memory) | +10 MB | +9 MB |
300
+ | fast_excel 0.5 | +182 MB | +151 MB |
280
301
 
281
302
  The `:standard` mode uses more memory than fast_excel's: when saving, rust_xlsxwriter assembles each worksheet's XML in memory (so several worksheets can be built in parallel) instead of streaming it from a temp file. Use `memory: :constant` or `memory: :low` for large exports.
282
303
 
304
+ ### Threads
305
+
306
+ Most of the time goes into saving (building the XML and compressing it). `to_xlsx` and `save` do that without holding Ruby's global lock, so in a threaded server (Puma, Sidekiq) other threads keep running while a large export is saved. An interrupt (Ctrl-C, `Timeout`, `Thread#raise`) takes effect once the save finishes.
307
+
283
308
  ### Reproduce
284
309
 
285
310
  ```bash
data/bench/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- fast_xlsx (0.2.0)
4
+ fast_xlsx (0.4.0)
5
5
  rb_sys (~> 0.9.130)
6
6
 
7
7
  GEM
@@ -77,7 +77,7 @@ DEPENDENCIES
77
77
  CHECKSUMS
78
78
  caxlsx (4.5.0) sha256=e3d98d859f148df05d5462086b5079b523f29c1766b569535f1d68629ce743ff
79
79
  fast_excel (0.5.0) sha256=59c418bdcf586a6030798d4e3a9f575742badaceaf7bb90f38eee5feb5bdc478
80
- fast_xlsx (0.2.0)
80
+ fast_xlsx (0.4.0)
81
81
  ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
82
82
  ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
83
83
  ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastXlsx
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/fast_xlsx.rb CHANGED
@@ -102,10 +102,15 @@ module FastXlsx
102
102
 
103
103
  # Cell writer for one sheet; create with Workbook#add_worksheet.
104
104
  class Worksheet
105
- def write(row, col, value, format = nil)
105
+ # write(row, col, value, format = nil) or write("B2", value, format = nil)
106
+ # is native: the (row, col) form runs once per cell, so it skips a Ruby
107
+ # wrapper. Other forms come here.
108
+ def _write_ref(*args)
109
+ row, col, (value, format) = CellRange.cell(args, 1..2)
106
110
  _write(row, col, value, format)
107
111
  self
108
112
  end
113
+ private :_write_ref
109
114
 
110
115
  def append(values, format: nil)
111
116
  _append(values, format)
@@ -158,14 +163,16 @@ module FastXlsx
158
163
  end
159
164
 
160
165
  # Adds a comment (Excel "note") to a cell.
161
- def write_comment(row, col, text, author: nil)
166
+ def write_comment(*args, author: nil)
167
+ row, col, (text, *) = CellRange.cell(args, 1..1)
162
168
  _write_comment(row, col, text, author)
163
169
  end
164
170
 
165
171
  # Inserts a PNG, JPEG, GIF or BMP image with its top-left corner in the
166
172
  # cell. source is a file path or an IO (anything responding to #read).
167
173
  # Options: scale: or width:/height: (pixels), x_offset:, y_offset: (pixels), alt_text:.
168
- def insert_image(row, col, source, **)
174
+ def insert_image(*args, **)
175
+ row, col, (source, *) = CellRange.cell(args, 1..1)
169
176
  bytes = source.respond_to?(:read) ? source.read : File.binread(source)
170
177
  _insert_image(row, col, bytes, { ** })
171
178
  end
@@ -173,7 +180,8 @@ module FastXlsx
173
180
  # Inserts a chart with its top-left corner in the cell. series is an Array
174
181
  # of { values:, categories:, name: } with Excel ranges such as
175
182
  # "Sheet1!$B$2:$B$13". Options: title:, x_axis:, y_axis:, width:, height:.
176
- def insert_chart(row, col, type:, series:, **)
183
+ def insert_chart(*cell, type:, series:, **)
184
+ row, col, = CellRange.cell(cell)
177
185
  _insert_chart(row, col, { type: type, series: series, ** })
178
186
  end
179
187
 
@@ -197,6 +205,18 @@ module FastXlsx
197
205
  margin ? margins(footer: margin) : self
198
206
  end
199
207
 
208
+ # Printing: landscape:, paper: (:letter, :legal, :tabloid, :a3, :a4, :a5 or
209
+ # Excel's paper number), fit_width:/fit_height: (pages; 0 or left out =
210
+ # as many as needed), repeat_rows:/repeat_columns: (an index or Range,
211
+ # printed on every page), print_area: (any cell range), gridlines:.
212
+ def page_setup(repeat_rows: nil, repeat_columns: nil, print_area: nil, **options)
213
+ options[:repeat_rows] = CellRange.bounds(repeat_rows) if repeat_rows
214
+ options[:repeat_columns] = CellRange.bounds(repeat_columns) if repeat_columns
215
+ options[:print_area] = CellRange.split(print_area.is_a?(Array) ? print_area : [print_area]).first if print_area
216
+ _page_setup(options)
217
+ self
218
+ end
219
+
200
220
  # Print margins in inches; margins not given keep their current value.
201
221
  def margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil)
202
222
  _margins(*[left, right, top, bottom, header, footer].map { |m| m || -1.0 })
@@ -214,6 +234,13 @@ module FastXlsx
214
234
  _group_columns(*CellRange.bounds(columns), collapsed)
215
235
  end
216
236
 
237
+ # Keeps the rows above and the columns left of the cell visible while
238
+ # scrolling: (1, 0) or "A2" freezes the first row.
239
+ def freeze_panes(*cell)
240
+ _freeze_panes(*CellRange.cell(cell).first(2))
241
+ self
242
+ end
243
+
217
244
  # Locks the sheet against editing. Cells whose format has locked: false
218
245
  # stay editable. allow: actions users may still take, any of :format_cells,
219
246
  # :format_columns, :format_rows, :insert_columns, :insert_rows,
@@ -236,6 +263,7 @@ module FastXlsx
236
263
  module CellRange
237
264
  REF = /\A\$?([A-Za-z]{1,3})\$?([1-9]\d*)\z/ # ASCII only: /i also matches the Kelvin sign
238
265
  FORMS = 'a range is (first_row, first_col, last_row, last_col), "A1:D10" or (rows, cols)'
266
+ CELL_FORMS = 'a cell is (row, col) or "B2"'
239
267
 
240
268
  module_function
241
269
 
@@ -243,12 +271,7 @@ module FastXlsx
243
271
  # Returns [[first_row, first_col, last_row, last_col], the args after it].
244
272
  def split(args, following = 0..0)
245
273
  range, rest = parse(args)
246
- unless following.cover?(rest.size)
247
- expected = following.minmax.uniq.join("..")
248
- raise ArgumentError, "wrong number of arguments after the cell range (given #{rest.size}, " \
249
- "expected #{expected}); #{FORMS}"
250
- end
251
-
274
+ check_following(rest, following, "cell range", FORMS)
252
275
  [range, rest]
253
276
  end
254
277
 
@@ -263,6 +286,30 @@ module FastXlsx
263
286
  end
264
287
  end
265
288
 
289
+ # (row, col) or a single-cell reference ("B2") off the front of args, as
290
+ # [row, col, the args after it].
291
+ def cell(args, following = 0..0)
292
+ row, col, *rest = args.first.is_a?(String) ? [*single_cell(args.first), *args.drop(1)] : args
293
+ raise ArgumentError, "expected a cell, got #{args.inspect}; #{CELL_FORMS}" if col.nil?
294
+
295
+ check_following(rest, following, "cell", CELL_FORMS)
296
+ [row, col, rest]
297
+ end
298
+
299
+ def single_cell(ref)
300
+ first_row, first_col, last_row, last_col = excel(ref)
301
+ return [first_row, first_col] if first_row == last_row && first_col == last_col
302
+
303
+ raise ArgumentError, "expected a single cell like \"B2\", got #{ref.inspect}"
304
+ end
305
+
306
+ def check_following(rest, following, what, forms)
307
+ return if following.cover?(rest.size)
308
+
309
+ raise ArgumentError, "wrong number of arguments after the #{what} " \
310
+ "(given #{rest.size}, expected #{following.minmax.uniq.join("..")}); #{forms}"
311
+ end
312
+
266
313
  def rows_and_cols(rows, cols)
267
314
  first_row, last_row = bounds(rows)
268
315
  first_col, last_col = bounds(cols)
data/sig/fast_xlsx.rbs CHANGED
@@ -57,6 +57,7 @@ module FastXlsx
57
57
 
58
58
  class Worksheet
59
59
  def write: (Integer row, Integer col, cell value, ?Format? format) -> self
60
+ | (String cell, cell value, ?Format? format) -> self
60
61
  def append: (Array[cell] values, ?format: Format? | Array[Format?]) -> self
61
62
  def <<: (Array[cell] row) -> self
62
63
  def concat: (Array[Array[cell]] rows) -> self
@@ -72,11 +73,20 @@ module FastXlsx
72
73
  | (String range) -> self
73
74
  | (indexes rows, indexes cols) -> self
74
75
  def freeze_panes: (Integer row, Integer col) -> self
76
+ | (String cell) -> self
75
77
  def row_height: (Integer row, Numeric height) -> self
76
78
  def page_breaks: (Array[Integer] rows) -> self
77
79
  def vertical_page_breaks: (Array[Integer] cols) -> self
78
80
  def page_header: (String text, ?margin: Numeric?) -> self
79
81
  def page_footer: (String text, ?margin: Numeric?) -> self
82
+ def activate: () -> self
83
+ def hide: () -> self
84
+ def zoom: (Integer percent) -> self
85
+ def tab_color: (String | Integer color) -> self
86
+ def hide_gridlines: () -> self
87
+ def page_setup: (?landscape: bool, ?paper: :letter | :legal | :tabloid | :a3 | :a4 | :a5 | Integer,
88
+ ?fit_width: Integer, ?fit_height: Integer, ?repeat_rows: indexes, ?repeat_columns: indexes,
89
+ ?print_area: String | Array[cell_range], ?gridlines: bool) -> self
80
90
  def margins: (?left: Numeric?, ?right: Numeric?, ?top: Numeric?, ?bottom: Numeric?,
81
91
  ?header: Numeric?, ?footer: Numeric?) -> self
82
92
  type protect_action = :format_cells | :format_columns | :format_rows | :insert_columns | :insert_rows
@@ -98,13 +108,19 @@ module FastXlsx
98
108
  ?input_title: String, ?input_message: String,
99
109
  ?error_title: String, ?error_message: String) -> self
100
110
  def write_comment: (Integer row, Integer col, String text, ?author: String?) -> self
111
+ | (String cell, String text, ?author: String?) -> self
101
112
  def insert_image: (Integer row, Integer col, String | _Reader source, ?scale: Numeric, ?width: Numeric, ?height: Numeric,
102
113
  ?x_offset: Integer, ?y_offset: Integer, ?alt_text: String) -> self
114
+ | (String cell, String | _Reader source, ?scale: Numeric, ?width: Numeric, ?height: Numeric,
115
+ ?x_offset: Integer, ?y_offset: Integer, ?alt_text: String) -> self
103
116
  type chart_series = { values: String, ?categories: String, ?name: String }
104
117
 
105
118
  def insert_chart: (Integer row, Integer col, type: Symbol, series: Array[chart_series],
106
119
  ?title: String, ?x_axis: String, ?y_axis: String,
107
120
  ?width: Integer, ?height: Integer) -> self
121
+ | (String cell, type: Symbol, series: Array[chart_series],
122
+ ?title: String, ?x_axis: String, ?y_axis: String,
123
+ ?width: Integer, ?height: Integer) -> self
108
124
  type table_column = String | { header: String, ?total: Symbol, ?total_label: String, ?format: Format }
109
125
 
110
126
  def add_table: (*cell_range range,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_xlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Zac