exceljs
Version:
Excel Workbook Manager - Read and Write xlsx and csv Files.
92 lines (82 loc) • 2.44 kB
JavaScript
/**
* Copyright (c) 2015 Guyon Roche
* LICENCE: MIT - please refer to LICENCE file included with this module
* or https://github.com/guyonroche/exceljs/blob/master/LICENSE
*/
;
var utils = require('../../../utils/utils');
var BaseXform = require('../base-xform');
var ColXform = module.exports = function () {};
utils.inherits(ColXform, BaseXform, {
get tag() {
return 'col';
},
prepare: function prepare(model, options) {
var styleId = options.styles.addStyleModel(model.style || {});
if (styleId) {
model.styleId = styleId;
}
},
render: function render(xmlStream, model) {
xmlStream.openNode('col');
xmlStream.addAttribute('min', model.min);
xmlStream.addAttribute('max', model.max);
if (model.width) {
xmlStream.addAttribute('width', model.width);
}
if (model.styleId) {
xmlStream.addAttribute('style', model.styleId);
}
if (model.hidden) {
xmlStream.addAttribute('hidden', '1');
}
if (model.bestFit) {
xmlStream.addAttribute('bestFit', '1');
}
if (model.outlineLevel) {
xmlStream.addAttribute('outlineLevel', model.outlineLevel);
}
if (model.collapsed) {
xmlStream.addAttribute('collapsed', '1');
}
xmlStream.addAttribute('customWidth', '1');
xmlStream.closeNode();
},
parseOpen: function parseOpen(node) {
if (node.name === 'col') {
var model = this.model = {
min: parseInt(node.attributes.min || '0', 10),
max: parseInt(node.attributes.max || '0', 10),
width: parseFloat(node.attributes.width || '0')
};
if (node.attributes.style) {
model.styleId = parseInt(node.attributes.style, 10);
}
if (node.attributes.hidden) {
model.hidden = true;
}
if (node.attributes.bestFit) {
model.bestFit = true;
}
if (node.attributes.outlineLevel) {
model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
}
if (node.attributes.collapsed) {
model.collapsed = true;
}
return true;
}
return false;
},
parseText: function parseText() {},
parseClose: function parseClose() {
return false;
},
reconcile: function reconcile(model, options) {
// reconcile column styles
if (model.styleId) {
model.style = options.styles.getStyleModel(model.styleId);
}
}
});
//# sourceMappingURL=col-xform.js.map