1-
21import { XmlHelper } from '../helper/xml-helper' ;
32import ModifyXmlHelper from '../helper/modify-xml-helper' ;
43import { TableData , TableRow } from '../types/table-types' ;
@@ -9,68 +8,59 @@ export class ModifyTable {
98 table : ModifyXmlHelper ;
109 xml : XMLDocument | Element ;
1110
12- constructor (
13- table : XMLDocument | Element ,
14- data : TableData ,
15- ) {
11+ constructor ( table : XMLDocument | Element , data : TableData ) {
1612 this . data = data ;
1713
1814 this . table = new ModifyXmlHelper ( table ) ;
1915 this . xml = table ;
2016 }
2117
2218 modify ( ) : ModifyTable {
23- this . setContents ( )
24- this . sliceRows ( )
19+ this . setContents ( ) ;
20+ this . sliceRows ( ) ;
2521
26- return this
22+ return this ;
2723 }
2824
2925 setContents ( ) {
3026 this . data . body . forEach ( ( row : TableRow , r : number ) => {
3127 row . values . forEach ( ( cell : number | string , c : number ) => {
32- this . table . modify (
33- this . row ( r ,
34- this . column ( c ,
35- this . cell ( cell )
36- )
37- )
38- )
39- } )
40- } )
28+ this . table . modify ( this . row ( r , this . column ( c , this . cell ( cell ) ) ) ) ;
29+ } ) ;
30+ } ) ;
4131 }
4232
4333 sliceRows ( ) {
4434 this . table . modify ( {
45- 'a:tbl' : this . slice ( 'a:tr' , this . data . body . length )
46- } )
35+ 'a:tbl' : this . slice ( 'a:tr' , this . data . body . length ) ,
36+ } ) ;
4737 }
4838
4939 row = ( index : number , children : ModificationTags ) : ModificationTags => {
5040 return {
5141 'a:tr' : {
5242 index : index ,
53- children : children
54- }
55- }
56- }
43+ children : children ,
44+ } ,
45+ } ;
46+ } ;
5747
5848 column = ( index : number , children : ModificationTags ) : ModificationTags => {
5949 return {
6050 'a:tc' : {
6151 index : index ,
62- children : children
63- }
64- }
65- }
52+ children : children ,
53+ } ,
54+ } ;
55+ } ;
6656
6757 cell = ( value : number | string ) : ModificationTags => {
6858 return {
6959 'a:t' : {
7060 modify : ModifyXmlHelper . text ( value ) ,
71- }
72- }
73- }
61+ } ,
62+ } ;
63+ } ;
7464
7565 slice ( tag : string , length : number ) : Modification {
7666 return {
@@ -83,22 +73,24 @@ export class ModifyTable {
8373 } ,
8474 } ;
8575 }
86-
76+
8777 adjustHeight ( ) {
88- const tableHeight = Number ( this . xml
89- . getElementsByTagName ( 'p:xfrm' ) [ 0 ]
90- . getElementsByTagName ( 'a:ext' ) [ 0 ]
91- . getAttribute ( 'cy' ) )
78+ const tableHeight = Number (
79+ this . xml
80+ . getElementsByTagName ( 'p:xfrm' ) [ 0 ]
81+ . getElementsByTagName ( 'a:ext' ) [ 0 ]
82+ . getAttribute ( 'cy' ) ,
83+ ) ;
9284
93- const rowHeight = tableHeight / this . data . body . length
85+ const rowHeight = tableHeight / this . data . body . length ;
9486
9587 this . data . body . forEach ( ( row : TableRow , r : number ) => {
9688 this . table . modify ( {
9789 'a:tr' : {
9890 index : r ,
9991 modify : ModifyXmlHelper . attribute ( 'h' , Math . round ( rowHeight ) ) ,
100- }
101- } )
102- } )
92+ } ,
93+ } ) ;
94+ } ) ;
10395 }
10496}
0 commit comments