Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn import_to_xlsx(raw_data: &JsValue) -> Vec<u8> {

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!();
Expand Down Expand Up @@ -160,7 +161,7 @@ pub fn import_to_xlsx(raw_data: &JsValue) -> Vec<u8> {
Some(value) => {
if !value.is_empty() {
match value.parse::<f64>() {
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(_) | _ => {
Expand Down Expand Up @@ -445,6 +446,28 @@ fn get_styles_data(style_table: StyleTable) -> String {
style_sheet.to_xml()
}

fn get_text_styles(styles: &Option<Vec<Dict>>) -> Vec<bool> {
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<u32>, text_styles: &Vec<bool>) -> 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!();
Expand Down
2 changes: 1 addition & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down