From 9b0f3db36810854be9e919072d47f47beb8fb9ba Mon Sep 17 00:00:00 2001 From: MikeZyatkov Date: Thu, 7 Mar 2019 12:39:53 +0500 Subject: [PATCH 1/3] Add vertical align property Add support vertical align property (vertAlign) with possible values are superscript and subscript. Use: for entire cell firstRow.font = { name: 'Arial', family: 2, size: 20, vertAlign: 'superscript'} rich text: worksheet.getCell('A10').value = { 'richText': [ {'font': {'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': 'This is '}, {'font': {'italic': true,'size': 12,'color': {'theme': 1},'name': 'Calibri','vertAlign': 'superscript'},'text': 'superscript'}, {'font': {'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': 'and '}, {'font': {'italic': true,'size': 12,'color': {'theme': 1},'name': 'Calibri','vertAlign': 'subscript'},'text': 'subscript'}, ] }; --- index.d.ts | 1 + lib/xlsx/xform/style/font-xform.js | 1 + 2 files changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index 3a28909c9..5e21195b5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -226,6 +226,7 @@ export interface Font { bold: boolean; italic: boolean; underline: boolean | 'none' | 'single' | 'double' | 'singleAccounting' | 'doubleAccounting'; + vertAlign: 'superscript' | 'subscript'; strike: boolean; outline: boolean; } diff --git a/lib/xlsx/xform/style/font-xform.js b/lib/xlsx/xform/style/font-xform.js index 46234fe77..55da9b847 100644 --- a/lib/xlsx/xform/style/font-xform.js +++ b/lib/xlsx/xform/style/font-xform.js @@ -30,6 +30,7 @@ var FontXform = module.exports = function(options) { extend: { prop: 'extend', xform: new BooleanXform({tag: 'extend', attr: 'val'}) }, family: { prop: 'family', xform: new IntegerXform({tag: 'family', attr: 'val'}) }, outline: { prop: 'outline', xform: new BooleanXform({tag: 'outline', attr: 'val'}) }, + vertAlign: { prop: 'vertAlign', xform: new StringXform({ tag: 'vertAlign', attr: 'val' }) }, scheme: { prop: 'scheme', xform: new StringXform({tag: 'scheme', attr: 'val'}) }, shadow: { prop: 'shadow', xform: new BooleanXform({tag: 'shadow', attr: 'val'}) }, strike: { prop: 'strike', xform: new BooleanXform({tag: 'strike', attr: 'val'}) }, From 11dc61146750420470635e81f04f2101eaa67054 Mon Sep 17 00:00:00 2001 From: MikeZyatkov Date: Fri, 29 Mar 2019 13:24:08 +0500 Subject: [PATCH 2/3] test for vertical align prop --- .../style/vertical-aligment-xform.spec.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/unit/xlsx/xform/style/vertical-aligment-xform.spec.js diff --git a/spec/unit/xlsx/xform/style/vertical-aligment-xform.spec.js b/spec/unit/xlsx/xform/style/vertical-aligment-xform.spec.js new file mode 100644 index 000000000..ff17ad9b9 --- /dev/null +++ b/spec/unit/xlsx/xform/style/vertical-aligment-xform.spec.js @@ -0,0 +1,23 @@ +'use strict'; + +var StringXform = require('../../../../../lib/xlsx/xform/simple/string-xform'); +var testXformHelper = require('./../test-xform-helper'); + +var expectations = [ + { + title: 'superscript', + create: function() { return new StringXform({ tag: 'vertAlign', attr: 'val' }); }, + preparedModel: 'superscript', + xml: '', + parsedModel: 'superscript', + tests: ['render', 'renderIn', 'parse'] + }, + { + title: 'subscript', + create: function() { return new StringXform({ tag: 'vertAlign', attr: 'val' }); }, + preparedModel: 'subscript ', + xml: '', + parsedModel: 'subscript', + tests: ['render', 'renderIn', 'parse'] + } +]; From f82b9da40c641e8e36ba6f80567fabcb62f3ec2d Mon Sep 17 00:00:00 2001 From: MikeZyatkov Date: Fri, 26 Apr 2019 13:35:11 +0500 Subject: [PATCH 3/3] doc: Add vertical align property example to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index c27c8cfda..f2647f74d 100644 --- a/README.md +++ b/README.md @@ -877,6 +877,11 @@ ws.getCell('A2').font = { italic: true }; +// for the vertical align +ws.getCell('A3').font = { + vertAlign: 'superscript' +}; + // note: the cell will store a reference to the font object assigned. // If the font object is changed afterwards, the cell font will change also... var font = { name: 'Arial', size: 12 }; @@ -899,6 +904,7 @@ font.size = 20; // Cell A3 now has font size 20! | underline | Font underline style | true, false, 'none', 'single', 'double', 'singleAccounting', 'doubleAccounting' | | strike | Font strikethrough | true, false | | outline | Font outline | true, false | +| vertAlign | Vertical align | 'superscript', 'subscript' ### Alignment