diff --git a/crates/xlsx/src/chart.rs b/crates/xlsx/src/chart.rs index b292083e57..612f9dd725 100644 --- a/crates/xlsx/src/chart.rs +++ b/crates/xlsx/src/chart.rs @@ -419,6 +419,23 @@ const DASHES: [(LineDash, &str); 11] = [ const EMU_PER_PT: f64 = 12_700.0; +fn rich_title(t: &El) -> Option { + let tx = t.child("tx")?; + if let Some(rich) = tx.child("rich") { + let paras: Vec = + rich.kids("p").map(|p| p.kids("r").filter_map(|r| r.child("t")).map(|t| t.text.as_str()).collect::()).collect(); + let s = paras.join("\n"); + return if s.is_empty() { None } else { Some(s) }; + } + if let Some(sr) = tx.child("strRef") { + if let Some(v) = sr.path(&["strCache", "pt", "v"]) { + return Some(v.text.clone()); + } + return sr.child("f").map(|f| f.text.trim().to_string()); + } + None +} + pub(crate) fn from_dml_chart(dc: DmlChart, root: Option<&El>, budget: &mut ChartReadBudget) -> (Chart, Vec) { let plot = root.and_then(|r| r.path(&["chart", "plotArea"])); let groups: Vec<&El> = plot.map(|p| p.children.iter().filter(|g| g.name.ends_with("Chart")).collect()).unwrap_or_default(); @@ -519,18 +536,20 @@ pub(crate) fn from_dml_chart(dc: DmlChart, root: Option<&El>, budget: &mut Chart }; let hole_size = if plot.is_some_and(|p| p.child("doughnutChart").is_some()) { (dc.hole_size * 100.0).round().clamp(10.0, 90.0) as u8 } else { 75 }; - let auto_title_deleted = root - .and_then(|r| r.child("chart")) - .is_some_and(|c| c.child("title").is_none() && c.child("autoTitleDeleted").is_some_and(|d| d.flag("val", true))); + // No ``: an automatic title (a lone series' name), unless the file deleted it. + let title = match root.and_then(|r| r.child("chart")) { + Some(c) => match c.child("title") { + Some(t) => rich_title(t).or(dc.title), + None if c.child("autoTitleDeleted").is_some_and(|d| d.flag("val", true)) => Some(String::new()), + None => None, + }, + None => dc.title, + }; let ch = Chart { id: 0, kind, anchor: Default::default(), - title: match dc.title { - Some(t) => Some(t), - None if auto_title_deleted => Some(String::new()), - None => None, - }, + title, series, legend, data_labels: dc.data_labels || series_labels,