From 179e69959bbf5d9df6cb581ea8b629582cc9e8c3 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Fri, 9 Feb 2024 21:04:42 +0900 Subject: [PATCH] Define header footer (#678) * chore: define header and footer json properties * fix: some errors --- README.md | 2 +- docx-core/examples/alignment.rs | 2 +- docx-core/examples/bookmark.rs | 2 +- docx-core/examples/comment.rs | 2 +- docx-core/examples/custom_property.rs | 2 +- docx-core/examples/custom_xml.rs | 2 +- docx-core/examples/data_binding.rs | 2 +- docx-core/examples/dirty_toc.rs | 2 +- docx-core/examples/doc_id.rs | 2 +- docx-core/examples/even_header.rs | 2 +- docx-core/examples/first_header.rs | 2 +- docx-core/examples/font.rs | 2 +- docx-core/examples/font_size.rs | 2 +- docx-core/examples/footer.rs | 2 +- docx-core/examples/header.rs | 2 +- docx-core/examples/hello.rs | 2 +- docx-core/examples/history.rs | 2 +- docx-core/examples/hyperlink.rs | 2 +- docx-core/examples/image_floating.rs | 2 +- docx-core/examples/image_inline.rs | 2 +- docx-core/examples/image_inline_rotate.rs | 2 +- docx-core/examples/indent.rs | 2 +- docx-core/examples/nested_comment.rs | 2 +- docx-core/examples/numbering.rs | 2 +- docx-core/examples/outline_lvl.rs | 2 +- docx-core/examples/page_margin.rs | 2 +- docx-core/examples/page_size.rs | 2 +- docx-core/examples/sdt.rs | 2 +- docx-core/examples/style.rs | 2 +- docx-core/examples/table.rs | 2 +- docx-core/examples/table_border.rs | 2 +- docx-core/examples/toc_simple.rs | 2 +- docx-core/examples/toc_with_comment.rs | 2 +- docx-core/examples/toc_with_hyperlink.rs | 2 +- docx-core/examples/toc_with_item.rs | 2 +- docx-core/examples/toc_with_style_level.rs | 2 +- docx-core/examples/toc_with_tc.rs | 2 +- docx-core/examples/web_ext.rs | 2 +- .../documents/elements/delete_instr_text.rs | 15 ++++--- docx-core/src/documents/elements/drawing.rs | 12 ++++-- docx-core/tests/lib.rs | 40 +++++++++---------- docx-core/tests/reader.rs | 36 ++++++++--------- docx-wasm/js/json/footer.ts | 11 +++++ docx-wasm/js/json/header.ts | 11 +++++ docx-wasm/js/json/index.ts | 1 + docx-wasm/js/json/section-property.ts | 18 +++++++++ 46 files changed, 135 insertions(+), 85 deletions(-) create mode 100644 docx-wasm/js/json/footer.ts create mode 100644 docx-wasm/js/json/header.ts diff --git a/README.md b/README.md index 8ad39f6..1aedd8e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ use docx_rs::*; pub fn hello() -> Result<(), DocxError> { let path = std::path::Path::new("./hello.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .build() diff --git a/docx-core/examples/alignment.rs b/docx-core/examples/alignment.rs index ddc62db..004743c 100644 --- a/docx-core/examples/alignment.rs +++ b/docx-core/examples/alignment.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./alignment.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .add_paragraph( diff --git a/docx-core/examples/bookmark.rs b/docx-core/examples/bookmark.rs index 84fe01b..c18f569 100644 --- a/docx-core/examples/bookmark.rs +++ b/docx-core/examples/bookmark.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/bookmark.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_bookmark_start(1, "hello") .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) diff --git a/docx-core/examples/comment.rs b/docx-core/examples/comment.rs index e469f2c..6718fa3 100644 --- a/docx-core/examples/comment.rs +++ b/docx-core/examples/comment.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/comment.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() diff --git a/docx-core/examples/custom_property.rs b/docx-core/examples/custom_property.rs index cd7b11e..9851249 100644 --- a/docx-core/examples/custom_property.rs +++ b/docx-core/examples/custom_property.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/custom_property.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .custom_property("hello", "world") diff --git a/docx-core/examples/custom_xml.rs b/docx-core/examples/custom_xml.rs index 8cb6906..b49f09e 100644 --- a/docx-core/examples/custom_xml.rs +++ b/docx-core/examples/custom_xml.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/custom_xml.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .add_custom_item("06AC5857-5C65-A94A-BCEC-37356A209BC3", "") diff --git a/docx-core/examples/data_binding.rs b/docx-core/examples/data_binding.rs index 842db3c..9b2bb13 100644 --- a/docx-core/examples/data_binding.rs +++ b/docx-core/examples/data_binding.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/data_binding.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() diff --git a/docx-core/examples/dirty_toc.rs b/docx-core/examples/dirty_toc.rs index c32be95..af81a74 100644 --- a/docx-core/examples/dirty_toc.rs +++ b/docx-core/examples/dirty_toc.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/dirty_toc.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("Hello")) .style("Heading1") diff --git a/docx-core/examples/doc_id.rs b/docx-core/examples/doc_id.rs index da3fd27..9ada1f4 100644 --- a/docx-core/examples/doc_id.rs +++ b/docx-core/examples/doc_id.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/doc_id.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("World"))) .doc_id("2F0CF1F9-607F-5941-BF59-8A81BE87AAAA") diff --git a/docx-core/examples/even_header.rs b/docx-core/examples/even_header.rs index 4544a18..58f2a3e 100644 --- a/docx-core/examples/even_header.rs +++ b/docx-core/examples/even_header.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/even_header.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let header = Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))); let even_header = diff --git a/docx-core/examples/first_header.rs b/docx-core/examples/first_header.rs index c9549cb..728fb98 100644 --- a/docx-core/examples/first_header.rs +++ b/docx-core/examples/first_header.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/first_header.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let header = Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))); let first_header = diff --git a/docx-core/examples/font.rs b/docx-core/examples/font.rs index 81742e7..d4e5f82 100644 --- a/docx-core/examples/font.rs +++ b/docx-core/examples/font.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./font.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new().add_run( diff --git a/docx-core/examples/font_size.rs b/docx-core/examples/font_size.rs index 86e1a18..4bd7b8e 100644 --- a/docx-core/examples/font_size.rs +++ b/docx-core/examples/font_size.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/font_size.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello").size(24))) .build() diff --git a/docx-core/examples/footer.rs b/docx-core/examples/footer.rs index 48ee0df..7ed6a83 100644 --- a/docx-core/examples/footer.rs +++ b/docx-core/examples/footer.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/footer.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let footer = Footer::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))); Docx::new() diff --git a/docx-core/examples/header.rs b/docx-core/examples/header.rs index b62bec1..b992097 100644 --- a/docx-core/examples/header.rs +++ b/docx-core/examples/header.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/header.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let header = Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))); Docx::new() diff --git a/docx-core/examples/hello.rs b/docx-core/examples/hello.rs index 9a7f104..b6ef6b0 100644 --- a/docx-core/examples/hello.rs +++ b/docx-core/examples/hello.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/hello.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .build() diff --git a/docx-core/examples/history.rs b/docx-core/examples/history.rs index 6739e1e..61b88dd 100644 --- a/docx-core/examples/history.rs +++ b/docx-core/examples/history.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./history.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() diff --git a/docx-core/examples/hyperlink.rs b/docx-core/examples/hyperlink.rs index 33347fb..bad189c 100644 --- a/docx-core/examples/hyperlink.rs +++ b/docx-core/examples/hyperlink.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/hyperlink.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_hyperlink( Hyperlink::new("anchor", HyperlinkType::Anchor).add_run(Run::new().add_text("Hello")), diff --git a/docx-core/examples/image_floating.rs b/docx-core/examples/image_floating.rs index b982408..c658a77 100644 --- a/docx-core/examples/image_floating.rs +++ b/docx-core/examples/image_floating.rs @@ -5,7 +5,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/image_floating.docx"); - let file = File::create(&path).unwrap(); + let file = File::create(path).unwrap(); let mut img = File::open("./images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); let _ = img.read_to_end(&mut buf).unwrap(); diff --git a/docx-core/examples/image_inline.rs b/docx-core/examples/image_inline.rs index 48bf31d..7de301e 100644 --- a/docx-core/examples/image_inline.rs +++ b/docx-core/examples/image_inline.rs @@ -5,7 +5,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/image_inline.docx"); - let file = File::create(&path).unwrap(); + let file = File::create(path).unwrap(); let mut img = File::open("./images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); let _ = img.read_to_end(&mut buf).unwrap(); diff --git a/docx-core/examples/image_inline_rotate.rs b/docx-core/examples/image_inline_rotate.rs index a855271..33ab84c 100644 --- a/docx-core/examples/image_inline_rotate.rs +++ b/docx-core/examples/image_inline_rotate.rs @@ -5,7 +5,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/image_inline_rotate.docx"); - let file = File::create(&path).unwrap(); + let file = File::create(path).unwrap(); let mut img = File::open("./images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); let _ = img.read_to_end(&mut buf).unwrap(); diff --git a/docx-core/examples/indent.rs b/docx-core/examples/indent.rs index 7f5a10e..ea29b75 100644 --- a/docx-core/examples/indent.rs +++ b/docx-core/examples/indent.rs @@ -4,7 +4,7 @@ pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/indent.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text(DUMMY)).indent( Some(840), diff --git a/docx-core/examples/nested_comment.rs b/docx-core/examples/nested_comment.rs index c3f2ab1..0e36ab3 100644 --- a/docx-core/examples/nested_comment.rs +++ b/docx-core/examples/nested_comment.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/nested_comment.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() diff --git a/docx-core/examples/numbering.rs b/docx-core/examples/numbering.rs index b1cd557..e235fd3 100644 --- a/docx-core/examples/numbering.rs +++ b/docx-core/examples/numbering.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./numbering.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() diff --git a/docx-core/examples/outline_lvl.rs b/docx-core/examples/outline_lvl.rs index 1791d16..41f8538 100644 --- a/docx-core/examples/outline_lvl.rs +++ b/docx-core/examples/outline_lvl.rs @@ -2,7 +2,7 @@ use docx_rs::*; fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./outlineLvl.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( diff --git a/docx-core/examples/page_margin.rs b/docx-core/examples/page_margin.rs index 5adb465..ab81f37 100644 --- a/docx-core/examples/page_margin.rs +++ b/docx-core/examples/page_margin.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/page_margin.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .build() diff --git a/docx-core/examples/page_size.rs b/docx-core/examples/page_size.rs index a0b2d64..5e46e31 100644 --- a/docx-core/examples/page_size.rs +++ b/docx-core/examples/page_size.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/page_size.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .page_size(200, 400) diff --git a/docx-core/examples/sdt.rs b/docx-core/examples/sdt.rs index 1bfdf35..5019c58 100644 --- a/docx-core/examples/sdt.rs +++ b/docx-core/examples/sdt.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/sdt.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p = Paragraph::new().add_run( Run::new() .add_text("Hello") diff --git a/docx-core/examples/style.rs b/docx-core/examples/style.rs index a3de126..ae53070 100644 --- a/docx-core/examples/style.rs +++ b/docx-core/examples/style.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/style.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("Hello").style("Run1")) diff --git a/docx-core/examples/table.rs b/docx-core/examples/table.rs index f1d04f8..453d50e 100644 --- a/docx-core/examples/table.rs +++ b/docx-core/examples/table.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./table.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![TableRow::new(vec![ TableCell::new().add_paragraph(Paragraph::new()) diff --git a/docx-core/examples/table_border.rs b/docx-core/examples/table_border.rs index d3a3b67..607412c 100644 --- a/docx-core/examples/table_border.rs +++ b/docx-core/examples/table_border.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./table_border.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![ TableRow::new(vec![ diff --git a/docx-core/examples/toc_simple.rs b/docx-core/examples/toc_simple.rs index 25b0c13..8bf647b 100644 --- a/docx-core/examples/toc_simple.rs +++ b/docx-core/examples/toc_simple.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/toc_simple.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("!!Hello")) .style("Heading1") diff --git a/docx-core/examples/toc_with_comment.rs b/docx-core/examples/toc_with_comment.rs index 09496f0..5179426 100644 --- a/docx-core/examples/toc_with_comment.rs +++ b/docx-core/examples/toc_with_comment.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/toc_with_comment.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("!!Hello")) .style("Heading1") diff --git a/docx-core/examples/toc_with_hyperlink.rs b/docx-core/examples/toc_with_hyperlink.rs index 544b906..2569369 100644 --- a/docx-core/examples/toc_with_hyperlink.rs +++ b/docx-core/examples/toc_with_hyperlink.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/toc_with_hyperlink.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("Hello")) .style("Heading1") diff --git a/docx-core/examples/toc_with_item.rs b/docx-core/examples/toc_with_item.rs index 0041db2..b374e34 100644 --- a/docx-core/examples/toc_with_item.rs +++ b/docx-core/examples/toc_with_item.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/toc_with_item.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("Hello")) .style("Heading1") diff --git a/docx-core/examples/toc_with_style_level.rs b/docx-core/examples/toc_with_style_level.rs index a007463..6126a0c 100644 --- a/docx-core/examples/toc_with_style_level.rs +++ b/docx-core/examples/toc_with_style_level.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/examples/toc_with_style_level.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let style1 = Style::new("Heading1", StyleType::Paragraph).name("Heading 1"); let style2 = Style::new("StyleLevel1", StyleType::Paragraph) diff --git a/docx-core/examples/toc_with_tc.rs b/docx-core/examples/toc_with_tc.rs index e5ca0f4..26a7eb0 100644 --- a/docx-core/examples/toc_with_tc.rs +++ b/docx-core/examples/toc_with_tc.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/toc_with_tc.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let p1 = Paragraph::new() .add_run(Run::new().add_text("Hello")) .style("Heading1") diff --git a/docx-core/examples/web_ext.rs b/docx-core/examples/web_ext.rs index 9f69bce..774ec3c 100644 --- a/docx-core/examples/web_ext.rs +++ b/docx-core/examples/web_ext.rs @@ -2,7 +2,7 @@ use docx_rs::*; pub fn main() -> Result<(), DocxError> { let path = std::path::Path::new("./output/web_ext.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .taskpanes() .web_extension( diff --git a/docx-core/src/documents/elements/delete_instr_text.rs b/docx-core/src/documents/elements/delete_instr_text.rs index c12dfb1..408e8a6 100644 --- a/docx-core/src/documents/elements/delete_instr_text.rs +++ b/docx-core/src/documents/elements/delete_instr_text.rs @@ -13,9 +13,9 @@ pub enum DeleteInstrText { Unsupported(String), } -impl BuildXML for Box { +impl BuildXML for DeleteInstrText { fn build(&self) -> Vec { - let instr = match self.as_ref() { + let instr = match self { DeleteInstrText::TOC(toc) => toc.build(), DeleteInstrText::TC(tc) => tc.build(), DeleteInstrText::PAGEREF(page_ref) => page_ref.build(), @@ -30,6 +30,12 @@ impl BuildXML for Box { } } +impl BuildXML for Box { + fn build(&self) -> Vec { + self.as_ref().build() + } +} + impl Serialize for DeleteInstrText { fn serialize(&self, serializer: S) -> Result where @@ -80,10 +86,7 @@ mod tests { #[test] fn test_delete_toc_instr() { - let b = Box::new(DeleteInstrText::TOC( - InstrToC::new().heading_styles_range(1, 3), - )) - .build(); + let b = DeleteInstrText::TOC(InstrToC::new().heading_styles_range(1, 3)).build(); assert_eq!( str::from_utf8(&b).unwrap(), r#"TOC \o "1-3""# diff --git a/docx-core/src/documents/elements/drawing.rs b/docx-core/src/documents/elements/drawing.rs index 665b9da..6cfb371 100644 --- a/docx-core/src/documents/elements/drawing.rs +++ b/docx-core/src/documents/elements/drawing.rs @@ -56,6 +56,12 @@ impl Drawing { } impl BuildXML for Box { + fn build(&self) -> Vec { + self.as_ref().build() + } +} + +impl BuildXML for Drawing { fn build(&self) -> Vec { let b = XMLBuilder::new(); let mut b = b.open_drawing(); @@ -161,7 +167,7 @@ mod tests { let mut img = std::fs::File::open("../images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); let _ = img.read_to_end(&mut buf).unwrap(); - let d = Box::new(Drawing::new().pic(Pic::new(&buf))).build(); + let d = Drawing::new().pic(Pic::new(&buf)).build(); assert_eq!( str::from_utf8(&d).unwrap(), r#" @@ -210,7 +216,7 @@ mod tests { let mut img = std::fs::File::open("../images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); let _ = img.read_to_end(&mut buf).unwrap(); - let d = Box::new(Drawing::new().pic(Pic::new(&buf).overlapping())).build(); + let d = Drawing::new().pic(Pic::new(&buf).overlapping()).build(); assert_eq!( str::from_utf8(&d).unwrap(), r#" @@ -264,7 +270,7 @@ mod tests { pic = pic.relative_from_h(RelativeFromHType::Column); pic = pic.relative_from_v(RelativeFromVType::Paragraph); pic = pic.position_h(DrawingPosition::Align(PicAlign::Right)); - let d = Box::new(Drawing::new().pic(pic)).build(); + let d = Drawing::new().pic(pic).build(); assert_eq!( str::from_utf8(&d).unwrap(), r#" diff --git a/docx-core/tests/lib.rs b/docx-core/tests/lib.rs index 9772da1..a606288 100644 --- a/docx-core/tests/lib.rs +++ b/docx-core/tests/lib.rs @@ -9,7 +9,7 @@ pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit #[test] pub fn hello() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/hello.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .build() @@ -20,7 +20,7 @@ pub fn hello() -> Result<(), DocxError> { #[test] pub fn indent() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/indent.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text(DUMMY)).indent( Some(840), @@ -50,7 +50,7 @@ pub fn indent() -> Result<(), DocxError> { #[test] pub fn size() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/size.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello").size(60))) .add_paragraph( @@ -66,7 +66,7 @@ pub fn size() -> Result<(), DocxError> { #[test] pub fn alignment() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/alignment.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .add_paragraph( @@ -82,7 +82,7 @@ pub fn alignment() -> Result<(), DocxError> { #[test] pub fn table() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/table.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![ TableRow::new(vec![ @@ -101,7 +101,7 @@ pub fn table() -> Result<(), DocxError> { #[test] pub fn table_with_grid() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/table_with_grid.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![ TableRow::new(vec![ @@ -121,7 +121,7 @@ pub fn table_with_grid() -> Result<(), DocxError> { #[test] pub fn table_merged() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/table_merged.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![ TableRow::new(vec![ @@ -159,7 +159,7 @@ pub fn table_merged() -> Result<(), DocxError> { #[test] pub fn decoration() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/decoration.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -189,7 +189,7 @@ pub fn decoration() -> Result<(), DocxError> { #[test] pub fn tab_and_break() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/tab_and_break.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new().add_run( @@ -209,7 +209,7 @@ pub fn tab_and_break() -> Result<(), DocxError> { #[test] pub fn history() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/history.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -228,7 +228,7 @@ pub fn history() -> Result<(), DocxError> { #[test] pub fn underline() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/underline.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello").underline("single"))) .build() @@ -239,7 +239,7 @@ pub fn underline() -> Result<(), DocxError> { #[test] pub fn highlight() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/highlight.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -254,7 +254,7 @@ pub fn highlight() -> Result<(), DocxError> { #[test] pub fn comments() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/comments.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -276,7 +276,7 @@ pub fn comments() -> Result<(), DocxError> { #[test] pub fn comments_to_table() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/comments_table.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let table = Table::new(vec![TableRow::new(vec![ TableCell::new().add_paragraph( Paragraph::new() @@ -312,7 +312,7 @@ pub fn comments_to_table() -> Result<(), DocxError> { #[test] pub fn default_numbering() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/default_numbering.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -342,7 +342,7 @@ pub fn default_numbering() -> Result<(), DocxError> { #[test] pub fn user_numbering() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/user_numbering.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -375,7 +375,7 @@ pub fn user_numbering() -> Result<(), DocxError> { #[test] pub fn escape() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/escape.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -390,7 +390,7 @@ pub fn escape() -> Result<(), DocxError> { #[test] pub fn vanish() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/vanish.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( Paragraph::new() @@ -406,7 +406,7 @@ pub fn vanish() -> Result<(), DocxError> { #[test] pub fn date() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/date.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))) .created_at("2019-01-01T00:00:00Z") @@ -419,7 +419,7 @@ pub fn date() -> Result<(), DocxError> { #[test] pub fn line_spacing() -> Result<(), DocxError> { let path = std::path::Path::new("./tests/output/line_spacing.docx"); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); Docx::new() .add_paragraph( diff --git a/docx-core/tests/reader.rs b/docx-core/tests/reader.rs index 9d15c00..835fc32 100644 --- a/docx-core/tests/reader.rs +++ b/docx-core/tests/reader.rs @@ -14,7 +14,7 @@ pub fn read_hello() { assert_json_snapshot!("read_hello", &json); let path = std::path::Path::new("./tests/output/hello.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -29,7 +29,7 @@ pub fn read_numbering() { assert_json_snapshot!("read_numbering", &json); let path = std::path::Path::new("./tests/output/numbering.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -44,7 +44,7 @@ pub fn read_decoration() { assert_json_snapshot!("read_decoration", &json); let path = std::path::Path::new("./tests/output/decoration.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -60,7 +60,7 @@ pub fn read_highlight_and_underline() { assert_json_snapshot!("read_highlight_and_underline", &json); let path = std::path::Path::new("./tests/output/highlight_and_underline.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -75,7 +75,7 @@ pub fn read_history() { assert_json_snapshot!("read_history", &json); let path = std::path::Path::new("./tests/output/history.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -90,7 +90,7 @@ pub fn read_indent_word_online() { assert_json_snapshot!("read_indent_word_online", &json); let path = std::path::Path::new("./tests/output/indent_word_online.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -105,7 +105,7 @@ pub fn read_tab_and_break() { assert_json_snapshot!("read_tab_and_break", &json); let path = std::path::Path::new("./tests/output/tab_and_break.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -120,7 +120,7 @@ pub fn read_table_docx() { assert_json_snapshot!("read_table_docx", &json); let path = std::path::Path::new("./tests/output/table_docx.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -135,7 +135,7 @@ pub fn read_table_merged_libre_office() { assert_json_snapshot!("read_table_merged_libre_office", &json); let path = std::path::Path::new("./tests/output/table_merged_libre_office.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -150,7 +150,7 @@ pub fn read_bom() { assert_json_snapshot!("read_bom", &json); let path = std::path::Path::new("./tests/output/bom.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -165,7 +165,7 @@ pub fn read_bookmark() { assert_json_snapshot!("read_bookmark", &json); let path = std::path::Path::new("./tests/output/bookmark.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -180,7 +180,7 @@ pub fn read_insert_table() { assert_json_snapshot!("read_insert_table", &json); let path = std::path::Path::new("./tests/output/insert_table.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -195,7 +195,7 @@ pub fn read_textbox() { assert_json_snapshot!("read_textbox", &json); let path = std::path::Path::new("./tests/output/textbox.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -210,7 +210,7 @@ pub fn read_from_doc() { assert_json_snapshot!("read_from_doc", &json); let path = std::path::Path::new("./tests/output/from_doc.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -225,7 +225,7 @@ pub fn read_lvl_override() { assert_json_snapshot!("read_lvl_override", &json); let path = std::path::Path::new("./tests/output/lvl_override.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -240,7 +240,7 @@ pub fn read_comment() { assert_json_snapshot!("read_comment", &json); let path = std::path::Path::new("./tests/output/comment.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -255,7 +255,7 @@ pub fn read_extended_comment() { assert_json_snapshot!("read_extended_comments", &json); let path = std::path::Path::new("./tests/output/extended_comments.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } @@ -270,7 +270,7 @@ pub fn read_line_spacing() { assert_json_snapshot!("line_spacing", &json); let path = std::path::Path::new("./tests/output/line_spacing.json"); - let mut file = std::fs::File::create(&path).unwrap(); + let mut file = std::fs::File::create(path).unwrap(); file.write_all(json.as_bytes()).unwrap(); file.flush().unwrap(); } diff --git a/docx-wasm/js/json/footer.ts b/docx-wasm/js/json/footer.ts new file mode 100644 index 0000000..52aefe8 --- /dev/null +++ b/docx-wasm/js/json/footer.ts @@ -0,0 +1,11 @@ +import { ParagraphJSON } from "./paragraph"; +import { TableJSON } from "./table"; + +export type FooterJSON = { + children: (ParagraphJSON | TableJSON)[]; +}; + +export type FooterReferenceJSON = { + footerType: string; + id: string; +}; diff --git a/docx-wasm/js/json/header.ts b/docx-wasm/js/json/header.ts new file mode 100644 index 0000000..213af05 --- /dev/null +++ b/docx-wasm/js/json/header.ts @@ -0,0 +1,11 @@ +import { ParagraphJSON } from "./paragraph"; +import { TableJSON } from "./table"; + +export type HeaderJSON = { + children: (ParagraphJSON | TableJSON)[]; +}; + +export type HeaderReferenceJSON = { + headerType: string; + id: string; +}; diff --git a/docx-wasm/js/json/index.ts b/docx-wasm/js/json/index.ts index 57b22eb..3849455 100644 --- a/docx-wasm/js/json/index.ts +++ b/docx-wasm/js/json/index.ts @@ -59,6 +59,7 @@ export type SettingsJSON = { defaultTabStop: number; adjustLineHeightInTable: boolean; characterSpacingControl?: CharacterSpacingValues | null; + evenAndOddHeaders: boolean; zoom: number; docVars: { name: string; val: string }[]; }; diff --git a/docx-wasm/js/json/section-property.ts b/docx-wasm/js/json/section-property.ts index 0d48ac4..0fb4c4c 100644 --- a/docx-wasm/js/json/section-property.ts +++ b/docx-wasm/js/json/section-property.ts @@ -1,3 +1,6 @@ +import { HeaderJSON, HeaderReferenceJSON } from "./header"; +import { FooterJSON, FooterReferenceJSON } from "./footer"; + export type DocGridType = "default" | "lines" | "linesAndChars" | "snapToChars"; export type SectionType = @@ -30,4 +33,19 @@ export type SectionPropertyJSON = { columns: number; docGrid?: DocGridJSON; sectionType?: SectionType; + titlePg?: boolean; + // header + headerReference?: HeaderReferenceJSON; + header?: HeaderJSON; + firstHeaderReference?: HeaderReferenceJSON; + firstHeader?: HeaderJSON; + eventHeaderReference?: HeaderReferenceJSON; + eventHeader?: HeaderJSON; + // footer + footerReference?: FooterReferenceJSON; + footer?: FooterJSON; + firstFooterReference?: FooterReferenceJSON; + firstFooter?: FooterJSON; + eventFooterReference?: FooterReferenceJSON; + eventFooter?: FooterJSON; };