Skip to content

Commit

Permalink
Merge pull request #19 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 4.3.0
  • Loading branch information
adrianq authored Mar 12, 2024
2 parents c971df1 + 429dc46 commit f1ea2fc
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 11 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.21.1
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ Set or clear the comment on the cell.
| [opts.text] | <code>string</code> | The comment text to set. |
| [opts.width] | <code>string</code> | Comment box width. |
| [opts.height] | <code>string</code> | Comment box height. |
| [opts.textAlign] | <code>string</code> | Comment text Align. |
| [opts.horizontalAlignment] | <code>string</code> | Comment horizontalAlignment |

<a name="Cell+dataValidation"></a>

Expand Down Expand Up @@ -3137,6 +3139,8 @@ Set the comment on the cell with the given address.
| [opts.text] | <code>string</code> | The comment text to set. |
| [opts.width] | <code>string</code> | Comment box width. |
| [opts.height] | <code>string</code> | Comment box height. |
| [opts.horizontalAlignment] | <code>string</code> | Comment horizontalAlignment. |
| [opts.textAlign] | <code>string</code> | Comment textAlign. |

<a name="Sheet+conditionalFormatting"></a>

Expand Down
4 changes: 3 additions & 1 deletion lib/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class Cell {
* @param {string} [opts.text] - The comment text to set.
* @param {string} [opts.width] - Comment box width.
* @param {string} [opts.height] - Comment box height.
* @param {string} [opts.textAlign] - Comment text Align.
* @param {string} [opts.horizontalAlignment] -Comment horizontalAlignment
* @returns {Cell} The cell.
*/
comment() {
Expand Down Expand Up @@ -588,7 +590,7 @@ class Cell {
this._formulaType = fNode.attributes.t || "normal";
this._formulaRef = fNode.attributes.ref;
this._formula = fNode.children[0];
this._sharedFormulaId = String(fNode.attributes.si);
this._sharedFormulaId = _.isNil(fNode.attributes.si) ? undefined : String(fNode.attributes.si);

if (this._formulaType === "shared" && !_.isNil(this._sharedFormulaId) && !_.isNil(this._formula)) {
this.sheet().sharedFormulas(this._sharedFormulaId, { ref: this._formulaRef, formula: this._formula });
Expand Down
5 changes: 4 additions & 1 deletion lib/RichTextFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class RichTextFragment {
attributes: {},
children: [
{ name: 'rPr', attributes: {}, children: [] },
{ name: 't', attributes: {}, children: [] }
{ name: 't', attributes: /\s+/.test(value)
? { 'xml:space': 'preserve' }
: {},
children: [] }
]
};
this._fontNode = xmlq.findChild(this._node, 'rPr');
Expand Down
8 changes: 6 additions & 2 deletions lib/Sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ class Sheet {
* @param {string} [opts.text] - The comment text to set.
* @param {string} [opts.width] - Comment box width.
* @param {string} [opts.height] - Comment box height.
* @param {string} [opts.textAlign] - Comment textAlign.
* @param {string} [opts.horizontalAlignment] - Comment horizontalAlignment.
* @returns {Sheet} The sheet.
*/
comment() {
Expand All @@ -730,6 +732,8 @@ class Sheet {
this._comments[address] = {
width: "200pt",
height: "50pt",
horizontalAlignment: 'Left',
textAlign: 'left',
...comment,
row: ref.rowNumber,
column: ref.columnNumber
Expand Down Expand Up @@ -1276,7 +1280,7 @@ class Sheet {
{
name: "cfRule",
attributes: {
type: conditionalFormatting.type,
type: conditionalFormatting.type || "expression",
priority: conditionalFormatting.priority.toString(),
text: "",
dxfId: idx.toString(),
Expand Down Expand Up @@ -1975,7 +1979,7 @@ class Sheet {
this._drawings[i] = new Drawing(i, workbook, this, drawingNode, relationship);
}
} else {
throw new Error(`Unsupported Node: ${drawingNode}`);
console.error(`Unsupported Node: ${drawingNode}`);
}
}
});
Expand Down
11 changes: 6 additions & 5 deletions lib/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,9 @@ class StyleSheet {
this._fillsNode = xmlq.findChild(this._node, "fills");
this._bordersNode = xmlq.findChild(this._node, "borders");
this._cellXfsNode = xmlq.findChild(this._node, "cellXfs");
this._cellStylesNode = xmlq.findChild(this._node, "cellStyles");
this._dxfsNode = xmlq.findChild(this._node, "dxfs");

if (!this._dxfsNode) {
this._dxfsNode = { name: "dxfs", attributes: {}, children: [] };
xmlq.insertAfter(this._node, this._dxfsNode, this._cellXfs);
}

if (!this._numFmtsNode) {
this._numFmtsNode = {
name: "numFmts",
Expand All @@ -235,6 +231,11 @@ class StyleSheet {
xmlq.insertBefore(this._node, this._numFmtsNode, this._fontsNode);
}

if (!this._dxfsNode) {
this._dxfsNode = { name: "dxfs", attributes: {}, children: [] };
xmlq.insertAfter(this._node, this._dxfsNode, this._cellStylesNode);
}

// Remove the optional counts so we don't have to keep them up to date.
delete this._numFmtsNode.attributes.count;
delete this._fontsNode.attributes.count;
Expand Down
3 changes: 2 additions & 1 deletion lib/Workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,12 +935,13 @@ function getVmlDrawingXml(sheetIndex, comments) {
<v:shadow color="black" obscured="t"/>
<v:path o:connecttype="none"/>
<v:textbox style="mso-direction-alt:auto">
<div style="text-align:left"/>
<div style="text-align:${comment.textAlign}"/>
</v:textbox>
<x:ClientData ObjectType="Note">
<x:MoveWithCells/>
<x:SizeWithCells/>
<x:AutoFill>False</x:AutoFill>
<x:TextHAlign>${comment.horizontalAlignment}</x:TextHAlign>
<x:Row>${comment.row - 1}</x:Row>
<x:Column>${comment.column - 1}</x:Column>
</x:ClientData>
Expand Down
3 changes: 3 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ declare namespace XlsxPopulate {
style(style: Style): Cell;
value(): string | boolean | number | Date | undefined;
value(value: string | boolean | number | null | undefined): Cell;
value(value: (string | boolean | number | null | undefined | Date)[][]): Cell;
value(): Range;
workbook(): Workbook;
addHorizontalPageBreak(): Cell;
Expand Down Expand Up @@ -399,6 +400,8 @@ declare namespace XlsxPopulate {
text: string;
width: string;
height: string;
textAlign: 'left'| 'right'| 'start'|'end';
horizontalAlignment: 'Left'| 'Justify'| 'Center'| 'Right';
}

class ConditionalFormatting {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eyeseetea/xlsx-populate",
"version": "4.2.0",
"version": "4.3.0",
"private": false,
"description": "Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, and a focus on keeping existing workbook features and styles in tact.",
"license": "MIT",
Expand Down
23 changes: 23 additions & 0 deletions scripts/create-xlsx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e -u -o pipefail

indent_folder() {
local root=$1
find "$root" -name '*.xml' -o -name '*.vml' | while read -r file; do
if test -s "$file"; then
< "$file" xmllint --format - | sponge "$file"
fi
done
}


main() {
local folder=$1 output=$2
(
cd "$folder"
zip -q -r -D "../$output" *
)
echo "Written: $output"
}

main "$@"
28 changes: 28 additions & 0 deletions scripts/diff-xlsx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -e -u -o pipefail

indent_folder() {
local root=$1
find "$root" -name '*.xml' -o -name '*.vml' | while read -r file; do
if test -s "$file"; then
< "$file" xmllint --format - | sponge "$file"
fi
done
}

extract() {
local file=$1
name=$(basename "${file%.*}")
unzip -q -o -d "$name" "$file"
indent_folder "$name"
echo "$name"
}

main() {
local file1=$1 file2=$2
folder1=$(extract "$file1")
folder2=$(extract "$file2")
cdiff -ur "$folder1" "$folder2"
}

main "$@"
22 changes: 22 additions & 0 deletions scripts/extract-xlsx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e -u -o pipefail

indent_folder() {
local root=$1
find "$root" -name '*.xml' -o -name '*.vml' | while read -r file; do
if test -s "$file"; then
< "$file" xmllint --format - | sponge "$file"
fi
done
}


main() {
local file=$1
name=$(basename "${file%.*}")
unzip -q -o -d "$name" "$file"
indent_folder "$name"
echo "$file -> $name/"
}

main "$@"
13 changes: 13 additions & 0 deletions scripts/xml-indent-folder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e -u -o pipefail

main() {
local root=$1
find "$root" -name '*.xml' -o -name '*.vml' | while read -r file; do
if test -s "$file"; then
< "$file" xmllint --format - | sponge "$file"
fi
done
}

main "$@"

0 comments on commit f1ea2fc

Please sign in to comment.