diff --git a/src/lib.rs b/src/lib.rs index 406502e..c1236ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,6 +130,7 @@ pub fn import_to_xlsx(raw_data: &JsValue) -> Vec { let mut shared_strings = vec!(); let mut shared_strings_count = 0; + let text_styles = get_text_styles(&data.styles); let style_table = StyleTable::new(data.styles); let mut sheets_info: Vec<(String, String)> = vec!(); @@ -160,7 +161,7 @@ pub fn import_to_xlsx(raw_data: &JsValue) -> Vec { Some(value) => { if !value.is_empty() { match value.parse::() { - Ok(_) if !value.starts_with("0") || value.len() == 1 => { + Ok(_) if (!value.starts_with("0") || value.len() == 1) && !is_text_style(&cell.s, &text_styles) => { inner_cell.value = CellValue::Value(value.to_owned()); }, Err(_) | _ => { @@ -445,6 +446,28 @@ fn get_styles_data(style_table: StyleTable) -> String { style_sheet.to_xml() } +fn get_text_styles(styles: &Option>) -> Vec { + match styles { + Some(styles) => styles + .iter() + .map(|style| match style.get("format") { + Some(Value::String(format)) => { + format == "@" || format.eq_ignore_ascii_case("text") + }, + _ => false, + }) + .collect(), + None => vec!(), + } +} + +fn is_text_style(style: &Option, text_styles: &Vec) -> bool { + style + .and_then(|index| text_styles.get(index as usize)) + .copied() + .unwrap_or(false) +} + fn cell_offsets_to_index(row: usize, col: usize) -> String { let mut num = col; let mut chars = vec!(); diff --git a/src/style.rs b/src/style.rs index f6dbbb7..0608131 100644 --- a/src/style.rs +++ b/src/style.rs @@ -198,7 +198,7 @@ impl Border { } impl BorderProps { - pub fn to_xml_el(&self) -> Element { + pub fn to_xml_el(&self) -> Element<'_> { let el_name = match self.position { BorderPosition::Top => "top", BorderPosition::Right => "right",