Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numbering parsing #791

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix numbering parsing #791

wants to merge 1 commit into from

Conversation

sxhxliang
Copy link

What does this change?

fix #759

References

fix #759

What can I check for bug fixes?

use docx_rs::*;
use std::io::{Read, Write};
pub fn main() -> Result<(), DocxError> {
    let path = std::path::Path::new("./numbering.docx");
    let file = std::fs::File::create(path).unwrap();
    Docx::new()
        .add_paragraph(
            Paragraph::new()
                .add_run(Run::new().add_text("Hello"))
                .numbering(NumberingId::new(2), IndentLevel::new(0)),
        )
        .add_abstract_numbering(
            AbstractNumbering::new(2).add_level(
                Level::new(
                    0,
                    Start::new(1),
                    NumberFormat::new("decimal"),
                    LevelText::new("Section %1."),
                    LevelJc::new("left"),
                )
                .indent(
                    Some(1620),
                    Some(SpecialIndentType::Hanging(320)),
                    None,
                    None,
                ),
            ),
        )
        .add_numbering(Numbering::new(2, 2))
        .build()
        .pack(file)?;


    // read file
    let mut file = std::fs::File::open("./numbering.docx").unwrap();
    let mut buf = vec![];
    file.read_to_end(&mut buf).unwrap();
    let docx_copy = read_docx(&buf).unwrap();

    // pack file
    let path = std::path::Path::new("./numbering_copy.docx");
    let file = std::fs::File::create(path).unwrap();
    docx_copy.build().pack(file)?;

    Ok(())

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There is a problem with numbering parsing when reading the document
1 participant