@@ -83,7 +83,12 @@ export function sectionPropertiesFromNode(node?: Node | null): SectionProperties
8383 "numberOfColumns": ./${ QNS . w } cols/@${ QNS . w } num/number(),
8484 "separator": docxml:st-on-off(./${ QNS . w } cols/@${ QNS . w } sep),
8585 "equalWidth": docxml:st-on-off(./${ QNS . w } cols/@${ QNS . w } equalwidth),
86- "columns": array{}
86+ "columns": array{
87+ ./${ QNS . w } cols/${ QNS . w } col/map{
88+ "columnWidth": if (@${ QNS . w } w) then docxml:length(@${ QNS . w } w, 'twip') else (),
89+ "columnSpace": if (@${ QNS . w } space) then docxml:length(@${ QNS . w } space, 'twip') else ()
90+ }
91+ }
8792 },
8893 "pageWidth": docxml:length(${ QNS . w } pgSz/@${ QNS . w } w, 'twip'),
8994 "pageHeight": docxml:length(${ QNS . w } pgSz/@${ QNS . w } h, 'twip'),
@@ -102,13 +107,6 @@ export function sectionPropertiesFromNode(node?: Node | null): SectionProperties
102107 node ,
103108 ) ;
104109
105- evaluateXPathToArray ( `array{./${ QNS . w } cols/${ QNS . w } col/map{
106- "columnWidth": if (@${ QNS . w } w) then docxml:length(@${ QNS . w } w, 'twip') else (),
107- "columnSpace": if (@${ QNS . w } space) then docxml:length(@${ QNS . w } space, 'twip') else ()
108- }}` , node ) . forEach ( ( { columnWidth, columnSpace} ) => data . columns ?. columns ?. push (
109- { columnWidth : columnWidth || null , columnSpace : columnSpace || null }
110- ) ) ;
111-
112110 // console.log(data);
113111 return data ;
114112}
@@ -146,7 +144,15 @@ export function sectionPropertiesToNode(data: SectionProperties = {}): Node {
146144 if (exists($columns) and $columns('numberOfColumns') > 0) then element ${ QNS . w } cols {
147145 attribute ${ QNS . w } sep { $columns('separator') },
148146 attribute ${ QNS . w } equalwidth { $columns('equalWidth') },
149- attribute ${ QNS . w } num { $columns('numberOfColumns') }
147+ attribute ${ QNS . w } num { $columns('numberOfColumns') },
148+
149+ if (docxml:st-on-off(string($columns('equalWidth')))) then ()
150+ else for $column in $columns('columns')?*
151+ return element ${ QNS . w } col {
152+ attribute ${ QNS . w } w { round($column("columnWidth")("twip")) },
153+ if (not(exists($column("columnSpace")))) then ()
154+ else attribute ${ QNS . w } space { round($column("columnSpace")("twip")) }
155+ }
150156 } else (),
151157 if (exists($pageWidth) or exists($pageHeight) or $pageOrientation) then element ${ QNS . w } pgSz {
152158 if (exists($pageWidth)) then attribute ${ QNS . w } w {
@@ -191,36 +197,14 @@ export function sectionPropertiesToNode(data: SectionProperties = {}): Node {
191197 typeof data . footers === 'string'
192198 ? { first : data . footers , even : data . footers , odd : data . footers }
193199 : data . footers || { } ,
194- columns : {
195- numberOfColumns : data . columns ?. numberOfColumns ,
196- separator : data . columns ?. separator ,
197- equalWidth : data . columns ?. equalWidth } ,
200+ columns : data . columns || { } ,
198201 pageWidth : data . pageWidth || null ,
199202 pageHeight : data . pageHeight || null ,
200203 pageMargin : data . pageMargin || null ,
201204 pageOrientation : data . pageOrientation || null ,
202205 isTitlePage : data . isTitlePage || null ,
203206 }
204- ) ;
205- data . columns ?. columns ?. forEach ( ( col ) => {
206- // console.log("COL");
207- if ( col . columnWidth != undefined ) {
208- update (
209- newNode ,
210- `let $cols := ./${ QNS . w } sectPr/${ QNS . w } cols
211- return (
212- if (exists($cols))
213- then (
214- insert node element ${ QNS . w } col {
215- attribute ${ QNS . w } w { round(${ col . columnWidth ?. twip . toString ( ) } ) },
216- attribute ${ QNS . w } space { round(${ col . columnSpace ?. twip . toString ( ) } ) }
217- } as last into $cols
218- ) else ()
219- )
220- `
221- )
222- }
223- } ) ;
207+ ) ;
224208
225209 return newNode ;
226210}
0 commit comments