Skip to main content

excel_writer/
context.rs

1use std::{borrow::Cow, collections::HashMap};
2
3use excel_column_id::ColumnId;
4
5use crate::{
6    cell::ColIndex,
7    shared_strings::{SharedStringIndex, SharedStrings},
8};
9
10#[derive(Default)]
11pub struct Context {
12    pub(crate) shared_strings: SharedStrings,
13    pub(crate) column_ids_cache: HashMap<ColIndex, ColumnId>,
14}
15
16impl Context {
17    pub(crate) fn add_shared_string(&mut self, value: Cow<'static, str>) -> SharedStringIndex {
18        self.shared_strings.insert(value)
19    }
20
21    pub(crate) fn add_col_index(&mut self, col_index: ColIndex) {
22        self.column_ids_cache
23            .entry(col_index)
24            .or_insert_with(|| ColumnId::from(col_index.0 + 1));
25    }
26}