diff --git a/base/src/new_empty.rs b/base/src/new_empty.rs index 285d088..5799afa 100644 --- a/base/src/new_empty.rs +++ b/base/src/new_empty.rs @@ -68,6 +68,7 @@ impl Model { frozen_rows: 0, show_grid_lines: true, views, + conditional_formatting: vec![] } } diff --git a/base/src/types.rs b/base/src/types.rs index fa98aba..b43d3ad 100644 --- a/base/src/types.rs +++ b/base/src/types.rs @@ -117,6 +117,26 @@ pub struct Worksheet { pub views: HashMap, /// Whether or not to show the grid lines in the worksheet pub show_grid_lines: bool, + pub conditional_formatting: Vec +} + +#[derive(Encode, Decode, Debug, PartialEq, Clone)] +pub struct ColorScale { + +} + +#[derive(Encode, Decode, Debug, PartialEq, Clone)] +pub enum CfRule { + ColorScale { + priority: u32, + }, + CellIs, +} + +#[derive(Encode, Decode, Debug, PartialEq, Clone)] +pub struct ConditionalFormatting { + sqref: String, + cf_rule: Vec } /// Internal representation of Excel's sheet_data diff --git a/xlsx/src/import/worksheets.rs b/xlsx/src/import/worksheets.rs index 3d14b44..8383615 100644 --- a/xlsx/src/import/worksheets.rs +++ b/xlsx/src/import/worksheets.rs @@ -148,6 +148,65 @@ fn load_columns(ws: Node) -> Result, XlsxError> { Ok(cols) } + +// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_cfRule_topic_ID0EFKO4.html +fn load_conditional_formatting(ws: Node) -> Result, XlsxError> { + // Conditional Formatting + // + // + // + // + // + // + // + // + // + // + let mut conditional_formatting = Vec::new(); + let conditional_formatting_nodes = ws + .children() + .filter(|n| n.has_tag_name("conditionalFormattng")) + .collect::>(); + for format in conditional_formatting_nodes { + let reference = get_attribute(&format, "sqref")?.to_string(); + // cfRule + let cf_rule_nodes = ws + .children() + .filter(|n| n.has_tag_name("cfRule")) + .collect::>(); + if cf_rule_nodes.len() == 1 { + let cf_rule = cf_rule_nodes[0] ; + let cf_type = get_attribute(&cf_rule, "type")?.to_string(); + match cf_type.as_str() { + "colorScale" => { + todo!() + } + "aboveAverage" => { + let dxf_id = get_attribute(&cf_rule, "dxfId")?.to_string(); + todo!() + } + "notContainsBlanks" => { + let dxf_id = get_attribute(&cf_rule, "dxfId")?.to_string(); + + } + _ => {} + + } + } + // priority + + // if type is avobeAverage then avobeAverage (and equlAverage) + + // dxfId for some types((Differential Formatting Id) What style to apply when the criteria are met + + // Posible children + // formula + // colorScales + } + + Ok(conditional_formatting) +} + fn load_merge_cells(ws: Node) -> Result, XlsxError> { // 18.3.1.55 Merge Cells // @@ -945,17 +1004,7 @@ pub(super) fn load_sheet( let merge_cells = load_merge_cells(ws)?; - // Conditional Formatting - // - // - // - // - // - // - // - // - // - // + let conditional_formatting = load_conditional_formatting(ws)?; // pageSetup //