bokuweb / docx-rs

:memo: A .docx file writer with Rust/WebAssembly.
https://bokuweb.github.io/docx-rs/
MIT License
341 stars 59 forks source link

Macros for commonly created objects #615

Open Ciubix8513 opened 1 year ago

Ciubix8513 commented 1 year ago

Is your feature request related to a problem? Please describe.

It is quite a pain to create things like paragraphs or table cells. For example if you need to create a bunch of paragraphs you have to do Paragraph::new().add_run(Run::new().add_text("Text")); over and over again

Describe the solution you'd like

It would be great if there were macros for that. For example, here's my macro for creating a paragraph:

#[macro_export]
macro_rules! paragraph {
    ($text:expr) => {
        paragraph!($text, AlignmentType::Center)
    };
    ($text:expr,$align:expr) => {
        Paragraph::new()
            .add_run(Run::new().add_text($text))
            .align($align)
    };
}

With this macro i can just do paragraph!("Text"); which is just so much nicer