Skip to main content

RichTextRun

Struct RichTextRun 

Source
pub struct RichTextRun {
    pub text: String,
    pub bold: bool,
    pub italic: bool,
    pub font_color: Option<String>,
    pub font_size: Option<f64>,
    pub font_name: Option<String>,
    pub underline: bool,
    pub strike: bool,
}
Expand description

One run of a CellValue::RichText value: a span of text sharing the same character formatting (<r><rPr>..</rPr><t>..</t></r>, CT_RElt) — a deliberately scoped-down subset of CT_RPrElt’s full run-property surface (bold/italic/color/size only, same subset CellFormat’s own font fields already cover; underline/strike/ vertical-align/font-family are not modeled).

Fields§

§text: String§bold: bool§italic: bool§font_color: Option<String>

The run’s font color, as an 8-hex-digit ARGB string.

§font_size: Option<f64>

The run’s font size, in points.

§font_name: Option<String>

The run’s font name/family (e.g. "Calibri").

§underline: bool

Underline (plain single underline only, same posture as CellFormat::underline).

§strike: bool

Strikethrough.

Implementations§

Source§

impl RichTextRun

Source

pub fn new(text: impl Into<String>) -> RichTextRun

Creates a plain (no formatting) run.

Examples found in repository?
examples/xlsx_rich_data.rs (line 59)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_bold(self, bold: bool) -> RichTextRun

Sets bold and returns the run for chaining.

Examples found in repository?
examples/xlsx_rich_data.rs (line 59)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_italic(self, italic: bool) -> RichTextRun

Sets italic and returns the run for chaining.

Examples found in repository?
examples/xlsx_rich_data.rs (line 60)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_font_color(self, color: impl Into<String>) -> RichTextRun

Sets the font color (8-hex-digit ARGB) and returns the run for chaining.

Examples found in repository?
examples/xlsx_rich_data.rs (line 59)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_font_size(self, size: f64) -> RichTextRun

Sets the font size, in points, and returns the run for chaining.

Source

pub fn with_font_name(self, font_name: impl Into<String>) -> RichTextRun

Sets the font name/family and returns the run for chaining.

Source

pub fn with_underline(self, underline: bool) -> RichTextRun

Sets underline and returns the run for chaining.

Source

pub fn with_strike(self, strike: bool) -> RichTextRun

Sets strikethrough and returns the run for chaining.

Trait Implementations§

Source§

impl Clone for RichTextRun

Source§

fn clone(&self) -> RichTextRun

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RichTextRun

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RichTextRun

Source§

fn eq(&self, other: &RichTextRun) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RichTextRun

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.