diff --git a/docx-core/src/documents/document_rels.rs b/docx-core/src/documents/document_rels.rs index ba4f5f6..5a504a6 100644 --- a/docx-core/src/documents/document_rels.rs +++ b/docx-core/src/documents/document_rels.rs @@ -2,18 +2,25 @@ use crate::documents::BuildXML; use crate::xml_builder::*; #[derive(Debug)] -pub struct DocumentRels {} +pub struct DocumentRels { + pub(crate) has_comments: bool, + pub(crate) has_numberings: bool, +} impl DocumentRels { pub fn new() -> DocumentRels { - DocumentRels {} + DocumentRels { + has_comments: false, + has_numberings: false, + } } } impl BuildXML for DocumentRels { fn build(&self) -> Vec { - let b = XMLBuilder::new(); - b.declaration(None) + let mut b = XMLBuilder::new(); + b = b + .declaration(None) .open_relationships("http://schemas.openxmlformats.org/package/2006/relationships") .relationship( "rId1", @@ -22,25 +29,31 @@ impl BuildXML for DocumentRels { ) .relationship( "rId2", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", - "numbering.xml", - ) - .relationship( - "rId3", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", - "comments.xml", - ) - .relationship( - "rId4", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml", ) .relationship( - "rId5", + "rId3", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml", + ); + + if self.has_comments { + b = b.relationship( + "rId4", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", + "comments.xml", ) - .close() - .build() + } + + if self.has_numberings { + b = b.relationship( + "rId5", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", + "numbering.xml", + ) + } + + b.close().build() } } diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index f7ca25f..33d4ca2 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -154,6 +154,11 @@ impl Docx { _ => {} } } + // If this document has comments, set comments.xml to document_rels. + // This is because comments.xml without comment cause an error on word online. + if comments.len() > 0 { + self.document_rels.has_comments = true; + } self.comments.add_comments(comments); } } diff --git a/docx-wasm/pkg/index.d.ts b/docx-wasm/pkg/index.d.ts index a56b8da..2a94e51 100644 --- a/docx-wasm/pkg/index.d.ts +++ b/docx-wasm/pkg/index.d.ts @@ -340,6 +340,11 @@ export class Table { * @returns {Table} */ align(v: number): Table; +/** +* @param {number} w +* @returns {Table} +*/ + width(w: number): Table; } /** */ diff --git a/docx-wasm/pkg/index.js b/docx-wasm/pkg/index.js index 69302c5..87af7d2 100644 --- a/docx-wasm/pkg/index.js +++ b/docx-wasm/pkg/index.js @@ -972,6 +972,19 @@ export class Table { const ret = wasm.table_align(ptr, v); return Table.__wrap(ret); } + /** + * @param {number} w + * @returns {Table} + */ + width(w) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(w); + const ret = wasm.table_width(ptr, w); + return Table.__wrap(ret); + } } /** */ diff --git a/docx-wasm/pkg/index_bg.d.ts b/docx-wasm/pkg/index_bg.d.ts index 348bce1..41a76c2 100644 --- a/docx-wasm/pkg/index_bg.d.ts +++ b/docx-wasm/pkg/index_bg.d.ts @@ -44,6 +44,7 @@ export function table_add_row(a: number, b: number): number; export function table_set_grid(a: number, b: number, c: number): number; export function table_indent(a: number, b: number): number; export function table_align(a: number, b: number): number; +export function table_width(a: number, b: number): number; export function __wbg_numbering_free(a: number): void; export function createNumbering(a: number): number; export function numbering_add_level(a: number, b: number): number; diff --git a/docx-wasm/pkg/index_bg.wasm b/docx-wasm/pkg/index_bg.wasm index 0f39fa8..a476bc4 100644 Binary files a/docx-wasm/pkg/index_bg.wasm and b/docx-wasm/pkg/index_bg.wasm differ