laravel-excel 0.3.0

Excel, CSV, ODS, HTML and PDF exports and imports with typed columns for Laravel Rust: a port of Laravel Excel (maatwebsite/excel).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//! The concerns: the interfaces in `Maatwebsite\Excel\Concerns`, as traits.
//!
//! Implement the concerns you need on your export or import, then declare them with
//! [`export!`](crate::export) or [`import!`](crate::import), which wires them up the way PHP's
//! `instanceof` checks do:
//!
//! ```ignore
//! use laravel_excel::concerns::*;
//!
//! pub struct UsersExport;
//!
//! impl FromCollection for UsersExport {
//!     type Row = User;
//!
//!     async fn collection(&self) -> laravel::Result<Vec<User>> {
//!         User::all().await
//!     }
//! }
//!
//! impl WithHeadings for UsersExport {
//!     fn headings(&self) -> impl IntoRows {
//!         ["#", "Name", "Email"]
//!     }
//! }
//!
//! laravel_excel::export!(UsersExport: FromCollection, WithHeadings, ShouldAutoSize);
//! ```

use std::future::Future;

use futures_util::Stream;
use laravel::model::{IntoRow, Model};
use laravel::validation::Rules;

use crate::config::{CsvExportSettings, CsvImportSettings};
use crate::error::Failure;
use crate::events::{
    AfterBatch, AfterChunk, AfterImport, AfterSheet, BeforeExport, BeforeImport, BeforeSheet, BeforeWriting,
};
pub use crate::row::{IntoRows, Key, Row};
use crate::sheets::SheetKey;
pub use crate::sheets::Sheets;
use crate::spreadsheet::{Drawing, Properties, Worksheet};
use crate::style::Style;
pub use crate::value::{Value, ValueBinder};

// ---------------------------------------------------------------------------------------------
// Export sources
// ---------------------------------------------------------------------------------------------

/// `FromCollection`: the sheet's rows come from a list.
///
/// Each item becomes one row, through `WithMapping` when the export has it, or else through
/// [`IntoRows`]: a model or struct becomes its fields, like `attributesToArray()`.
pub trait FromCollection {
    /// The type of the items.
    type Row: Send;

    /// The items to export.
    fn collection(&self) -> impl Future<Output = laravel::Result<Vec<Self::Row>>> + Send;
}

/// `FromArray`: the sheet's rows come from an array, without awaiting anything.
pub trait FromArray {
    /// The type of the items.
    type Row: Send;

    /// The items to export.
    fn array(&self) -> Vec<Self::Row>;
}

/// `FromIterator`: the sheet's rows come from an iterator.
pub trait FromIterator {
    /// The type of the items.
    type Row: Send;

    /// The items to export.
    fn iterator(&self) -> impl Iterator<Item = Self::Row> + Send;
}

/// `FromGenerator`: the sheet's rows come from a stream, produced as they're written. A PHP
/// generator is lazy, and so is a Rust stream.
pub trait FromGenerator {
    /// The type of the items.
    type Row: Send;

    /// The items to export.
    fn generator(&self) -> impl Stream<Item = laravel::Result<Self::Row>> + Send;
}

/// `FromQuery`: the sheet's rows come from a model query, read in chunks of
/// [`chunk_size`](crate::ExcelConfig::chunk_size) rows (or `WithCustomChunkSize`).
///
/// The query is ordered by the model's key after any ordering of its own, as Eloquent's `chunk()`
/// does for a query without an order.
pub trait FromQuery {
    /// The model the query returns.
    type Model: Model + Send;

    /// The query.
    fn query(&self) -> laravel::db::Builder<Self::Model>;
}

/// `FromScout`: the sheet's rows are a search's results, read page by page with the chunk size
/// (`WithCustomChunkSize` or `excel.exports.chunk_size`), as Laravel Excel paginates a Scout
/// builder. Needs the `scout` feature, which enables `laravel::search`.
#[cfg(feature = "scout")]
pub trait FromScout {
    /// The model the search returns.
    type Model: laravel::search::Searchable + Send;

    /// The search, such as `Post::search("rust")`.
    fn scout(&self) -> laravel::search::Query<Self::Model>;
}

/// `FromView`: the sheet is an HTML table, rendered from a view and read like PhpSpreadsheet's
/// HTML reader reads it.
pub trait FromView {
    /// The view to render.
    fn view(&self) -> laravel::view::View;
}

// ---------------------------------------------------------------------------------------------
// Export concerns
// ---------------------------------------------------------------------------------------------

/// `WithHeadings`: rows written before the data, such as `["#", "Name", "Email"]`. A list of
/// lists writes several heading rows.
pub trait WithHeadings {
    /// The heading row or rows.
    fn headings(&self) -> impl IntoRows;
}

/// `WithMapping`: turns each item of the export's source, or each row of an import, into a row.
///
/// On an export, `In` is the source's row type, and the result may be one row or a list of rows.
/// On an import, `In` is [`Row`], and the result is the row passed on.
pub trait WithMapping<In> {
    /// Maps one item.
    fn map(&self, row: In) -> impl IntoRows;
}

/// `WithColumnFormatting`: number formats for whole columns, such as `("B", "dd/mm/yyyy")`, or
/// ranges such as `("B2:B10", "0.00")`. See [`number_format`](crate::style::number_format).
pub trait WithColumnFormatting {
    /// The column (or range) and its format code.
    fn column_formats(&self) -> Vec<(&str, &str)>;
}

/// `ShouldAutoSize`: the columns without an explicit width fit their content.
pub trait ShouldAutoSize {}

/// `WithTitle`: the sheet's title, and the document's title. Characters a sheet title can't hold
/// (`* : / \ ? [ ]`) are removed, and the title is cut to 31 characters.
pub trait WithTitle {
    /// The title.
    fn title(&self) -> String;
}

/// `WithMultipleSheets`: one sheet per export (or import) of [`Sheets`].
pub trait WithMultipleSheets {
    /// The sheets.
    fn sheets(&self) -> Sheets;
}

/// `WithExportTemplate`: the export is written into a copy of this workbook, sheet by sheet: the
/// first sheet export into the template's first sheet, and so on, with new sheets after the
/// template's. Rows go below what the sheet holds. A relative path is under the application's
/// base path.
pub trait WithExportTemplate {
    /// The template's path, such as `resources/templates/invoice.xlsx`.
    fn export_template(&self) -> String;
}

/// `WithCharts`: charts added to the sheet after its rows (XLSX).
pub trait WithCharts {
    /// The charts.
    fn charts(&self) -> Vec<crate::spreadsheet::Chart>;
}

/// `WithConditionalSheets`: the sheets are the selected ones of [`conditional_sheets`]: the
/// trait's `onlySheets()` and `conditionalSheets()`. Keep the selection in a field and return it
/// from [`selected_sheets`]; declare `WithConditionalSheets` in `export!`/`import!` instead of
/// `WithMultipleSheets`.
///
/// [`conditional_sheets`]: WithConditionalSheets::conditional_sheets
/// [`selected_sheets`]: WithConditionalSheets::selected_sheets
pub trait WithConditionalSheets {
    /// Every sheet, under the keys `selected_sheets` picks from.
    fn conditional_sheets(&self) -> Sheets;

    /// The keys of the sheets to use: what `onlySheets()` stored.
    fn selected_sheets(&self) -> Vec<crate::sheets::SheetKey>;
}

impl<T: WithConditionalSheets> WithMultipleSheets for T {
    fn sheets(&self) -> Sheets {
        self.conditional_sheets().only(self.selected_sheets())
    }
}

/// `WithStyles`: styles for cells, ranges, rows and columns, applied after the data is written.
///
/// Keys are coordinates such as `B2`, ranges such as `A1:C3`, columns such as `B`, or row
/// numbers such as `1` (styling the row's used cells). `sheet` is the sheet itself, for styling it
/// directly.
pub trait WithStyles {
    /// The styles to apply.
    fn styles(&self, sheet: &mut Worksheet) -> Vec<(String, Style)>;
}

/// `WithEvents` with `RegistersEventListeners`: hooks into the export or import as it runs. Each
/// method is one of Laravel Excel's events, and does nothing unless you override it.
pub trait WithEvents {
    /// `BeforeExport`: the workbook was created.
    fn before_export(&self, event: &mut BeforeExport<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `BeforeWriting`: the workbook is about to be written.
    fn before_writing(&self, event: &mut BeforeWriting<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `BeforeSheet`: a sheet is about to be exported or imported.
    fn before_sheet(&self, event: &mut BeforeSheet<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `AfterSheet`: a sheet was exported or imported.
    fn after_sheet(&self, event: &mut AfterSheet<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `BeforeImport`: the file was opened for an import.
    fn before_import(&self, event: &mut BeforeImport<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `AfterImport`: the import finished.
    fn after_import(&self, event: &mut AfterImport<'_>) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `AfterBatch`: a batch of `ToModel` rows was saved.
    fn after_batch(&self, event: &AfterBatch) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `AfterChunk`: a chunk of a `WithChunkReading` import was read.
    fn after_chunk(&self, event: &AfterChunk) -> laravel::Result<()> {
        let _ = event;
        Ok(())
    }

    /// `ImportFailed`: the import failed with `error`.
    fn import_failed(&self, error: &laravel::Error) {
        let _ = error;
    }
}

/// `WithCustomStartCell`: the cell the sheet starts at, such as `B2`, instead of `A1`.
pub trait WithCustomStartCell {
    /// The start cell.
    fn start_cell(&self) -> String;
}

/// `WithColumns`: the sheet as typed columns, for exports and imports. See
/// [`columns`](crate::columns).
///
/// Cannot be combined with `WithHeadings` or `WithMapping` (export), or with `WithMappedCells`,
/// `WithColumnLimit` or `WithGroupedHeadingRow` (import). Column formats and widths are applied
/// before `WithColumnFormatting`, `WithColumnWidths` and `WithStyles`, so those still win where
/// they overlap.
pub trait WithColumns {
    /// The columns.
    fn columns(&self) -> Vec<crate::columns::Column>;
}

/// `WithProgressBar`: the import reports its progress: the `progressStart()`,
/// `progressAdvance()` and `progressFinish()` calls Laravel Excel makes on
/// `getConsoleOutput()`. Forward them to a console progress bar, such as the one
/// `laravel::console` starts with `progress(total, message)`.
pub trait WithProgressBar {
    /// The rows to read: the sheet's highest row, or with `WithChunkReading` all sheets' rows.
    fn progress_start(&self, total: u64);
    /// One more row was read.
    fn progress_advance(&self, step: u64);
    /// The sheet, or with `WithChunkReading` the import, is done.
    fn progress_finish(&self);
}

/// `WithSkipDuplicates`: `ToModel` rows that break a unique index are skipped, as
/// `insertOrIgnore()` skips them. Rows are inserted one by one, and only unique violations are
/// skipped; other errors go to `SkipsOnError` or fail the import.
pub trait WithSkipDuplicates {}

/// `WithReadFilter`: only the cells the filter accepts are read: PhpSpreadsheet's
/// `IReadFilter::readCell()`. Columns are letters such as `B`; rows start at 1.
pub trait WithReadFilter {
    /// Whether to read the cell.
    fn read_cell(&self, column: &str, row: u32, worksheet_name: &str) -> bool;
}

/// `HasReferencesToOtherSheets`: in PHP, formulas of an imported sheet are calculated with the
/// other sheets loaded. This port reads the results stored in the file, which already include
/// other sheets, so the marker changes nothing.
pub trait HasReferencesToOtherSheets {}

/// `WithFormatData`: imported values as the cells show them, with their number formats, such as
/// `05/03/2024` for a date cell. Number formats are read from XLSX files; XLS, ODS and CSV values
/// use `General`.
pub trait WithFormatData {}

/// `WithStrictNullComparison`: `null` values are written as empty cells instead of being skipped.
pub trait WithStrictNullComparison {}

/// `WithProperties`: the document properties, on top of `config('excel.exports.properties')`.
pub trait WithProperties {
    /// The properties.
    fn properties(&self) -> Properties;
}

/// `WithColumnWidths`: explicit column widths, such as `("A", 55.0)`. These columns don't
/// auto-size.
pub trait WithColumnWidths {
    /// The column and its width in characters.
    fn column_widths(&self) -> Vec<(&str, f64)>;
}

/// `WithFreezePane`: freezes the rows above and the columns left of a cell, such as `B2`.
pub trait WithFreezePane {
    /// The pane's top left cell.
    fn freeze_pane(&self) -> String;
}

/// `WithTabColor`: the sheet tab's color, as `RRGGBB` hex.
pub trait WithTabColor {
    /// The color.
    fn tab_color(&self) -> String;
}

/// `WithSheetProtection`: protects the sheet, with an optional password.
pub trait WithSheetProtection {
    /// The password, or `None` for protection without a password.
    fn sheet_protection(&self) -> Option<String>;
}

/// `WithPageBreaks`: page breaks after the given rows.
pub trait WithPageBreaks {
    /// The rows to break after.
    fn page_breaks(&self) -> Vec<u32>;
}

/// `WithPrintArea`: the sheet's print area, such as `A1:D20`.
pub trait WithPrintArea {
    /// The range.
    fn print_area(&self) -> String;
}

/// `WithDrawings`: images placed on the sheet.
pub trait WithDrawings {
    /// The images.
    fn drawings(&self) -> Vec<Drawing>;
}

/// `WithDefaultStyles`: the workbook's default style.
pub trait WithDefaultStyles {
    /// The default style.
    fn default_styles(&self) -> Style;
}

/// `WithBackgroundColor`: the workbook's default background color, as `RRGGBB` hex.
pub trait WithBackgroundColor {
    /// The color.
    fn background_color(&self) -> String;
}

/// `WithCustomValueBinder`: decides the type of each written value (and of each value read from a
/// CSV file) instead of the configured value binder.
pub trait WithCustomValueBinder: ValueBinder {}

/// `WithCustomCsvSettings` on an export: overrides `config('excel.exports.csv')`.
pub trait WithCustomCsvSettings {
    /// The settings for writing.
    fn csv_settings(&self) -> CsvExportSettings {
        crate::config::current().exports.csv
    }

    /// The settings for reading.
    fn csv_import_settings(&self) -> CsvImportSettings {
        crate::config::current().imports.csv
    }
}

/// `WithCustomChunkSize`: the chunk size of a `FromQuery` export.
pub trait WithCustomChunkSize {
    /// Rows per chunk.
    fn chunk_size(&self) -> u64;
}

/// `WithCustomQuerySize`: the number of rows a queued `FromQuery` export splits into chunks, when
/// the query's own count isn't right (such as for a grouped query).
pub trait WithCustomQuerySize {
    /// The number of rows.
    fn query_size(&self) -> impl Future<Output = laravel::Result<u64>> + Send;
}

/// `WithPreCalculateFormulas`. This port can't calculate formulas, so an export with this concern
/// fails when it's written; see the README.
pub trait WithPreCalculateFormulas {}

/// `ShouldQueue`: `Excel::store` (and `Excel::import` with `WithChunkReading`) queue the work.
///
/// The export or import must implement `Serialize` and `Deserialize`, so the queued jobs can
/// carry it.
pub trait ShouldQueue {
    /// The connection, or the default connection: the `$connection` property (or `#[Connection]`).
    fn on_connection(&self) -> Option<String> {
        None
    }

    /// The queue, or the default queue: the `$queue` property (or `#[Queue]`).
    fn on_queue(&self) -> Option<String> {
        None
    }
}

/// `ShouldBatch`: queued work is dispatched as a job batch instead of a chain.
pub trait ShouldBatch {}

/// `ShouldQueueWithoutChain`: queued import chunks are dispatched separately instead of as a
/// chain, with the final clean-up delayed. Like the PHP interface, it extends `ShouldQueue`.
pub trait ShouldQueueWithoutChain: ShouldQueue {
    /// Seconds to wait before the final job runs (`$cleanupInterval`, 60 by default).
    fn cleanup_interval(&self) -> u64 {
        60
    }
}

// ---------------------------------------------------------------------------------------------
// Import destinations
// ---------------------------------------------------------------------------------------------

/// `ToModel`: each row becomes a model row to insert.
///
/// Return `row!(User { .. })`, a fill struct, or nothing to skip the row. Without
/// `WithBatchInserts`, each row is created on its own and runs the model's hooks and events, like
/// `saveOrFail()`; with it, rows are inserted in batches without hooks, like `Model::insert()`.
pub trait ToModel {
    /// The model to insert.
    type Model: Model + Send;

    /// The model rows for a sheet row: `None`/an empty list skips it.
    fn model(&self, row: Row) -> impl IntoIterator<Item = impl IntoRow<Self::Model>>;
}

/// `ToCollection`: receives the sheet's rows.
pub trait ToCollection {
    /// Handles the rows.
    fn collection(&self, rows: Vec<Row>) -> impl Future<Output = laravel::Result<()>> + Send;
}

/// `ToArray`: receives the sheet's rows. In Rust it receives the same rows as `ToCollection`.
pub trait ToArray {
    /// Handles the rows.
    fn array(&self, rows: Vec<Row>) -> impl Future<Output = laravel::Result<()>> + Send;
}

/// `OnEachRow`: handles each row as it's read.
pub trait OnEachRow {
    /// Handles one row.
    fn on_row(&self, row: Row) -> impl Future<Output = laravel::Result<()>> + Send;
}

// ---------------------------------------------------------------------------------------------
// Import concerns
// ---------------------------------------------------------------------------------------------

/// `WithHeadingRow`: the first row (or [`heading_row`](Self::heading_row)) holds headings, which
/// become the keys of the rows below it, formatted by the heading row formatter.
pub trait WithHeadingRow {
    /// The heading row's number.
    fn heading_row(&self) -> u32 {
        1
    }
}

/// `WithGroupedHeadingRow`: the values of columns that share a heading are grouped into a list.
/// Like the PHP interface, it extends `WithHeadingRow`.
pub trait WithGroupedHeadingRow: WithHeadingRow {}

/// `WithStartRow`: rows above this one are skipped.
pub trait WithStartRow {
    /// The first row to read.
    fn start_row(&self) -> u32;
}

/// `WithLimit`: at most this many rows are read, counting from the start row.
pub trait WithLimit {
    /// The number of rows.
    fn limit(&self) -> u32;
}

/// `WithColumnLimit`: columns after this one, such as `D`, are ignored.
pub trait WithColumnLimit {
    /// The last column to read.
    fn end_column(&self) -> String;
}

/// `WithMappedCells`: reads single cells into a row, such as `("name", "B1")`, instead of reading
/// rows. With `ToModel`, `ToArray` or `ToCollection`, the import receives that one row.
pub trait WithMappedCells {
    /// Keys and the coordinates they read.
    fn mapping(&self) -> Vec<(&str, &str)>;
}

/// `WithBatchInserts`: `ToModel` rows are inserted in batches of this size.
pub trait WithBatchInserts {
    /// Rows per batch.
    fn batch_size(&self) -> usize;
}

/// `WithChunkReading`: the sheet is read and processed in chunks of this many rows, each in its
/// own transaction. With `ShouldQueue`, each chunk is a queued job.
pub trait WithChunkReading {
    /// Rows per chunk.
    fn chunk_size(&self) -> u32;
}

/// `WithUpserts`: `ToModel` rows that conflict on these columns update the existing row.
///
/// Without `WithUpsertColumns`, Laravel Excel updates the columns the row sets. This port can't
/// see which columns a row sets, so it updates every column of the model except its key,
/// `created_at`, and the `unique_by` columns; implement `WithUpsertColumns` when rows don't set
/// every column.
pub trait WithUpserts {
    /// The columns that identify a row.
    fn unique_by(&self) -> Vec<&'static str>;
}

/// `WithUpsertColumns`: the columns `WithUpserts` updates on a conflict.
pub trait WithUpsertColumns {
    /// The columns to update.
    fn upsert_columns(&self) -> Vec<&'static str>;
}

/// `WithValidation`: rows are validated before they're handled.
///
/// Rules are keyed by heading (with `WithHeadingRow`) or column index, such as `"email"` or `"1"`.
/// A `*.` prefix, as in Laravel Excel, is accepted and ignored. Failed rows stop the import with a
/// [`ValidationException`](crate::ValidationException), unless the import has `SkipsOnFailure`.
pub trait WithValidation {
    /// The rules for one row.
    fn rules(&self) -> Rules;

    /// Prepares a row before it's validated: `prepareForValidation($data, $index)`.
    fn prepare_for_validation(&self, row: Row) -> Row {
        row
    }

    /// Names for the attributes in messages, such as `("email", "e-mail address")`:
    /// `customValidationAttributes()`. Failures carry the name instead of the attribute.
    fn custom_validation_attributes(&self) -> Vec<(String, String)> {
        Vec::new()
    }
}

/// `SkipsOnFailure`: rows that fail validation are skipped and passed here instead of stopping the
/// import. Keep them with [`Failures`](crate::Failures), like PHP's `SkipsFailures` trait.
pub trait SkipsOnFailure {
    /// Receives the failures.
    fn on_failure(&self, failures: Vec<Failure>);
}

/// `SkipsOnError`: errors while handling a row (such as a database error) are passed here instead
/// of stopping the import. Keep them with [`Errors`](crate::Errors), like PHP's `SkipsErrors`.
pub trait SkipsOnError {
    /// Receives the error.
    fn on_error(&self, error: laravel::Error);
}

/// `SkipsEmptyRows`: rows whose cells are all empty are skipped.
pub trait SkipsEmptyRows {
    /// Whether to also skip this (non-empty) row: `isEmptyWhen($row)`.
    fn is_empty_when(&self, row: &Row) -> bool {
        let _ = row;
        false
    }
}

/// `SkipsUnknownSheets`: a sheet that `WithMultipleSheets` names but the file doesn't have is
/// passed here instead of failing the import.
pub trait SkipsUnknownSheets {
    /// Receives the sheet's name or index.
    fn on_unknown_sheet(&self, sheet: &SheetKey);
}

/// `WithCalculatedFormulas`: formula cells give the value the file stored for them, instead of the
/// formula.
pub trait WithCalculatedFormulas {}

/// `RemembersRowNumber`: in Rust each [`Row`] carries its number, as
/// [`Row::row_number`]; this marker is accepted for parity.
pub trait RemembersRowNumber {}

/// `RemembersChunkOffset`: in Rust the chunk's first row is
/// [`AfterChunk::start_row`](crate::events::AfterChunk); this marker is accepted for parity.
pub trait RemembersChunkOffset {}