Add column width calculation
Some checks failed
Build and Deploy / build (push) Failing after 11s
Build and Deploy / deploy (push) Has been skipped
Some checks failed
Build and Deploy / build (push) Failing after 11s
Build and Deploy / deploy (push) Has been skipped
This commit is contained in:
parent
7c87d3220d
commit
3d98e41d2b
@ -79,6 +79,17 @@ function generateContentFileXMLString(sheetsData) {
|
|||||||
root.setAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
|
root.setAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
|
||||||
root.setAttribute('office:version', '1.2');
|
root.setAttribute('office:version', '1.2');
|
||||||
|
|
||||||
|
const styleNode = doc.createElement("office:automatic-styles");
|
||||||
|
const boldCellStyleNode = doc.createElement("style:style");
|
||||||
|
boldCellStyleNode.setAttribute("style:name", "boldcell");
|
||||||
|
boldCellStyleNode.setAttribute("style:family", "table-cell");
|
||||||
|
const boldCellTextPropsNode = doc.createElement("style:text-properties");
|
||||||
|
boldCellTextPropsNode.setAttribute("fo:font-weight", "bold");
|
||||||
|
boldCellStyleNode.appendChild(boldCellTextPropsNode);
|
||||||
|
styleNode.appendChild(boldCellStyleNode);
|
||||||
|
|
||||||
|
root.appendChild(styleNode);
|
||||||
|
|
||||||
const bodyNode = doc.createElement('office:body');
|
const bodyNode = doc.createElement('office:body');
|
||||||
root.appendChild(bodyNode);
|
root.appendChild(bodyNode);
|
||||||
|
|
||||||
@ -91,8 +102,29 @@ function generateContentFileXMLString(sheetsData) {
|
|||||||
tableNode.setAttribute('table:name', sheetName);
|
tableNode.setAttribute('table:name', sheetName);
|
||||||
spreadsheetNode.appendChild(tableNode);
|
spreadsheetNode.appendChild(tableNode);
|
||||||
|
|
||||||
const columnNode = doc.createElement('table:table-column');
|
var columnsWidthChars = {};
|
||||||
tableNode.appendChild(columnNode);
|
for (let r = 0; r < sheetData.length; r++) {
|
||||||
|
for (let c = 0; c < sheetData[r].length; c++) {
|
||||||
|
if (typeof columnsWidthChars[c] == "undefined") {
|
||||||
|
columnsWidthChars[c] = sheetData[r][c].value.length;
|
||||||
|
}
|
||||||
|
columnsWidthChars[c] = Math.max(columnsWidthChars[c], sheetData[r][c].value.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var prop in columnsWidthChars) {
|
||||||
|
var columnNode = doc.createElement('table:table-column');
|
||||||
|
columnNode.setAttribute("table:style-name", "colwidth" + columnsWidthChars[prop]);
|
||||||
|
tableNode.appendChild(columnNode);
|
||||||
|
|
||||||
|
var columnWidthNode = doc.createElement("style:style");
|
||||||
|
columnWidthNode.setAttribute("style:name", "colwidth" + columnsWidthChars[prop]);
|
||||||
|
columnWidthNode.setAttribute("style:family", "table-column");
|
||||||
|
const columnWidthPropsNode = doc.createElement("style:table-column-properties");
|
||||||
|
columnWidthPropsNode.setAttribute("style:column-width", `${columnsWidthChars[prop] * 0.26}cm`);
|
||||||
|
columnWidthNode.appendChild(columnWidthPropsNode);
|
||||||
|
styleNode.appendChild(columnWidthNode);
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate through rows
|
// Iterate through rows
|
||||||
sheetData.forEach((row) => {
|
sheetData.forEach((row) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user