|
6 | 6 | } from '../types/xml-types'; |
7 | 7 | import { XmlHelper } from './xml-helper'; |
8 | 8 | import HasShapes from '../classes/has-shapes'; |
9 | | -import { FindElementSelector } from '../types/types'; |
| 9 | +import { FindElementSelector, ShapeModificationCallback } from '../types/types'; |
10 | 10 | import ModifyTableHelper from './modify-table-helper'; |
11 | 11 | import { TableData, TableInfo } from '../types/table-types'; |
12 | 12 |
|
@@ -114,13 +114,9 @@ export class XmlSlideHelper { |
114 | 114 | type: XmlSlideHelper.getElementType(slideElement), |
115 | 115 | position: XmlSlideHelper.parseShapeCoordinates(slideElement), |
116 | 116 | hasTextBody: !!XmlSlideHelper.getTextBody(slideElement), |
117 | | - getText: () => XmlSlideHelper.parseTextFragments(slideElement), |
118 | | - // getTableInfo: () => { |
119 | | - // const data = <TableInfo[]>[]; |
120 | | - // ModifyTableHelper.readTableData(data)(slideElement); |
121 | | - // return data; |
122 | | - // }, |
123 | 117 | getXmlElement: () => slideElement, |
| 118 | + getText: () => XmlSlideHelper.parseTextFragments(slideElement), |
| 119 | + getTableInfo: () => XmlSlideHelper.readTableInfo(slideElement), |
124 | 120 | getAltText: () => XmlSlideHelper.getImageAltText(slideElement), |
125 | 121 | }; |
126 | 122 | } |
@@ -293,4 +289,39 @@ export class XmlSlideHelper { |
293 | 289 | return null; |
294 | 290 | } |
295 | 291 | }; |
| 292 | + |
| 293 | + static readTableInfo = (element: XmlElement): TableInfo[] => { |
| 294 | + const info = <TableInfo[]>[]; |
| 295 | + const rows = element.getElementsByTagName('a:tr'); |
| 296 | + if (!rows) { |
| 297 | + console.error("Can't find a table row."); |
| 298 | + return info; |
| 299 | + } |
| 300 | + |
| 301 | + for (let r = 0; r < rows.length; r++) { |
| 302 | + const row = rows.item(r); |
| 303 | + const columns = row.getElementsByTagName('a:tc'); |
| 304 | + for (let c = 0; c < columns.length; c++) { |
| 305 | + const cell = columns.item(c); |
| 306 | + const gridSpan = cell.getAttribute('gridSpan'); |
| 307 | + const hMerge = cell.getAttribute('hMerge'); |
| 308 | + const texts = cell.getElementsByTagName('a:t'); |
| 309 | + const text: string[] = []; |
| 310 | + for (let t = 0; t < texts.length; t++) { |
| 311 | + text.push(texts.item(t).textContent); |
| 312 | + } |
| 313 | + info.push({ |
| 314 | + row: r, |
| 315 | + column: c, |
| 316 | + rowXml: row, |
| 317 | + columnXml: cell, |
| 318 | + text: text, |
| 319 | + textContent: text.join(''), |
| 320 | + gridSpan: Number(gridSpan), |
| 321 | + hMerge: Number(hMerge), |
| 322 | + }); |
| 323 | + } |
| 324 | + } |
| 325 | + return info; |
| 326 | + }; |
296 | 327 | } |
0 commit comments