-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrenderers.js
40 lines (33 loc) · 1.06 KB
/
renderers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { hf, sheetId } from "./hyperformulaConfig";
/**
* Fill the HTML table with data.
*/
export function renderTable() {
const theadDOM = document.querySelector(".example thead");
const tbodyDOM = document.querySelector(".example tbody");
const { height, width } = hf.getSheetDimensions(sheetId);
let newTheadHTML = "";
let newTbodyHTML = "";
for (let row = -1; row < height; row++) {
for (let col = 0; col < width; col++) {
if (row === -1) {
newTheadHTML += `<th><span></span></th>`;
continue;
}
const cellAddress = { sheet: sheetId, col, row };
const cellHasFormula = hf.doesCellHaveFormula(cellAddress);
let cellValue = "";
if (!hf.isCellEmpty(cellAddress) && !cellHasFormula) {
cellValue = hf.getCellValue(cellAddress);
} else {
cellValue = hf.getCellFormula(cellAddress);
}
newTbodyHTML += `<td><span>
${cellValue}
</span></td>`;
}
newTbodyHTML += "</tr>";
}
tbodyDOM.innerHTML = `<tr>${newTbodyHTML}</tr>`;
theadDOM.innerHTML = newTheadHTML;
}