impl first and even header/footer with rust/JS (#374)
* fix: header structure * fix: footer structure * fix: Support first and even header / footer with rust * fix: Support js interface * fix: testmain
parent
6c1d4a99d6
commit
8c9bb7b72d
|
@ -0,0 +1,17 @@
|
|||
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 header =
|
||||
Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")));
|
||||
let even_header =
|
||||
Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Even")));
|
||||
Docx::new()
|
||||
.header(header)
|
||||
.even_header(even_header)
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("World")))
|
||||
.build()
|
||||
.pack(file)?;
|
||||
Ok(())
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
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 header =
|
||||
Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")));
|
||||
let first_header =
|
||||
Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_text("First")));
|
||||
Docx::new()
|
||||
.header(header)
|
||||
.first_header(first_header)
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("World")))
|
||||
.build()
|
||||
.pack(file)?;
|
||||
Ok(())
|
||||
}
|
|
@ -150,13 +150,33 @@ impl Document {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn header_reference(mut self, r: HeaderReference) -> Self {
|
||||
self.section_property = self.section_property.header_reference(r);
|
||||
pub fn header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.header(h, rid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer_reference(mut self, r: FooterReference) -> Self {
|
||||
self.section_property = self.section_property.footer_reference(r);
|
||||
pub fn first_header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.first_header(h, rid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.even_header(h, rid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.footer(h, rid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.first_footer(h, rid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.section_property = self.section_property.even_footer(h, rid);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,44 @@ use super::*;
|
|||
use crate::documents::BuildXML;
|
||||
use crate::types::*;
|
||||
use crate::xml_builder::*;
|
||||
use crate::{Footer, Header};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SectionProperty {
|
||||
page_size: PageSize,
|
||||
page_margin: PageMargin,
|
||||
columns: usize,
|
||||
doc_grid: DocGrid,
|
||||
header_reference: Option<HeaderReference>,
|
||||
footer_reference: Option<FooterReference>,
|
||||
section_type: Option<SectionType>,
|
||||
pub page_size: PageSize,
|
||||
pub page_margin: PageMargin,
|
||||
pub columns: usize,
|
||||
pub title_pg: bool,
|
||||
pub doc_grid: DocGrid,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub header_reference: Option<HeaderReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub header: Option<Header>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub first_header_reference: Option<HeaderReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub first_header: Option<Header>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub even_header_reference: Option<HeaderReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub even_header: Option<Header>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub footer_reference: Option<FooterReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub footer: Option<Footer>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub first_footer_reference: Option<FooterReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub first_footer: Option<Footer>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub even_footer_reference: Option<FooterReference>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub even_footer: Option<Footer>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub section_type: Option<SectionType>,
|
||||
}
|
||||
|
||||
impl SectionProperty {
|
||||
|
@ -42,15 +67,88 @@ impl SectionProperty {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn header_reference(mut self, r: HeaderReference) -> Self {
|
||||
self.header_reference = Some(r);
|
||||
pub fn title_pg(mut self) -> Self {
|
||||
self.title_pg = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer_reference(mut self, r: FooterReference) -> Self {
|
||||
self.footer_reference = Some(r);
|
||||
pub fn header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.header_reference = Some(HeaderReference::new("default", rid));
|
||||
self.header = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.first_header_reference = Some(HeaderReference::new("first", rid));
|
||||
self.first_header = Some(h);
|
||||
self.title_pg = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_header_without_title_pg(mut self, h: Header, rid: &str) -> Self {
|
||||
self.first_header_reference = Some(HeaderReference::new("first", rid));
|
||||
self.first_header = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_header(mut self, h: Header, rid: &str) -> Self {
|
||||
self.even_header_reference = Some(HeaderReference::new("even", rid));
|
||||
self.even_header = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.footer_reference = Some(FooterReference::new("default", rid));
|
||||
self.footer = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.first_footer_reference = Some(FooterReference::new("first", rid));
|
||||
self.first_footer = Some(h);
|
||||
self.title_pg = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_footer_without_title_pg(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.first_footer_reference = Some(FooterReference::new("first", rid));
|
||||
self.first_footer = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_footer(mut self, h: Footer, rid: &str) -> Self {
|
||||
self.even_footer_reference = Some(FooterReference::new("even", rid));
|
||||
self.even_footer = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_headers(&self) -> Vec<&Header> {
|
||||
let mut headers = vec![];
|
||||
if let Some(ref header) = self.header {
|
||||
headers.push(header);
|
||||
}
|
||||
if let Some(ref header) = self.first_header {
|
||||
headers.push(header);
|
||||
}
|
||||
if let Some(ref header) = self.even_header {
|
||||
headers.push(header);
|
||||
}
|
||||
headers
|
||||
}
|
||||
|
||||
pub fn get_footers(&self) -> Vec<&Footer> {
|
||||
let mut footers = vec![];
|
||||
if let Some(ref footer) = self.footer {
|
||||
footers.push(footer);
|
||||
}
|
||||
if let Some(ref footer) = self.first_footer {
|
||||
footers.push(footer);
|
||||
}
|
||||
if let Some(ref footer) = self.even_footer {
|
||||
footers.push(footer);
|
||||
}
|
||||
footers
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SectionProperty {
|
||||
|
@ -59,9 +157,22 @@ impl Default for SectionProperty {
|
|||
page_size: PageSize::new(),
|
||||
page_margin: PageMargin::new(),
|
||||
columns: 425,
|
||||
title_pg: false,
|
||||
doc_grid: DocGrid::default(),
|
||||
// headers
|
||||
header_reference: None,
|
||||
header: None,
|
||||
first_header_reference: None,
|
||||
first_header: None,
|
||||
even_header_reference: None,
|
||||
even_header: None,
|
||||
// footers
|
||||
footer_reference: None,
|
||||
footer: None,
|
||||
first_footer_reference: None,
|
||||
first_footer: None,
|
||||
even_footer_reference: None,
|
||||
even_footer: None,
|
||||
section_type: None,
|
||||
}
|
||||
}
|
||||
|
@ -77,11 +188,20 @@ impl BuildXML for SectionProperty {
|
|||
.columns(&format!("{}", &self.columns))
|
||||
.add_child(&self.doc_grid)
|
||||
.add_optional_child(&self.header_reference)
|
||||
.add_optional_child(&self.footer_reference);
|
||||
.add_optional_child(&self.first_header_reference)
|
||||
.add_optional_child(&self.even_header_reference)
|
||||
.add_optional_child(&self.footer_reference)
|
||||
.add_optional_child(&self.first_footer_reference)
|
||||
.add_optional_child(&self.even_footer_reference);
|
||||
|
||||
if let Some(t) = self.section_type {
|
||||
b = b.type_tag(&t.to_string());
|
||||
}
|
||||
|
||||
if self.title_pg {
|
||||
b = b.title_pg();
|
||||
}
|
||||
|
||||
b.close().build()
|
||||
}
|
||||
}
|
||||
|
@ -106,11 +226,22 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_section_property_with_footer() {
|
||||
let c = SectionProperty::new().footer_reference(FooterReference::new("default", "rId6"));
|
||||
let c = SectionProperty::new().footer(Footer::new(), "rId6");
|
||||
let b = c.build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:sectPr><w:pgSz w:w="11906" w:h="16838" /><w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0" /><w:cols w:space="425" /><w:docGrid w:type="lines" w:linePitch="360" /><w:footerReference w:type="default" r:id="rId6" /></w:sectPr>"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_section_property_with_title_pf() {
|
||||
let c = SectionProperty::new().title_pg();
|
||||
let b = c.build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:sectPr><w:pgSz w:w="11906" w:h="16838" /><w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0" /><w:cols w:space="425" /><w:docGrid w:type="lines" w:linePitch="360" /><w:titlePg />
|
||||
</w:sectPr>"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,8 +75,6 @@ pub struct Docx {
|
|||
pub settings: Settings,
|
||||
pub font_table: FontTable,
|
||||
pub media: Vec<(usize, Vec<u8>)>,
|
||||
pub header: Option<Header>,
|
||||
pub footer: Option<Footer>,
|
||||
pub comments_extended: CommentsExtended,
|
||||
pub web_settings: WebSettings,
|
||||
pub taskpanes: Option<Taskpanes>,
|
||||
|
@ -115,8 +113,6 @@ impl Default for Docx {
|
|||
settings,
|
||||
font_table,
|
||||
media,
|
||||
header: None,
|
||||
footer: None,
|
||||
comments_extended,
|
||||
web_settings,
|
||||
taskpanes: None,
|
||||
|
@ -217,39 +213,87 @@ impl Docx {
|
|||
|
||||
pub fn header(mut self, header: Header) -> Self {
|
||||
if header.has_numbering {
|
||||
// If this document has numbering, set numberings.xml to document_rels.
|
||||
// This is because numberings.xml without numbering cause an error on word online.
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
if self.header.is_none() {
|
||||
let count = self.document_rels.header_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
// Add default header reference
|
||||
.header_reference(HeaderReference::new("default", create_header_rid(1)));
|
||||
self.document_rels.header_count += 1;
|
||||
.header(header, &create_header_rid(count));
|
||||
self.document_rels.header_count = count;
|
||||
self.content_type = self.content_type.add_header();
|
||||
}
|
||||
self.header = Some(header);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, footer: Footer) -> Docx {
|
||||
if footer.has_numbering {
|
||||
// If this document has numbering, set numberings.xml to document_rels.
|
||||
// This is because numberings.xml without numbering cause an error on word online.
|
||||
pub fn first_header(mut self, header: Header) -> Self {
|
||||
if header.has_numbering {
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
if self.footer.is_none() {
|
||||
let count = self.document_rels.header_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
// Add default footer reference
|
||||
.footer_reference(FooterReference::new("default", create_footer_rid(1)));
|
||||
self.document_rels.footer_count += 1;
|
||||
self.content_type = self.content_type.add_footer();
|
||||
.first_header(header, &create_header_rid(count));
|
||||
self.document_rels.header_count = count;
|
||||
self.content_type = self.content_type.add_header();
|
||||
self
|
||||
}
|
||||
self.footer = Some(footer);
|
||||
|
||||
pub fn even_header(mut self, header: Header) -> Self {
|
||||
if header.has_numbering {
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
let count = self.document_rels.header_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
.even_header(header, &create_header_rid(count));
|
||||
self.document_rels.header_count = count;
|
||||
self.content_type = self.content_type.add_header();
|
||||
self.settings = self.settings.even_and_odd_headers();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, footer: Footer) -> Self {
|
||||
if footer.has_numbering {
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
let count = self.document_rels.footer_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
.footer(footer, &create_footer_rid(count));
|
||||
self.document_rels.footer_count = count;
|
||||
self.content_type = self.content_type.add_footer();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_footer(mut self, footer: Footer) -> Self {
|
||||
if footer.has_numbering {
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
let count = self.document_rels.footer_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
.first_footer(footer, &create_footer_rid(count));
|
||||
self.document_rels.footer_count = count;
|
||||
self.content_type = self.content_type.add_footer();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_footer(mut self, footer: Footer) -> Self {
|
||||
if footer.has_numbering {
|
||||
self.document_rels.has_numberings = true;
|
||||
}
|
||||
let count = self.document_rels.footer_count + 1;
|
||||
self.document.section_property = self
|
||||
.document
|
||||
.section_property
|
||||
.even_footer(footer, &create_footer_rid(count));
|
||||
self.document_rels.footer_count = count;
|
||||
self.content_type = self.content_type.add_footer();
|
||||
self.settings = self.settings.even_and_odd_headers();
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -365,8 +409,21 @@ impl Docx {
|
|||
|
||||
self.document_rels.image_ids = image_ids;
|
||||
|
||||
let footer = self.footer.as_ref().map(|footer| footer.build());
|
||||
let header = self.header.as_ref().map(|header| header.build());
|
||||
let headers: Vec<Vec<u8>> = self
|
||||
.document
|
||||
.section_property
|
||||
.get_headers()
|
||||
.iter()
|
||||
.map(|h| h.build())
|
||||
.collect();
|
||||
|
||||
let footers: Vec<Vec<u8>> = self
|
||||
.document
|
||||
.section_property
|
||||
.get_footers()
|
||||
.iter()
|
||||
.map(|h| h.build())
|
||||
.collect();
|
||||
|
||||
XMLDocx {
|
||||
content_type: self.content_type.build(),
|
||||
|
@ -380,8 +437,8 @@ impl Docx {
|
|||
font_table: self.font_table.build(),
|
||||
numberings: self.numberings.build(),
|
||||
media: images,
|
||||
header,
|
||||
footer,
|
||||
headers,
|
||||
footers,
|
||||
comments_extended: self.comments_extended.build(),
|
||||
taskpanes: self.taskpanes.map(|taskpanes| taskpanes.build()),
|
||||
taskpanes_rels: self.taskpanes_rels.build(),
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct Settings {
|
|||
zoom: Zoom,
|
||||
doc_id: Option<DocId>,
|
||||
doc_vars: Vec<DocVar>,
|
||||
even_and_odd_headers: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
@ -33,6 +34,11 @@ impl Settings {
|
|||
self.doc_vars.push(DocVar::new(name, val));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_and_odd_headers(mut self) -> Self {
|
||||
self.even_and_odd_headers = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
|
@ -42,6 +48,7 @@ impl Default for Settings {
|
|||
zoom: Zoom::new(100),
|
||||
doc_id: None,
|
||||
doc_vars: vec![],
|
||||
even_and_odd_headers: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +109,10 @@ impl BuildXML for Settings {
|
|||
}
|
||||
b = b.close();
|
||||
}
|
||||
|
||||
if self.even_and_odd_headers {
|
||||
b = b.even_and_odd_headers();
|
||||
}
|
||||
b.close().build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ pub struct XMLDocx {
|
|||
pub font_table: Vec<u8>,
|
||||
pub numberings: Vec<u8>,
|
||||
pub media: Vec<(usize, Vec<u8>)>,
|
||||
pub header: Option<Vec<u8>>,
|
||||
pub footer: Option<Vec<u8>>,
|
||||
pub headers: Vec<Vec<u8>>,
|
||||
pub footers: Vec<Vec<u8>>,
|
||||
pub comments_extended: Vec<u8>,
|
||||
pub taskpanes: Option<Vec<u8>>,
|
||||
pub taskpanes_rels: Vec<u8>,
|
||||
|
|
|
@ -277,6 +277,8 @@ impl XMLBuilder {
|
|||
closed!(footer_reference, "w:footerReference", "w:type", "r:id");
|
||||
|
||||
closed_with_str!(type_tag, "w:type");
|
||||
closed!(title_pg, "w:titlePg");
|
||||
closed!(even_and_odd_headers, "w:evenAndOddHeaders");
|
||||
closed!(page_size, "w:pgSz", "w:w", "w:h");
|
||||
closed!(page_size_with_orient, "w:pgSz", "w:w", "w:h", "w:orient");
|
||||
closed!(
|
||||
|
|
|
@ -46,14 +46,14 @@ where
|
|||
zip.start_file("word/commentsExtended.xml", options)?;
|
||||
zip.write_all(&xml.comments_extended)?;
|
||||
|
||||
if let Some(header) = xml.header {
|
||||
zip.start_file("word/header1.xml", options)?;
|
||||
zip.write_all(&header)?;
|
||||
for (i, h) in xml.headers.iter().enumerate() {
|
||||
zip.start_file(format!("word/header{}.xml", i + 1), options)?;
|
||||
zip.write_all(h)?;
|
||||
}
|
||||
|
||||
if let Some(footer) = xml.footer {
|
||||
zip.start_file("word/footer1.xml", options)?;
|
||||
zip.write_all(&footer)?;
|
||||
for (i, h) in xml.footers.iter().enumerate() {
|
||||
zip.start_file(format!("word/footer{}.xml", i + 1), options)?;
|
||||
zip.write_all(h)?;
|
||||
}
|
||||
|
||||
if !xml.media.is_empty() {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -863,6 +863,22 @@ export class Docx {
|
|||
docx = docx.header(header);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._firstHeader) {
|
||||
let header = wasm.createHeader();
|
||||
this.sectionProperty._firstHeader.children.forEach((c) => {
|
||||
header = header.add_paragraph(this.buildParagraph(c));
|
||||
});
|
||||
docx = docx.first_header(header);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._evenHeader) {
|
||||
let header = wasm.createHeader();
|
||||
this.sectionProperty._evenHeader.children.forEach((c) => {
|
||||
header = header.add_paragraph(this.buildParagraph(c));
|
||||
});
|
||||
docx = docx.even_header(header);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._footer) {
|
||||
let footer = wasm.createFooter();
|
||||
this.sectionProperty._footer.children.forEach((c) => {
|
||||
|
@ -871,6 +887,22 @@ export class Docx {
|
|||
docx = docx.footer(footer);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._firstFooter) {
|
||||
let footer = wasm.createFooter();
|
||||
this.sectionProperty._firstFooter.children.forEach((c) => {
|
||||
footer = footer.add_paragraph(this.buildParagraph(c));
|
||||
});
|
||||
docx = docx.first_footer(footer);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._evenFooter) {
|
||||
let footer = wasm.createFooter();
|
||||
this.sectionProperty._evenFooter.children.forEach((c) => {
|
||||
footer = footer.add_paragraph(this.buildParagraph(c));
|
||||
});
|
||||
docx = docx.even_footer(footer);
|
||||
}
|
||||
|
||||
if (this.sectionProperty._pageMargin) {
|
||||
const { top, left, right, bottom, header, footer, gutter } =
|
||||
this.sectionProperty._pageMargin;
|
||||
|
|
|
@ -19,7 +19,11 @@ export class SectionProperty {
|
|||
linePitch: 360,
|
||||
};
|
||||
_header: Header | null = null;
|
||||
_firstHeader: Header | null = null;
|
||||
_evenHeader: Header | null = null;
|
||||
_footer: Footer | null = null;
|
||||
_firstFooter: Footer | null = null;
|
||||
_evenFooter: Footer | null = null;
|
||||
|
||||
pageSize(w: number, h: number) {
|
||||
this._pageSize.w = w;
|
||||
|
@ -47,10 +51,30 @@ export class SectionProperty {
|
|||
return this;
|
||||
}
|
||||
|
||||
firstHeader(header: Header) {
|
||||
this._firstHeader = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
evenHeader(header: Header) {
|
||||
this._evenHeader = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
footer(footer: Footer) {
|
||||
this._footer = footer;
|
||||
return this;
|
||||
}
|
||||
|
||||
firstFooter(footer: Footer) {
|
||||
this._firstFooter = footer;
|
||||
return this;
|
||||
}
|
||||
|
||||
evenFooter(footer: Footer) {
|
||||
this._evenFooter = footer;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export type PageOrientationType = "landscape" | "portrait";
|
||||
|
|
|
@ -78,11 +78,31 @@ impl Docx {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn first_header(mut self, header: Header) -> Self {
|
||||
self.0 = self.0.first_header(header.take());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_header(mut self, header: Header) -> Self {
|
||||
self.0 = self.0.even_header(header.take());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, footer: Footer) -> Self {
|
||||
self.0 = self.0.footer(footer.take());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_footer(mut self, footer: Footer) -> Self {
|
||||
self.0 = self.0.first_footer(footer.take());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn even_footer(mut self, footer: Footer) -> Self {
|
||||
self.0 = self.0.even_footer(footer.take());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn page_size(mut self, w: u32, h: u32) -> Docx {
|
||||
self.0 = self.0.page_size(w, h);
|
||||
self
|
||||
|
|
|
@ -953,8 +953,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -969,7 +967,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -981,8 +979,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -1016,6 +1012,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "FB0AE6E2-8FB8-3345-A8FC-78CE6F3ABE4E",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -1698,8 +1695,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -1714,7 +1709,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11906,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -1726,8 +1721,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -1761,6 +1754,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": null,
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -2357,8 +2351,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -2373,7 +2365,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -2385,8 +2377,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -2420,6 +2410,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "A1898E6C-1AED-3C4D-9CCF-C24208DA732E",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -3824,8 +3815,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -3840,7 +3829,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11906,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -3852,8 +3841,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -3887,6 +3874,7 @@ Object {
|
|||
"defaultTabStop": 709,
|
||||
"docId": "50d61cff-8055-4197-917b-3993d0243c46",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -6342,8 +6330,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 600,
|
||||
"footer": 992,
|
||||
|
@ -6358,7 +6344,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11906,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -6370,8 +6356,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -6405,6 +6389,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "E43E077A-3477-A242-BD53-4313974E06A2",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -7240,8 +7225,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -7256,7 +7239,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11906,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -7268,8 +7251,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -7303,6 +7284,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": null,
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -7927,8 +7909,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -7943,7 +7923,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -7955,8 +7935,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [
|
||||
|
@ -9955,6 +9933,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "10BE20B6-DCA9-7441-B548-606D7D9EDD92",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -12512,8 +12491,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -12528,7 +12505,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11906,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -12540,8 +12517,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [
|
||||
|
@ -13772,6 +13747,7 @@ Object {
|
|||
"val": "{\\"id\\":\\"c3327226-c646-42fd-8747-366d471232d7\\",\\"commentHash\\":\\"8b1a9953c4611296a827abf8c47804d7\\",\\"articleId\\":\\"55b04568-28f5-467e-b69c-51a057caeda2\\",\\"commentRangeId\\":\\"6a46e35b-c93f-4462-8aff-6361aa20f521\\",\\"createdBy\\":\\"admin\\",\\"updatedAt\\":\\"2020-12-18T06:28:45.760Z\\",\\"parentCommentId\\":null}",
|
||||
},
|
||||
],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -15809,8 +15785,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -15825,7 +15799,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -15837,8 +15811,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [
|
||||
|
@ -17191,6 +17163,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "F952540B-8E26-9040-BEAB-F11A2F10B576",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -20584,8 +20557,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -20600,7 +20571,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -20612,8 +20583,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -20647,6 +20616,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "C272B628-6DE8-264A-8734-9D2219FFD42F",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -21869,8 +21839,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -21885,7 +21853,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -21897,8 +21865,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -21932,6 +21898,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "9F52F717-3F03-584C-ACEF-96E0106FA905",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
@ -22932,8 +22899,6 @@ Object {
|
|||
"gridType": "lines",
|
||||
"linePitch": 360,
|
||||
},
|
||||
"footerReference": null,
|
||||
"headerReference": null,
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"footer": 992,
|
||||
|
@ -22948,7 +22913,7 @@ Object {
|
|||
"orient": null,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
"titlePg": false,
|
||||
},
|
||||
},
|
||||
"documentRels": Object {
|
||||
|
@ -22960,8 +22925,6 @@ Object {
|
|||
"imageIds": Array [],
|
||||
},
|
||||
"fontTable": Object {},
|
||||
"footer": null,
|
||||
"header": null,
|
||||
"media": Array [],
|
||||
"numberings": Object {
|
||||
"abstractNums": Array [],
|
||||
|
@ -22995,6 +22958,7 @@ Object {
|
|||
"defaultTabStop": 840,
|
||||
"docId": "7501A506-09EA-0F4C-ACFF-789B81CBED2D",
|
||||
"docVars": Array [],
|
||||
"evenAndOddHeaders": false,
|
||||
"zoom": 100,
|
||||
},
|
||||
"styles": Object {
|
||||
|
|
Loading…
Reference in New Issue