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
// SPDX-License-Identifier: MIT
//
// Copyright 2016-2026, Johann Tuffe.
//! An example of deserializing rows that have a fixed set of named columns
//! plus an unknown number of extra columns captured with `#[serde(flatten)]`.
//!
//! Compared with `deserialize_struct`, which requires every column to be
//! declared as a struct field, this example shows how to use Serde's
//! `#[serde(flatten)]` attribute to absorb any remaining columns into a
//! [`std::collections::HashMap`]. This is useful when the spreadsheet may
//! contain extra columns that are not known at compile time.
//!
//! The sample Excel file `readings.xlsx` contains a single sheet named
//! "Sheet1" with the following data:
//!
//! ```text
//! ______________________________________________________________________________
//! | || | | | |
//! | || A | B | C | D |
//! |_________||________________|________________|________________|________________|
//! | 1 || Station | Celsius | Humidity | Pressure |
//! |_________||________________|________________|________________|________________|
//! | 2 || London | 15 | 72 | 1013 |
//! |_________||________________|________________|________________|________________|
//! | 3 || Paris | 18.5 | 65 | 1009 |
//! |_________||________________|________________|________________|________________|
//! | 4 || Berlin | 12 | 80 | 1017 |
//! |_________||________________|________________|________________|________________|
//! |_ ___________________________________________________________________|
//! \ Sheet1 /
//! ------
//! ```
//!
//! Next: `deserialize_fallible` — handling cells that may be empty or contain
//! unexpected types.
use HashMap;
use ;
use Deserialize;
// The `station` field is matched by name to the "Station" header. All
// remaining columns are absorbed into `readings` by `#[serde(flatten)]`.