()
| 178 | } |
| 179 | |
| 180 | store() { |
| 181 | // where the table needs to store table data, headers, footers in |
| 182 | // the sheet... |
| 183 | const assignStyle = (cell, style) => { |
| 184 | if (style) { |
| 185 | Object.keys(style).forEach(key => { |
| 186 | cell.style[key] = style[key]; |
| 187 | }); |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | const {worksheet, table} = this; |
| 192 | const {row, col} = table.tl; |
| 193 | let count = 0; |
| 194 | if (table.headerRow) { |
| 195 | const r = worksheet.getRow(row + count++); |
| 196 | table.columns.forEach((column, j) => { |
| 197 | const {style, name} = column; |
| 198 | const cell = r.getCell(col + j); |
| 199 | cell.value = name; |
| 200 | assignStyle(cell, style); |
| 201 | }); |
| 202 | } |
| 203 | table.rows.forEach(data => { |
| 204 | const r = worksheet.getRow(row + count++); |
| 205 | data.forEach((value, j) => { |
| 206 | const cell = r.getCell(col + j); |
| 207 | cell.value = value; |
| 208 | |
| 209 | assignStyle(cell, table.columns[j].style); |
| 210 | }); |
| 211 | }); |
| 212 | |
| 213 | if (table.totalsRow) { |
| 214 | const r = worksheet.getRow(row + count++); |
| 215 | table.columns.forEach((column, j) => { |
| 216 | const cell = r.getCell(col + j); |
| 217 | if (j === 0) { |
| 218 | cell.value = column.totalsRowLabel; |
| 219 | } else { |
| 220 | const formula = this.getFormula(column); |
| 221 | if (formula) { |
| 222 | cell.value = { |
| 223 | formula: column.totalsRowFormula, |
| 224 | result: column.totalsRowResult, |
| 225 | }; |
| 226 | } else { |
| 227 | cell.value = null; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | assignStyle(cell, column.style); |
| 232 | }); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | load(worksheet) { |
| 237 | // where the table will read necessary features from a loaded sheet |
no test coverage detected