From aa8f3a759f816df614671ce8afa6813dfb9d8d7f Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Thu, 12 Mar 2015 09:52:30 -0400 Subject: [PATCH] Add support for textRotation --- README.md | 19 +++++++++++++------ bits/92_stylebuilder.js | 3 ++- test.js | 5 +++-- xlsx.js | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9d071be..c66eb79 100644 --- a/README.md +++ b/README.md @@ -449,20 +449,27 @@ top-level attributes: `fill`, `font`, `numFmt`, `alignment`, and `border`. | | | "0.00%;\\(0.00%\\);\\-;@" // string specifying a custom format, escaping special characters | alignment | vertical | "bottom"||"center"||"top" | | horizontal | "bottom"||"center"||"top" +| | textRotation | Number from 0 to 180 or 255 (default is 0) +| | | "90" is rotated up 90 degrees +| | | "45" is rotated up 45 degrees +| | | "135" is rotated down 45 degrees +| | | "180" is rotated down 180 degrees +| | | "255" is special, aligned vertically | border | top | { style: BORDER_STYLE, color: COLOR_SPEC } | | bottom | { style: BORDER_STYLE, color: COLOR_SPEC } -| | left | { style: BORDER_STYLE, color: COLOR_SPEC } -| | right | { style: BORDER_STYLE, color: COLOR_SPEC } -| | diagonal | { style: BORDER_STYLE, color: COLOR_SPEC } -| | diagonalUp | true||false -| | diagonalDown | true||false +| | left | { style: BORDER_STYLE, color: COLOR_SPEC } +| | right | { style: BORDER_STYLE, color: COLOR_SPEC } +| | diagonal | { style: BORDER_STYLE, color: COLOR_SPEC } +| | diagonalUp | true||false +| | diagonalDown | true||false **COLOR_SPEC** Colors for `fill`, `font`, and `border` are specified as objects, either: +* `{ auto: 1}` specifying automatic values * `{ rgb: "FFFFAA00" }` specifying a hex ARGB value * `{ theme: "1", tint: "-0.25"}` specifying an integer index to a theme color and a tint value (default 0) -* `{indexed: 64}` default value for `fill.bgColor` +* `{ indexed: 64}` default value for `fill.bgColor` ** BORDER_STYLE** are piped directly to XML and may take on one of the following values: * `thin` diff --git a/bits/92_stylebuilder.js b/bits/92_stylebuilder.js index bc06889..a0dfbf7 100644 --- a/bits/92_stylebuilder.js +++ b/bits/92_stylebuilder.js @@ -192,10 +192,11 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo if (attributes.alignment.vertical) { $alignment.attr('vertical', attributes.alignment.vertical);} if (attributes.alignment.indent) { $alignment.attr('indent', attributes.alignment.indent);} if (attributes.alignment.wrapText) { $alignment.attr('wrapText', attributes.alignment.wrapText);} + if (attributes.alignment.textRotation) { $alignment.attr('textRotation', attributes.alignment.textRotation);} + $xf.append($alignment).attr('applyAlignment',1) } - this.$cellXfs.append($xf); var count = +this.$cellXfs.children().length; diff --git a/test.js b/test.js index 3f0dc20..e6abb0b 100644 --- a/test.js +++ b/test.js @@ -57,6 +57,8 @@ var paths = { var N1 = 'XLSX'; var N2 = 'XLSB'; + + function parsetest(x, wb, full, ext) { ext = (ext ? " [" + ext + "]": ""); if(!full && ext) return; @@ -111,7 +113,7 @@ function parsetest(x, wb, full, ext) { var csv = fixcsv(X.utils.make_csv(wb.Sheets[ws])); var result = (file == csv); if (!result) { // try again parsing the file ourselves - // somehow these workbooks are getting here having been parsed without {cellNF: true} + // somehow these workbooks are getting here having been parsec without {cellNF: true} // so re-read them with {cellNF:true} and all works just great. // THus these CSV tests seem to fail due to issue with test framework rather than XLSX itself var wb1 = X.readFile(wb.FILENAME, {cellStyles:true, cellNF:true}); @@ -167,7 +169,6 @@ describe('should parse test files', function() { var wb = wbtable[dir + x]; if(!wb) wb = X.readFile(dir + x, opts); var FILENAME = wb.FILENAME; - console.error(JSON.stringify(opts)) wb = X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF, cellNF: true}) wb.FILENAME = FILENAME; diff --git a/xlsx.js b/xlsx.js index 92b0af4..e65b87b 100644 --- a/xlsx.js +++ b/xlsx.js @@ -5693,10 +5693,11 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo if (attributes.alignment.vertical) { $alignment.attr('vertical', attributes.alignment.vertical);} if (attributes.alignment.indent) { $alignment.attr('indent', attributes.alignment.indent);} if (attributes.alignment.wrapText) { $alignment.attr('wrapText', attributes.alignment.wrapText);} + if (attributes.alignment.textRotation) { $alignment.attr('textRotation', attributes.alignment.textRotation);} + $xf.append($alignment).attr('applyAlignment',1) } - this.$cellXfs.append($xf); var count = +this.$cellXfs.children().length;