umya-spreadsheet 3.0.0

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
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
use super::{
    BooleanValue,
    EnumValue,
    StringValue,
    TotalsRowFunctionValues,
    UInt32Value,
    coordinate::Coordinate,
};
use crate::helper::coordinate::CellCoordinates;

// use reader::driver::*;

#[derive(Clone, Default, Debug)]
pub struct Table {
    name:             Box<str>,
    area:             (Coordinate, Coordinate),
    display_name:     Box<str>,
    columns:          Vec<TableColumn>,
    style_info:       Option<Box<TableStyleInfo>>,
    totals_row_shown: BooleanValue,
    totals_row_count: UInt32Value,
}
impl Table {
    #[inline]
    pub fn new<T>(name: &str, area: (T, T)) -> Self
    where
        T: Into<CellCoordinates>,
    {
        let coord_beg = Self::cell_coord_to_coord(area.0);
        let coord_end = Self::cell_coord_to_coord(area.1);
        let name: Box<str> = name.into();
        Self {
            area:             (coord_beg, coord_end),
            name:             name.clone(),
            display_name:     name,
            columns:          Vec::<TableColumn>::default(),
            style_info:       None,
            totals_row_shown: BooleanValue::default(),
            totals_row_count: UInt32Value::default(),
        }
    }

    #[inline]
    #[must_use]
    pub fn is_ok(&self) -> bool {
        !(self.name.is_empty()
            || self.display_name.is_empty()
            || self.area.0.col_num() == 0
            || self.area.0.row_num() == 0
            || self.area.1.col_num() == 0
            || self.area.1.row_num() == 0
            || self.area.0.col_num() > self.area.1.col_num()
            || self.area.0.row_num() > self.area.1.row_num())
    }

    #[inline]
    #[must_use]
    pub fn name(&self) -> &str {
        &self.name
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use name()")]
    pub fn get_name(&self) -> &str {
        self.name()
    }

    #[inline]
    pub fn set_name(&mut self, name: &str) {
        self.name = name.into();
        if self.display_name.is_empty() {
            self.display_name = name.into();
        }
    }

    #[inline]
    #[must_use]
    pub fn display_name(&self) -> &str {
        &self.display_name
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use display_name()")]
    pub fn get_display_name(&self) -> &str {
        self.display_name()
    }

    #[inline]
    pub fn set_display_name(&mut self, display_name: &str) {
        self.display_name = display_name.into();
    }

    #[inline]
    #[must_use]
    pub fn area(&self) -> &(Coordinate, Coordinate) {
        &self.area
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use area()")]
    pub fn get_area(&self) -> &(Coordinate, Coordinate) {
        self.area()
    }

    #[inline]
    pub fn set_area<T>(&mut self, area: (T, T))
    where
        T: Into<CellCoordinates>,
    {
        let coord_beg = Self::cell_coord_to_coord(area.0);
        let coord_end = Self::cell_coord_to_coord(area.1);
        self.area = (coord_beg, coord_end);
    }

    #[inline]
    pub fn add_column(&mut self, col: TableColumn) {
        self.columns.push(col);
    }

    #[inline]
    #[must_use]
    pub fn columns(&self) -> &[TableColumn] {
        &self.columns
    }

    #[inline]
    #[must_use]
    pub fn columns_mut(&mut self) -> &mut [TableColumn] {
        &mut self.columns
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use columns()")]
    pub fn get_columns(&self) -> &[TableColumn] {
        self.columns()
    }

    #[inline]
    pub(crate) fn has_style_info(&self) -> bool {
        self.style_info.is_some()
    }

    #[inline]
    #[must_use]
    pub fn style_info(&self) -> Option<&TableStyleInfo> {
        self.style_info.as_deref()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use style_info()")]
    pub fn get_style_info(&self) -> Option<&TableStyleInfo> {
        self.style_info()
    }

    #[inline]
    pub fn set_style_info(&mut self, style_info: Option<TableStyleInfo>) {
        self.style_info = style_info.map(Box::new);
    }

    #[inline]
    pub(crate) fn has_totals_row_shown(&self) -> bool {
        self.totals_row_shown.has_value()
    }

    #[inline]
    #[must_use]
    pub fn totals_row_shown(&self) -> bool {
        self.totals_row_shown.value()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use totals_row_shown()")]
    pub fn get_totals_row_shown(&self) -> bool {
        self.totals_row_shown()
    }

    #[inline]
    pub(crate) fn totals_row_shown_str(&self) -> &str {
        self.totals_row_shown.value_string()
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use totals_row_shown_str()")]
    pub(crate) fn get_totals_row_shown_str(&self) -> &str {
        self.totals_row_shown_str()
    }

    #[inline]
    pub fn set_totals_row_shown(&mut self, value: bool) {
        self.totals_row_shown.set_value(value);
    }

    #[inline]
    pub(crate) fn set_totals_row_shown_str(&mut self, value: &str) {
        self.totals_row_shown.set_value_string(value);
    }

    #[inline]
    pub(crate) fn has_totals_row_count(&self) -> bool {
        self.totals_row_count.has_value()
    }

    #[inline]
    #[must_use]
    pub fn totals_row_count(&self) -> u32 {
        self.totals_row_count.value()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use totals_row_count()")]
    pub fn get_totals_row_count(&self) -> u32 {
        self.totals_row_count()
    }

    #[inline]
    pub(crate) fn totals_row_count_str(&self) -> String {
        self.totals_row_count.value_string()
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use totals_row_count_str()")]
    pub(crate) fn get_totals_row_count_str(&self) -> String {
        self.totals_row_count_str()
    }

    #[inline]
    pub fn set_totals_row_count(&mut self, value: u32) {
        self.totals_row_count.set_value(value);
    }

    #[inline]
    pub(crate) fn set_totals_row_count_str(&mut self, value: &str) {
        self.totals_row_count.set_value_string(value);
    }

    #[inline]
    fn cell_coord_to_coord<T>(cc: T) -> Coordinate
    where
        T: Into<CellCoordinates>,
    {
        let cell_coord: CellCoordinates = cc.into();
        let mut coord: Coordinate = Coordinate::default();
        coord.set_col_num(cell_coord.col);
        coord.set_row_num(cell_coord.row);
        coord
    }
}

#[derive(Clone, Default, Debug)]
pub struct TableColumn {
    name:                      String,
    totals_row_label:          StringValue,
    totals_row_function:       EnumValue<TotalsRowFunctionValues>,
    calculated_column_formula: Option<String>,
}
impl TableColumn {
    #[inline]
    #[must_use]
    pub fn new(name: &str) -> Self {
        Self {
            name:                      name.to_string(),
            totals_row_label:          StringValue::default(),
            totals_row_function:       EnumValue::default(),
            calculated_column_formula: None,
        }
    }

    #[inline]
    #[must_use]
    pub fn name(&self) -> &str {
        self.name.as_str()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use name()")]
    pub fn get_name(&self) -> &str {
        self.name()
    }

    #[inline]
    pub fn set_name(&mut self, name: String) {
        self.name = name;
    }

    #[inline]
    #[allow(dead_code)]
    pub(crate) fn has_totals_row_label(&self) -> bool {
        self.totals_row_label.has_value()
    }

    #[inline]
    #[must_use]
    pub fn totals_row_label(&self) -> Option<&str> {
        self.totals_row_label.value()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use totals_row_label()")]
    pub fn get_totals_row_label(&self) -> Option<&str> {
        self.totals_row_label()
    }

    #[inline]
    pub(crate) fn totals_row_label_str(&self) -> &str {
        self.totals_row_label.value_str()
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use totals_row_label_str()")]
    pub(crate) fn get_totals_row_label_str(&self) -> &str {
        self.totals_row_label_str()
    }

    #[inline]
    pub fn set_totals_row_label(&mut self, value: &str) {
        self.totals_row_label.set_value(value);
    }

    #[inline]
    pub(crate) fn set_totals_row_label_str(&mut self, value: &str) {
        self.totals_row_label.set_value_string(value);
    }

    #[inline]
    #[allow(dead_code)]
    pub(crate) fn has_totals_row_function(&self) -> bool {
        self.totals_row_function.has_value()
    }

    #[inline]
    #[must_use]
    pub fn totals_row_function(&self) -> &TotalsRowFunctionValues {
        self.totals_row_function.value()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use totals_row_function()")]
    pub fn get_totals_row_function(&self) -> &TotalsRowFunctionValues {
        self.totals_row_function()
    }

    #[inline]
    pub(crate) fn totals_row_function_str(&self) -> &str {
        self.totals_row_function.value_string()
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use totals_row_function_str()")]
    pub(crate) fn get_totals_row_function_str(&self) -> &str {
        self.totals_row_function_str()
    }

    #[inline]
    pub fn set_totals_row_function(&mut self, value: TotalsRowFunctionValues) {
        self.totals_row_function.set_value(value);
    }

    #[inline]
    pub(crate) fn set_totals_row_function_str(&mut self, value: &str) {
        self.totals_row_function.set_value_string(value);
    }

    #[inline]
    #[must_use]
    pub fn calculated_column_formula(&self) -> Option<&String> {
        self.calculated_column_formula.as_ref()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use calculated_column_formula()")]
    pub fn get_calculated_column_formula(&self) -> Option<&String> {
        self.calculated_column_formula()
    }

    #[inline]
    pub(crate) fn set_calculated_column_formula(&mut self, value: String) {
        self.calculated_column_formula = Some(value);
    }
}

#[derive(Clone, Debug)]
pub struct TableStyleInfo {
    name:             String,
    show_first_col:   ShowColumn,
    show_last_col:    ShowColumn,
    show_row_stripes: ShowStripes,
    show_col_stripes: ShowStripes,
}

#[derive(Debug, Clone, Copy)]
pub enum ShowColumn {
    Show,
    Hide,
}

#[derive(Debug, Clone, Copy)]
pub enum ShowStripes {
    Show,
    Hide,
}

impl Default for TableStyleInfo {
    fn default() -> Self {
        Self {
            name:             String::new(), // Default name can be an empty string
            show_first_col:   ShowColumn::Hide, // Default to Hide
            show_last_col:    ShowColumn::Hide, // Default to Hide
            show_row_stripes: ShowStripes::Hide, // Default to Hide
            show_col_stripes: ShowStripes::Hide, // Default to Hide
        }
    }
}

impl TableStyleInfo {
    #[inline]
    #[must_use]
    pub fn new(
        name: &str,
        show_first_col: ShowColumn,
        show_last_col: ShowColumn,
        show_row_stripes: ShowStripes,
        show_col_stripes: ShowStripes,
    ) -> Self {
        Self {
            name: name.to_string(),
            show_first_col,
            show_last_col,
            show_row_stripes,
            show_col_stripes,
        }
    }

    #[inline]
    #[must_use]
    pub fn name(&self) -> &str {
        self.name.as_str()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use name()")]
    pub fn get_name(&self) -> &str {
        self.name()
    }

    #[inline]
    #[must_use]
    pub fn is_show_first_col(&self) -> bool {
        matches!(self.show_first_col, ShowColumn::Show)
    }

    #[inline]
    #[must_use]
    pub fn is_show_last_col(&self) -> bool {
        matches!(self.show_last_col, ShowColumn::Show)
    }

    #[inline]
    #[must_use]
    pub fn is_show_row_stripes(&self) -> bool {
        matches!(self.show_row_stripes, ShowStripes::Show)
    }

    #[inline]
    #[must_use]
    pub fn is_show_col_stripes(&self) -> bool {
        matches!(self.show_col_stripes, ShowStripes::Show)
    }
}