pub struct EmbeddedChart {
pub chart_space: ChartSpace,
pub width_emu: i64,
pub height_emu: i64,
pub name: String,
}Expand description
An inline chart (<w:drawing><wp:inline>..), embedded in a run — RunContent::Chart’s
payload. Structurally the same wp:inline skeleton as Image (wp:extent/wp:docPr,
wrapping an a:graphic/a:graphicData), but the a:graphicData wraps a <c:chart r:id="..">
graphic frame instead of a pic:pic (see writer.rs::write_embedded_chart) — its own
graphic-frame wiring rather than a picture’s, even though both live under wp:inline on the
Word side.
A deliberate scope decision, since chart-in-document support is still an evolving corner of the
format: cached values only, no embedded .xlsx workbook as a data source. This crate’s
chart::ChartSpace already carries every series’ cached values directly
(chart::NumericDataSource/StringDataSource), so a Word chart embedded this way renders
correctly in Word without any companion workbook part — it just can’t be “edited” via Word’s
“Edit Data in Excel” feature the way a real Word-native chart (created through Word’s own UI)
can.
Fields§
§chart_space: ChartSpace§width_emu: i64The width the chart is displayed at, in EMUs (wp:extent’s cx).
height_emu: i64The height the chart is displayed at, in EMUs (cy).
name: StringAlt text / description (wp:docPr’s descr/name attributes). May be empty.
Implementations§
Source§impl EmbeddedChart
impl EmbeddedChart
Sourcepub fn new(
chart_space: ChartSpace,
width_emu: i64,
height_emu: i64,
) -> EmbeddedChart
pub fn new( chart_space: ChartSpace, width_emu: i64, height_emu: i64, ) -> EmbeddedChart
Creates an embedded chart with an explicit display size in EMUs.
Examples found in repository?
18fn main() -> office_toolkit::Result<()> {
19 let path = output_path("docx_images_and_charts.docx");
20 let image_bytes = std::fs::read(image_fixture_path())?;
21
22 // 2 inches wide, 1.5 inches tall (914,400 EMU per inch).
23 let image = Image::new(image_bytes, ImageFormat::Png, 1_828_800, 1_371_600)
24 .with_description("Project test image");
25 let chart = EmbeddedChart::new(sample_chart_space(), 4_572_000, 2_743_200)
26 .with_name("Quarterly revenue");
27
28 let document = Document::new()
29 .with_paragraph(heading("An inline image", false))
30 .with_paragraph(Paragraph::new().with_run(Run::with_image(image)))
31 .with_paragraph(heading("An embedded bar chart", true))
32 .with_paragraph(Paragraph::new().with_run(Run::with_chart(chart)));
33
34 document.save_to_file(&path)?;
35 println!("Wrote {}", path.display());
36 Ok(())
37}Sourcepub fn with_name(self, name: impl Into<String>) -> EmbeddedChart
pub fn with_name(self, name: impl Into<String>) -> EmbeddedChart
Sets the chart’s alt text / name and returns it for chaining.
Examples found in repository?
18fn main() -> office_toolkit::Result<()> {
19 let path = output_path("docx_images_and_charts.docx");
20 let image_bytes = std::fs::read(image_fixture_path())?;
21
22 // 2 inches wide, 1.5 inches tall (914,400 EMU per inch).
23 let image = Image::new(image_bytes, ImageFormat::Png, 1_828_800, 1_371_600)
24 .with_description("Project test image");
25 let chart = EmbeddedChart::new(sample_chart_space(), 4_572_000, 2_743_200)
26 .with_name("Quarterly revenue");
27
28 let document = Document::new()
29 .with_paragraph(heading("An inline image", false))
30 .with_paragraph(Paragraph::new().with_run(Run::with_image(image)))
31 .with_paragraph(heading("An embedded bar chart", true))
32 .with_paragraph(Paragraph::new().with_run(Run::with_chart(chart)));
33
34 document.save_to_file(&path)?;
35 println!("Wrote {}", path.display());
36 Ok(())
37}Trait Implementations§
Source§impl Clone for EmbeddedChart
impl Clone for EmbeddedChart
Source§fn clone(&self) -> EmbeddedChart
fn clone(&self) -> EmbeddedChart
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more