Define header footer (#678)

* chore: define header and footer json properties

* fix: some errors
main
bokuweb 2024-02-09 21:04:42 +09:00 committed by GitHub
parent 5799884862
commit 179e69959b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
46 changed files with 135 additions and 85 deletions

View File

@ -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()

View File

@ -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(

View File

@ -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")))

View File

@ -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()

View File

@ -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")

View File

@ -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", "<root xmlns=\"https://exampple.com\"><item name=\"Cheap Item\" price=\"$193.95\"/><item name=\"Expensive Item\" price=\"$931.88\"/></root>")

View File

@ -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()

View File

@ -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")

View File

@ -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")

View File

@ -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 =

View File

@ -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 =

View File

@ -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(

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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")),

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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),

View File

@ -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()

View File

@ -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()

View File

@ -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(

View File

@ -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()

View File

@ -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)

View File

@ -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")

View File

@ -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"))

View File

@ -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())

View File

@ -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![

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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(

View File

@ -13,9 +13,9 @@ pub enum DeleteInstrText {
Unsupported(String),
}
impl BuildXML for Box<DeleteInstrText> {
impl BuildXML for DeleteInstrText {
fn build(&self) -> Vec<u8> {
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<DeleteInstrText> {
}
}
impl BuildXML for Box<DeleteInstrText> {
fn build(&self) -> Vec<u8> {
self.as_ref().build()
}
}
impl Serialize for DeleteInstrText {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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#"<w:delInstrText>TOC \o &quot;1-3&quot;</w:delInstrText>"#

View File

@ -56,6 +56,12 @@ impl Drawing {
}
impl BuildXML for Box<Drawing> {
fn build(&self) -> Vec<u8> {
self.as_ref().build()
}
}
impl BuildXML for Drawing {
fn build(&self) -> Vec<u8> {
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#"<w:drawing>
@ -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#"<w:drawing>
@ -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#"<w:drawing>

View File

@ -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(

View File

@ -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();
}

View File

@ -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;
};

View File

@ -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;
};

View File

@ -59,6 +59,7 @@ export type SettingsJSON = {
defaultTabStop: number;
adjustLineHeightInTable: boolean;
characterSpacingControl?: CharacterSpacingValues | null;
evenAndOddHeaders: boolean;
zoom: number;
docVars: { name: string; val: string }[];
};

View File

@ -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;
};