UNPKG

excel-builder

Version:

An easy way of building Excel files with javascript

86 lines (77 loc) 3.11 kB
/** * @module Excel/SheetView * * https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.sheetview%28v=office.14%29.aspx * */ "use strict"; var _ = require('lodash'); var Pane = require('./Pane'); var util = require('./util') var SheetView = function (config) { config = config || {}; this.pane = config.pane || new Pane(); this.showZeros = null; //Default this.defaultGridColor = null; this.colorId = null; this.rightToLeft = null; this.showFormulas = null; this.showGridLines = null; this.showOutlineSymbols = null; this.showRowColHeaders = null; this.showRuler = null; this.showWhiteSpace = null; this.tabSelected = null; this.topLeftCell = null; this.viewType = null; //http://www.datypic.com/sc/ooxml/t-ssml_ST_SheetViewType.html this.windowProtection = null; this.zoomScale = null; this.zoomScaleNormal = null; this.zoomScalePageLayoutView = null; this.zoomScaleSheetLayoutView = null; }; _.extend(SheetView.prototype, { /** * Added froze pane * @param column - column number: 0, 1, 2 ... * @param row - row number: 0, 1, 2 ... * @param cell - 'A1' * @deprecated */ freezePane: function(column, row, cell) { this.pane.state = 'frozen'; this.pane.xSplit = column; this.pane.ySplit = row; this.pane.topLeftCell = cell; }, exportXML: function (doc) { var sheetViews = doc.createElement('sheetViews'), sheetView = doc.createElement('sheetView'); util.setAttributesOnDoc(sheetView, { //TODO apparent you can add 'book views'.. investigate what these are workbookViewId: 0, showZeros: {v: this.showZeros, type: Boolean}, defaultGridColor: {v: this.defaultGridColor, type: Boolean}, //TODO: I have no idea what this even is :\ colorId: this.colorId, rightToLeft: {v: this.rightToLeft, type: Boolean}, showFormulas: {v: this.showFormulas, type: Boolean}, showGridLines: {v: this.showGridLines, type: Boolean}, showOutlineSymbols: {v: this.showOutlineSymbols, type: Boolean}, showRowColHeaders: {v: this.showRowColHeaders, type: Boolean}, showRuler: {v: this.showRuler, type: Boolean}, showWhiteSpace: {v: this.showWhiteSpace, type: Boolean}, tabSelected: {v: this.tabSelected, type: Boolean}, viewType: this.viewType, windowProtection: {v: this.windowProtection, type: Boolean}, zoomScale: {v: this.zoomScale, type: Boolean}, zoomScaleNormal: this.zoomScaleNormal, zoomScalePageLayoutView: this.zoomScalePageLayoutView, zoomScaleSheetLayoutView: this.zoomScaleSheetLayoutView }); sheetView.appendChild(this.pane.exportXML(doc)); sheetViews.appendChild(sheetView); return sheetViews; } }); module.exports = SheetView;