@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1,019 lines (838 loc) • 60.9 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(1463);
module.exports = __webpack_require__(1463);
/***/ }),
/***/ 3:
/***/ (function(module, exports) {
module.exports = function() { throw new Error("define cannot be used indirect"); };
/***/ }),
/***/ 19:
/***/ (function(module, exports) {
module.exports = require("../kendo.core");
/***/ }),
/***/ 879:
/***/ (function(module, exports) {
module.exports = require("./utils");
/***/ }),
/***/ 1463:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/***********************************************************************
* WARNING: this file is auto-generated. If you change it directly,
* your modifications will eventually be lost. The source code is in
* `kendo-ooxml` repository, you should make your changes there and
* run `src-modules/sync.sh` in this repository.
*/
(function(f, define){
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [
__webpack_require__(19),
__webpack_require__(879)
], __WEBPACK_AMD_DEFINE_FACTORY__ = (f), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
})(function(){
(function ($) {
/* jshint eqnull:true */
/* jshint laxbreak:true */
window.kendo.ooxml = window.kendo.ooxml || {};
var ooxml = kendo.ooxml;
var map = $.map;
var createZip = ooxml.createZip;
var current = {
toString: function (value) { return value; }
};
var IntlService = kendo.Class.extend({
});
IntlService.register = function(userImplementation) {
current = userImplementation;
};
IntlService.toString = function(value, format) {
return current.toString(value, format);
};
// date packing utilities from Kendo Spreadsheet
// Julian days algorithms from http://www.hermetic.ch/cal_stud/jdn.htm#comp
function dateToJulianDays(y, m, d) {
return ((1461 * (y + 4800 + ((m - 13) / 12 | 0))) / 4 | 0) +
((367 * (m - 1 - 12 * ((m - 13) / 12 | 0))) / 12 | 0) -
((3 * (((y + 4900 + ((m - 13) / 12 | 0)) / 100 | 0))) / 4 | 0) +
d - 32075;
}
// This uses the Google Spreadsheet approach: treat 1899-12-31 as day 1, allowing to avoid
// implementing the "Leap Year Bug" yet still be Excel compatible for dates starting 1900-03-01.
var BASE_DATE = dateToJulianDays(1900, 0, -1);
function packDate(year, month, date) {
return dateToJulianDays(year, month, date) - BASE_DATE;
}
function packTime(hh, mm, ss, ms) {
return (hh + (mm + (ss + ms / 1000) / 60) / 60) / 24;
}
function dateToSerial(date) {
var time = packTime(date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds());
var serial = packDate(date.getFullYear(),
date.getMonth(),
date.getDate());
return serial < 0 ? serial - 1 + time : serial + time;
}
var MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var DATA_URL_PREFIX = "data:" + MIME_TYPE + ";base64,";
var DATA_URL_OPTIONS = { compression: "DEFLATE", type: "base64" };
var BLOB_OPTIONS = { compression: "DEFLATE", type: "blob" };
var ARRAYBUFFER_OPTIONS = { compression: "DEFLATE", type: "arraybuffer" };
/* eslint-disable key-spacing, no-arrow-condition, indent, no-nested-ternary, consistent-return */
function toDataURI(content) {
return DATA_URL_PREFIX + content;
}
function indexOf(thing, array) {
return array.indexOf(thing);
}
var parseJSON = JSON.parse.bind(JSON);
function ESC(val) {
return String(val)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\"/g, """)
.replace(/\'/g, "'");
}
function repeat(count, func) {
var str = "";
for (var i = 0; i < count; ++i) {
str += func(i);
}
return str;
}
function foreach(arr, func) {
var str = "";
if (arr != null) {
if (Array.isArray(arr)) {
for (var i = 0; i < arr.length; ++i) {
str += func(arr[i], i);
}
} else if (typeof arr == "object") {
Object.keys(arr).forEach(function (key, i) {
str += func(arr[key], key, i);
});
}
}
return str;
}
var XMLHEAD = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r';
var RELS = XMLHEAD + "\n <Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n <Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\" Target=\"docProps/app.xml\"/>\n <Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\" Target=\"docProps/core.xml\"/>\n <Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"xl/workbook.xml\"/>\n </Relationships>";
var CORE = function (ref) {
var creator = ref.creator;
var lastModifiedBy = ref.lastModifiedBy;
var created = ref.created;
var modified = ref.modified;
return (XMLHEAD + "\n <cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\"\n xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\"\n xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <dc:creator>" + (ESC(creator)) + "</dc:creator>\n <cp:lastModifiedBy>" + (ESC(lastModifiedBy)) + "</cp:lastModifiedBy>\n <dcterms:created xsi:type=\"dcterms:W3CDTF\">" + (ESC(created)) + "</dcterms:created>\n <dcterms:modified xsi:type=\"dcterms:W3CDTF\">" + (ESC(modified)) + "</dcterms:modified>\n</cp:coreProperties>");
};
var APP = function (ref) {
var sheets = ref.sheets;
return (XMLHEAD + "\n<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">\n <Application>Microsoft Excel</Application>\n <DocSecurity>0</DocSecurity>\n <ScaleCrop>false</ScaleCrop>\n <HeadingPairs>\n <vt:vector size=\"2\" baseType=\"variant\">\n <vt:variant>\n <vt:lpstr>Worksheets</vt:lpstr>\n </vt:variant>\n <vt:variant>\n <vt:i4>" + (sheets.length) + "</vt:i4>\n </vt:variant>\n </vt:vector>\n </HeadingPairs>\n <TitlesOfParts>\n <vt:vector size=\"" + (sheets.length) + "\" baseType=\"lpstr\">" + (foreach(sheets, function (sheet, i) { return sheet.options.title
? ("<vt:lpstr>" + (ESC(sheet.options.title)) + "</vt:lpstr>")
: ("<vt:lpstr>Sheet" + (i + 1) + "</vt:lpstr>"); }
)) + "</vt:vector>\n </TitlesOfParts>\n <LinksUpToDate>false</LinksUpToDate>\n <SharedDoc>false</SharedDoc>\n <HyperlinksChanged>false</HyperlinksChanged>\n <AppVersion>14.0300</AppVersion>\n</Properties>");
};
var CONTENT_TYPES = function (ref) {
var sheetCount = ref.sheetCount;
var commentFiles = ref.commentFiles;
var drawingFiles = ref.drawingFiles;
return (XMLHEAD + "\n<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">\n <Default Extension=\"png\" ContentType=\"image/png\"/>\n <Default Extension=\"gif\" ContentType=\"image/gif\"/>\n <Default Extension=\"jpg\" ContentType=\"image/jpeg\"/>\n <Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\" />\n <Default Extension=\"xml\" ContentType=\"application/xml\" />\n <Default Extension=\"vml\" ContentType=\"application/vnd.openxmlformats-officedocument.vmlDrawing\"/>\n <Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\" />\n <Override PartName=\"/xl/styles.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml\"/>\n <Override PartName=\"/xl/sharedStrings.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml\"/>\n " + (repeat(sheetCount, function (idx) { return ("<Override PartName=\"/xl/worksheets/sheet" + (idx + 1) + ".xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\" />"); })) + "\n " + (foreach(commentFiles, function (filename) { return ("<Override PartName=\"/xl/" + filename + "\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml\"/>"); })) + "\n " + (foreach(drawingFiles, function (filename) { return ("<Override PartName=\"/xl/drawings/" + filename + "\" ContentType=\"application/vnd.openxmlformats-officedocument.drawing+xml\"/>"); })) + "\n <Override PartName=\"/docProps/core.xml\" ContentType=\"application/vnd.openxmlformats-package.core-properties+xml\" />\n <Override PartName=\"/docProps/app.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.extended-properties+xml\" />\n</Types>");
};
var WORKBOOK = function (ref) {
var sheets = ref.sheets;
var filterNames = ref.filterNames;
var userNames = ref.userNames;
return (XMLHEAD + "\n<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">\n <fileVersion appName=\"xl\" lastEdited=\"5\" lowestEdited=\"5\" rupBuild=\"9303\" />\n <workbookPr defaultThemeVersion=\"124226\" />\n <bookViews>\n <workbookView xWindow=\"240\" yWindow=\"45\" windowWidth=\"18195\" windowHeight=\"7995\" />\n </bookViews>\n <sheets>\n " + (foreach(sheets, function (ref, i) {
var options = ref.options;
var name = options.name || options.title || ("Sheet" + (i + 1));
return ("<sheet name=\"" + (ESC(name)) + "\" sheetId=\"" + (i + 1) + "\" r:id=\"rId" + (i + 1) + "\" />");
})) + "\n </sheets>\n " + (filterNames.length || userNames.length ? ("\n <definedNames>\n " + (foreach(filterNames, function (f) { return ("\n <definedName name=\"_xlnm._FilterDatabase\" hidden=\"1\" localSheetId=\"" + (f.localSheetId) + "\">" + (ESC(f.name)) + "!" + (ESC(f.from)) + ":" + (ESC(f.to)) + "</definedName>"); })) + "\n " + (foreach(userNames, function (f) { return ("\n <definedName name=\"" + (f.name) + "\" hidden=\"" + (f.hidden ? 1 : 0) + "\" " + (f.localSheetId != null ? ("localSheetId=\"" + (f.localSheetId) + "\"") : '') + ">" + (ESC(f.value)) + "</definedName>"); })) + "\n </definedNames>") : '') + "\n <calcPr fullCalcOnLoad=\"1\" calcId=\"145621\" />\n</workbook>");
};
var WORKSHEET = function (ref) {
var frozenColumns = ref.frozenColumns;
var frozenRows = ref.frozenRows;
var columns = ref.columns;
var defaults = ref.defaults;
var data = ref.data;
var index = ref.index;
var mergeCells = ref.mergeCells;
var autoFilter = ref.autoFilter;
var filter = ref.filter;
var showGridLines = ref.showGridLines;
var hyperlinks = ref.hyperlinks;
var validations = ref.validations;
var defaultCellStyleId = ref.defaultCellStyleId;
var rtl = ref.rtl;
var legacyDrawing = ref.legacyDrawing;
var drawing = ref.drawing;
var lastRow = ref.lastRow;
return (XMLHEAD + "\n<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">\n <dimension ref=\"A1:A" + lastRow + "\" />\n\n <sheetViews>\n <sheetView " + (rtl ? 'rightToLeft="1"' : '') + " " + (index === 0 ? 'tabSelected="1"' : '') + " workbookViewId=\"0\" " + (showGridLines === false ? 'showGridLines="0"' : '') + ">\n " + (frozenRows || frozenColumns ? ("\n <pane state=\"frozen\"\n " + (frozenColumns ? ("xSplit=\"" + frozenColumns + "\"") : '') + "\n " + (frozenRows ? ("ySplit=\"" + frozenRows + "\"") : '') + "\n topLeftCell=\"" + (String.fromCharCode(65 + (frozenColumns || 0)) + ((frozenRows || 0) + 1)) + "\"\n />") : '') + "\n </sheetView>\n </sheetViews>\n\n <sheetFormatPr x14ac:dyDescent=\"0.25\" customHeight=\"1\" defaultRowHeight=\"" + (defaults.rowHeight ? defaults.rowHeight * 0.75 : 15) + "\"\n " + (defaults.columnWidth ? ("defaultColWidth=\"" + (toWidth(defaults.columnWidth)) + "\"") : '') + " />\n\n " + (defaultCellStyleId != null || (columns && columns.length > 0) ? ("\n <cols>\n " + (!columns || !columns.length ? ("\n <col min=\"1\" max=\"16384\" style=\"" + defaultCellStyleId + "\"\n " + (defaults.columnWidth ? ("width=\"" + (toWidth(defaults.columnWidth)) + "\"") : '') + " /> ") : '') + "\n " + (foreach(columns, function (column, ci) {
var columnIndex = typeof column.index === "number" ? column.index + 1 : (ci + 1);
if (column.width === 0) {
return ("<col " + (defaultCellStyleId != null ? ("style=\"" + defaultCellStyleId + "\"") : '') + "\n min=\"" + columnIndex + "\" max=\"" + columnIndex + "\" hidden=\"1\" customWidth=\"1\" />");
}
return ("<col " + (defaultCellStyleId != null ? ("style=\"" + defaultCellStyleId + "\"") : '') + "\n min=\"" + columnIndex + "\" max=\"" + columnIndex + "\" customWidth=\"1\"\n " + (column.autoWidth
? ("width=\"" + (((column.width * 7 + 5) / 7 * 256) / 256) + "\" bestFit=\"1\"")
: ("width=\"" + (toWidth(column.width)) + "\"")) + " />");
})) + "\n </cols>") : '') + "\n\n <sheetData>\n " + (foreach(data, function (row, ri) {
var rowIndex = typeof row.index === "number" ? row.index + 1 : (ri + 1);
return ("\n <row r=\"" + rowIndex + "\" x14ac:dyDescent=\"0.25\"\n " + (row.level ? ("outlineLevel=\"" + (row.level) + "\"") : '') + "\n " + (row.height === 0 ? 'hidden="1"'
: row.height ? ("ht=\"" + (toHeight(row.height)) + "\" customHeight=\"1\"") : "") + ">\n " + (foreach(row.data, function (cell) { return ("\n <c r=\"" + (cell.ref) + "\" " + (cell.style ? ("s=\"" + (cell.style) + "\"") : '') + " " + (cell.type ? ("t=\"" + (cell.type) + "\"") : '') + ">\n " + (cell.formula != null ? writeFormula(cell.formula) : '') + "\n " + (cell.value != null ? ("<v>" + (ESC(cell.value)) + "</v>") : '') + "\n </c>"); })) + "\n </row>\n ");})) + "\n </sheetData>\n\n " + (autoFilter ? ("<autoFilter ref=\"" + (autoFilter.from) + ":" + (autoFilter.to) + "\"/>")
: filter ? spreadsheetFilters(filter) : '') + "\n\n " + (mergeCells.length ? ("\n <mergeCells count=\"" + (mergeCells.length) + "\">\n " + (foreach(mergeCells, function (ref) { return ("<mergeCell ref=\"" + ref + "\"/>"); })) + "\n </mergeCells>") : '') + "\n\n " + (validations.length ? ("\n <dataValidations>\n " + (foreach(validations, function (val) { return ("\n <dataValidation sqref=\"" + (val.sqref.join(" ")) + "\"\n showErrorMessage=\"" + (val.showErrorMessage) + "\"\n type=\"" + (ESC(val.type)) + "\"\n " + (val.type !== "list" ? ("operator=\"" + (ESC(val.operator)) + "\"") : '') + "\n allowBlank=\"" + (val.allowBlank) + "\"\n showDropDown=\"" + (val.showDropDown) + "\"\n " + (val.error ? ("error=\"" + (ESC(val.error)) + "\"") : '') + "\n " + (val.errorTitle ? ("errorTitle=\"" + (ESC(val.errorTitle)) + "\"") : '') + ">\n " + (val.formula1 ? ("<formula1>" + (ESC(val.formula1)) + "</formula1>") : '') + "\n " + (val.formula2 ? ("<formula2>" + (ESC(val.formula2)) + "</formula2>") : '') + "\n </dataValidation>"); })) + "\n </dataValidations>") : '') + "\n\n " + (hyperlinks.length ? ("\n <hyperlinks>\n " + (foreach(hyperlinks, function (link) { return ("\n <hyperlink ref=\"" + (link.ref) + "\" r:id=\"" + (link.rId) + "\"/>"); })) + "\n </hyperlinks>") : '') + "\n\n <pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\" />\n " + (legacyDrawing ? ("<legacyDrawing r:id=\"" + legacyDrawing + "\"/>") : '') + "\n " + (drawing ? ("<drawing r:id=\"" + drawing + "\"/>") : '') + "\n</worksheet>");
};
var WORKBOOK_RELS = function (ref) {
var count = ref.count;
return (XMLHEAD + "\n<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n " + (repeat(count, function (idx) { return ("\n <Relationship Id=\"rId" + (idx + 1) + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/sheet" + (idx + 1) + ".xml\" />"); })) + "\n <Relationship Id=\"rId" + (count + 1) + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\" />\n <Relationship Id=\"rId" + (count + 2) + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings\" Target=\"sharedStrings.xml\" />\n</Relationships>");
};
var WORKSHEET_RELS = function (ref) {
var hyperlinks = ref.hyperlinks;
var comments = ref.comments;
var sheetIndex = ref.sheetIndex;
var drawings = ref.drawings;
return (XMLHEAD + "\n<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n " + (foreach(hyperlinks, function (link) { return ("\n <Relationship Id=\"" + (link.rId) + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"" + (ESC(link.target)) + "\" TargetMode=\"External\" />"); })) + "\n " + (!comments.length ? '' : ("\n <Relationship Id=\"comment" + sheetIndex + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments\" Target=\"../comments" + sheetIndex + ".xml\"/>\n <Relationship Id=\"vml" + sheetIndex + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing\" Target=\"../drawings/vmlDrawing" + sheetIndex + ".vml\"/>")) + "\n " + (!drawings.length ? '' : ("\n <Relationship Id=\"drw" + sheetIndex + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing\" Target=\"../drawings/drawing" + sheetIndex + ".xml\"/>")) + "\n</Relationships>");
};
var COMMENTS_XML = function (ref) {
var comments = ref.comments;
return (XMLHEAD + "\n<comments xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">\n <authors>\n <author></author>\n </authors>\n <commentList>\n " + (foreach(comments, function (comment) { return ("\n <comment ref=\"" + (comment.ref) + "\" authorId=\"0\">\n <text>\n <r>\n <rPr>\n <sz val=\"8\"/>\n <color indexed=\"81\"/>\n <rFont val=\"Tahoma\"/>\n <charset val=\"1\"/>\n </rPr>\n <t>" + (ESC(comment.text)) + "</t>\n </r>\n </text>\n </comment>"); })) + "\n </commentList>\n</comments>");
};
var LEGACY_DRAWING = function (ref) {
var comments = ref.comments;
return ("<xml xmlns:v=\"urn:schemas-microsoft-com:vml\"\n xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n xmlns:x=\"urn:schemas-microsoft-com:office:excel\">\n <v:shapetype id=\"_x0000_t202\" path=\"m,l,21600r21600,l21600,xe\"></v:shapetype>\n " + (foreach(comments, function (comment) { return ("\n <v:shape type=\"#_x0000_t202\" style=\"visibility: hidden\" fillcolor=\"#ffffe1\" o:insetmode=\"auto\">\n <v:shadow on=\"t\" color=\"black\" obscured=\"t\"/>\n <x:ClientData ObjectType=\"Note\">\n <x:MoveWithCells/>\n <x:SizeWithCells/>\n <x:Anchor>" + (comment.anchor) + "</x:Anchor>\n <x:AutoFill>False</x:AutoFill>\n <x:Row>" + (comment.row) + "</x:Row>\n <x:Column>" + (comment.col) + "</x:Column>\n </x:ClientData>\n </v:shape>"); })) + "\n</xml>");
};
var DRAWINGS_XML = function (drawings) { return (XMLHEAD + "\n<xdr:wsDr xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\"\n xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"\n xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">\n " + (foreach(drawings, function (drawing, index) { return ("\n <xdr:oneCellAnchor editAs=\"oneCell\">\n <xdr:from>\n <xdr:col>" + (drawing.col) + "</xdr:col>\n <xdr:colOff>" + (drawing.colOffset) + "</xdr:colOff>\n <xdr:row>" + (drawing.row) + "</xdr:row>\n <xdr:rowOff>" + (drawing.rowOffset) + "</xdr:rowOff>\n </xdr:from>\n <xdr:ext cx=\"" + (drawing.width) + "\" cy=\"" + (drawing.height) + "\" />\n <xdr:pic>\n <xdr:nvPicPr>\n <xdr:cNvPr id=\"" + (index + 1) + "\" name=\"Picture " + (index + 1) + "\"/>\n <xdr:cNvPicPr/>\n </xdr:nvPicPr>\n <xdr:blipFill>\n <a:blip r:embed=\"" + (drawing.imageId) + "\"/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </xdr:blipFill>\n <xdr:spPr>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n </xdr:spPr>\n </xdr:pic>\n <xdr:clientData/>\n </xdr:oneCellAnchor>"); })) + "\n</xdr:wsDr>"); };
var DRAWINGS_RELS_XML = function (rels) { return (XMLHEAD + "\n<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n " + (foreach(rels, function (rel) { return ("\n <Relationship Id=\"" + (rel.rId) + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"" + (rel.target) + "\"/>"); })) + "\n</Relationships>"); };
var SHARED_STRINGS = function (ref) {
var count = ref.count;
var uniqueCount = ref.uniqueCount;
var indexes = ref.indexes;
return (XMLHEAD + "\n<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"" + count + "\" uniqueCount=\"" + uniqueCount + "\">\n " + (foreach(Object.keys(indexes), function (index) { return ("\n <si><t xml:space=\"preserve\">" + (ESC(index.substring(1))) + "</t></si>"); })) + "\n</sst>");
};
var STYLES = function (ref) {
var formats = ref.formats;
var fonts = ref.fonts;
var fills = ref.fills;
var borders = ref.borders;
var styles = ref.styles;
return (XMLHEAD + "\n<styleSheet\n xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"\n xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\n mc:Ignorable=\"x14ac\"\n xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\">\n <numFmts count=\"" + (formats.length) + "\">\n " + (foreach(formats, function (format, fi) { return ("\n <numFmt formatCode=\"" + (ESC(format.format)) + "\" numFmtId=\"" + (165 + fi) + "\" />"); })) + "\n </numFmts>\n <fonts count=\"" + (fonts.length + 1) + "\" x14ac:knownFonts=\"1\">\n <font>\n <sz val=\"11\" />\n <color theme=\"1\" />\n <name val=\"Calibri\" />\n <family val=\"2\" />\n <scheme val=\"minor\" />\n </font>\n " + (foreach(fonts, function (font) { return ("\n <font>\n <sz val=\"" + (font.fontSize || 11) + "\" />\n " + (font.bold ? '<b/>' : '') + "\n " + (font.italic ? '<i/>' : '') + "\n " + (font.underline ? '<u/>' : '') + "\n " + (font.color ? ("<color rgb=\"" + (ESC(font.color)) + "\" />") : '<color theme="1" />') + "\n " + (font.fontFamily ? ("\n <name val=\"" + (ESC(font.fontFamily)) + "\" />\n <family val=\"2\" />\n ") : "\n <name val=\"Calibri\" />\n <family val=\"2\" />\n <scheme val=\"minor\" />\n ") + "\n </font>"); })) + "\n </fonts>\n <fills count=\"" + (fills.length + 2) + "\">\n <fill><patternFill patternType=\"none\"/></fill>\n <fill><patternFill patternType=\"gray125\"/></fill>\n " + (foreach(fills, function (fill) { return ("\n " + (fill.background ? ("\n <fill>\n <patternFill patternType=\"solid\">\n <fgColor rgb=\"" + (ESC(fill.background)) + "\"/>\n </patternFill>\n </fill>\n ") : '')); })) + "\n </fills>\n <borders count=\"" + (borders.length + 1) + "\">\n <border><left/><right/><top/><bottom/><diagonal/></border>\n " + (foreach(borders, borderTemplate)) + "\n </borders>\n <cellStyleXfs count=\"1\">\n <xf borderId=\"0\" fillId=\"0\" fontId=\"0\" />\n </cellStyleXfs>\n <cellXfs count=\"" + (styles.length + 1) + "\">\n <xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" />\n " + (foreach(styles, function (style) { return ("\n <xf xfId=\"0\"\n " + (style.fontId ? ("fontId=\"" + (style.fontId) + "\" applyFont=\"1\"") : '') + "\n " + (style.fillId ? ("fillId=\"" + (style.fillId) + "\" applyFill=\"1\"") : '') + "\n " + (style.numFmtId ? ("numFmtId=\"" + (style.numFmtId) + "\" applyNumberFormat=\"1\"") : '') + "\n " + (style.textAlign || style.verticalAlign || style.wrap ? 'applyAlignment="1"' : '') + "\n " + (style.borderId ? ("borderId=\"" + (style.borderId) + "\" applyBorder=\"1\"") : '') + ">\n " + (style.textAlign || style.verticalAlign || style.wrap ? ("\n <alignment\n " + (style.textAlign ? ("horizontal=\"" + (ESC(style.textAlign)) + "\"") : '') + "\n " + (style.verticalAlign ? ("vertical=\"" + (ESC(style.verticalAlign)) + "\"") : '') + "\n " + (style.indent ? ("indent=\"" + (ESC(style.indent)) + "\"") : '') + "\n " + (style.wrap ? 'wrapText="1"' : '') + " />\n ") : '') + "\n </xf>\n "); })) + "\n </cellXfs>\n <cellStyles count=\"1\">\n <cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/>\n </cellStyles>\n <dxfs count=\"0\" />\n <tableStyles count=\"0\" defaultTableStyle=\"TableStyleMedium2\" defaultPivotStyle=\"PivotStyleMedium9\" />\n</styleSheet>");
};
function writeFormula(formula) {
if (typeof formula == "string") {
return ("<f>" + (ESC(formula)) + "</f>");
}
// array formulas
return ("<f t=\"array\" ref=\"" + (formula.ref) + "\">" + (ESC(formula.src)) + "</f>");
}
function numChar(colIndex) {
var letter = Math.floor(colIndex / 26) - 1;
return (letter >= 0 ? numChar(letter) : "") + String.fromCharCode(65 + (colIndex % 26));
}
function ref(rowIndex, colIndex) {
return numChar(colIndex) + (rowIndex + 1);
}
function $ref(rowIndex, colIndex) {
return "$" + numChar(colIndex) + "$" + (rowIndex + 1);
}
function filterRowIndex(options) {
var frozenRows = options.frozenRows || (options.freezePane || {}).rowSplit || 1;
return frozenRows - 1;
}
function toWidth(px) {
var maximumDigitWidth = 7;
return (px / maximumDigitWidth) - (Math.floor(128 / maximumDigitWidth) / 256);
}
function toHeight(px) {
return px * 0.75;
}
function stripFunnyChars(value) {
return String(value)
.replace(/[\x00-\x09\x0B\x0C\x0E-\x1F]/g, "") // leave CRLF in
.replace(/\r?\n/g, "\r\n"); // make sure LF is preceded by CR
}
var Worksheet = kendo.Class.extend({
init: function(options, sharedStrings, styles, borders) {
this.options = options;
this._strings = sharedStrings;
this._styles = styles;
this._borders = borders;
this._validations = {};
this._comments = [];
this._drawings = options.drawings || [];
this._hyperlinks = (this.options.hyperlinks || []).map(
function (link, i) { return $.extend({}, link, { rId: ("link" + i) }); });
},
relsToXML: function() {
var hyperlinks = this._hyperlinks;
var comments = this._comments;
var drawings = this._drawings;
if (hyperlinks.length || comments.length || drawings.length) {
return WORKSHEET_RELS({
hyperlinks : hyperlinks,
comments : comments,
sheetIndex : this.options.sheetIndex,
drawings : drawings
});
}
},
toXML: function(index) {
var this$1 = this;
var mergeCells = this.options.mergedCells || [];
var rows = this.options.rows || [];
var data = inflate(rows, mergeCells);
this._readCells(data);
var autoFilter = this.options.filter;
var filter;
if (autoFilter && (typeof autoFilter.from === "number") && (typeof autoFilter.to === "number")) {
// Grid enables auto filter
autoFilter = {
from: ref(filterRowIndex(this.options), autoFilter.from),
to: ref(filterRowIndex(this.options), autoFilter.to)
};
} else if (autoFilter && autoFilter.ref && autoFilter.columns) {
// this is probably from the Spreadsheet
filter = autoFilter;
autoFilter = null;
}
var validations = [];
for (var i in this._validations) {
if (Object.prototype.hasOwnProperty.call(this$1._validations, i)) {
validations.push(this$1._validations[i]);
}
}
var defaultCellStyleId = null;
if (this.options.defaultCellStyle) {
defaultCellStyleId = this._lookupStyle(this.options.defaultCellStyle);
}
var freezePane = this.options.freezePane || {};
var defaults = this.options.defaults || {};
var lastRow = this.options.rows ? this._getLastRow() : 1;
return WORKSHEET({
frozenColumns: this.options.frozenColumns || freezePane.colSplit,
frozenRows: this.options.frozenRows || freezePane.rowSplit,
columns: this.options.columns,
defaults: defaults,
data: data,
index: index,
mergeCells: mergeCells,
autoFilter: autoFilter,
filter: filter,
showGridLines: this.options.showGridLines,
hyperlinks: this._hyperlinks,
validations: validations,
defaultCellStyleId: defaultCellStyleId,
rtl: this.options.rtl !== undefined ? this.options.rtl : defaults.rtl,
legacyDrawing: this._comments.length ? ("vml" + (this.options.sheetIndex)) : null,
drawing: this._drawings.length ? ("drw" + (this.options.sheetIndex)) : null,
lastRow: lastRow
});
},
commentsXML: function() {
if (this._comments.length) {
return COMMENTS_XML({ comments: this._comments });
}
},
drawingsXML: function(images) {
if (this._drawings.length) {
var rels = {};
var main = this._drawings.map(function (drw) {
var ref = parseRef(drw.topLeftCell);
var img = rels[drw.image];
if (!img) {
img = rels[drw.image] = {
rId: ("img" + (drw.image)),
target: images[drw.image].target
};
}
return {
col : ref.col,
colOffset : pixelsToExcel(drw.offsetX),
row : ref.row,
rowOffset : pixelsToExcel(drw.offsetY),
width : pixelsToExcel(drw.width),
height : pixelsToExcel(drw.height),
imageId : img.rId
};
});
return {
main: DRAWINGS_XML(main),
rels: DRAWINGS_RELS_XML(rels)
};
}
},
legacyDrawing: function() {
if (this._comments.length) {
return LEGACY_DRAWING({ comments: this._comments });
}
},
_lookupString: function(value) {
var key = "$" + value;
var index = this._strings.indexes[key];
var result;
if (index !== undefined) {
result = index;
} else {
result = this._strings.indexes[key] = this._strings.uniqueCount;
this._strings.uniqueCount ++;
}
this._strings.count ++;
return result;
},
_lookupStyle: function(style) {
var json = JSON.stringify(style);
if (json === "{}") {
return 0;
}
var index = indexOf(json, this._styles);
if (index < 0) {
index = this._styles.push(json) - 1;
}
// There is one default style
return index + 1;
},
_lookupBorder: function(border) {
var json = JSON.stringify(border);
if (json === "{}") {
return;
}
var index = indexOf(json, this._borders);
if (index < 0) {
index = this._borders.push(json) - 1;
}
// There is one default border
return index + 1;
},
_readCells: function(rowData) {
var this$1 = this;
for (var i = 0; i < rowData.length; i++) {
var row = rowData[i];
var cells = row.cells;
row.data = [];
for (var j = 0; j < cells.length; j++) {
var cellData = this$1._cell(cells[j], row.index, j);
if (cellData) {
row.data.push(cellData);
}
}
}
},
_cell: function(data, rowIndex, cellIndex) {
if (!data || data === EMPTY_CELL) {
return null;
}
var value = data.value;
var border = {};
if (data.borderLeft) {
border.left = data.borderLeft;
}
if (data.borderRight) {
border.right = data.borderRight;
}
if (data.borderTop) {
border.top = data.borderTop;
}
if (data.borderBottom) {
border.bottom = data.borderBottom;
}
border = this._lookupBorder(border);
var defStyle = this.options.defaultCellStyle || {};
var style = { borderId: border };
(function(add) {
add("color");
add("background");
add("bold");
add("italic");
add("underline");
if (!add("fontFamily")) { add("fontName", "fontFamily"); }
add("fontSize");
add("format");
if (!add("textAlign")) { add("hAlign", "textAlign"); }
if (!add("verticalAlign")) { add("vAlign", "verticalAlign"); }
add("wrap");
add("indent");
})(
function(prop, target) {
var val = data[prop];
if (val === undefined) {
val = defStyle[prop];
}
if (val !== undefined) {
style[target || prop] = val;
return true;
}
}
);
var columns = this.options.columns || [];
var column = columns[cellIndex];
var type = typeof value;
if (column && column.autoWidth) {
var displayValue = value;
// XXX: let's not bring kendo.toString in only for this.
// better wait until the spreadsheet engine is available as a separate
// component, then we can use a real Excel-like formatter.
//
if (type === "number") {
// kendo.toString will not behave exactly like the Excel format
// Still, it's the best we have available for estimating the character count.
displayValue = IntlService.toString(value, data.format);
}
column.width = Math.max(column.width || 0, String(displayValue).length);
}
if (type === "string") {
value = stripFunnyChars(value);
value = this._lookupString(value);
type = "s";
} else if (type === "number") {
type = "n";
} else if (type === "boolean") {
type = "b";
value = Number(value);
} else if (value && value.getTime) {
type = null;
value = dateToSerial(value);
if (!style.format) {
style.format = "mm-dd-yy";
}
} else {
type = null;
value = null;
}
style = this._lookupStyle(style);
var cellName = ref(rowIndex, cellIndex);
if (data.validation) {
this._addValidation(data.validation, cellName);
}
if (data.comment) {
var anchor = [
cellIndex + 1, // start column
15, // start column offset
rowIndex, // start row
10, // start row offset
cellIndex + 3, // end column
15, // end column offset
rowIndex + 3, // end row
4 // end row offset
];
this._comments.push({
ref : cellName,
text : data.comment,
row : rowIndex,
col : cellIndex,
anchor : anchor.join(", ")
});
}
return {
value: value,
formula: data.formula,
type: type,
style: style,
ref: cellName
};
},
_addValidation: function(v, ref) {
var tmp = {
showErrorMessage : v.type === "reject" ? 1 : 0,
formula1 : v.from,
formula2 : v.to,
type : MAP_EXCEL_TYPE[v.dataType] || v.dataType,
operator : MAP_EXCEL_OPERATOR[v.comparerType] || v.comparerType,
allowBlank : v.allowNulls ? 1 : 0,
showDropDown : v.showButton ? 0 : 1, // LOL, Excel!
error : v.messageTemplate,
errorTitle : v.titleTemplate
};
var json = JSON.stringify(tmp);
if (!this._validations[json]) {
this._validations[json] = tmp;
tmp.sqref = [];
}
this._validations[json].sqref.push(ref);
},
_getLastRow: function() {
var rows = this.options.rows;
var lastRow = rows.length;
rows.forEach(function(row) {
if (row.index && row.index >= lastRow) {
lastRow = row.index + 1;
}
});
return lastRow;
}
});
var MAP_EXCEL_OPERATOR = {
// includes only what differs; key is our operator, value is Excel
// operator.
greaterThanOrEqualTo : "greaterThanOrEqual",
lessThanOrEqualTo : "lessThanOrEqual"
};
var MAP_EXCEL_TYPE = {
number: "decimal"
};
var defaultFormats = {
"General": 0,
"0": 1,
"0.00": 2,
"#,##0": 3,
"#,##0.00": 4,
"0%": 9,
"0.00%": 10,
"0.00E+00": 11,
"# ?/?": 12,
"# ??/??": 13,
"mm-dd-yy": 14,
"d-mmm-yy": 15,
"d-mmm": 16,
"mmm-yy": 17,
"h:mm AM/PM": 18,
"h:mm:ss AM/PM": 19,
"h:mm": 20,
"h:mm:ss": 21,
"m/d/yy h:mm": 22,
"#,##0 ;(#,##0)": 37,
"#,##0 ;[Red](#,##0)": 38,
"#,##0.00;(#,##0.00)": 39,
"#,##0.00;[Red](#,##0.00)": 40,
"mm:ss": 45,
"[h]:mm:ss": 46,
"mmss.0": 47,
"##0.0E+0": 48,
"@": 49,
"[$-404]e/m/d": 27,
"m/d/yy": 30,
"t0": 59,
"t0.00": 60,
"t#,##0": 61,
"t#,##0.00": 62,
"t0%": 67,
"t0.00%": 68,
"t# ?/?": 69,
"t# ??/??": 70
};
function convertColor(value) {
var color = value;
if (color.length < 6) {
color = color.replace(/(\w)/g, function($0, $1) {
return $1 + $1;
});
}
color = color.substring(1).toUpperCase();
if (color.length < 8) {
color = "FF" + color;
}
return color;
}
var Workbook = kendo.Class.extend({
init: function(options) {
var this$1 = this;
this.options = options || {};
this._strings = {
indexes: {},
count: 0,
uniqueCount: 0
};
this._styles = [];
this._borders = [];
this._images = this.options.images;
this._imgId = 0;
this._sheets = map(this.options.sheets || [], function (options, i) {
options.defaults = this$1.options;
options.sheetIndex = i + 1;
return new Worksheet(options, this$1._strings, this$1._styles, this$1._borders);
});
},
imageFilename: function(mimeType) {
var id = ++this._imgId;
switch (mimeType) {
case "image/jpg":
case "image/jpeg":
return ("image" + id + ".jpg");
case "image/png":
return ("image" + id + ".png");
case "image/gif":
return ("image" + id + ".gif");
default:
return ("image" + id + ".bin"); // XXX: anything better to do here?
}
},
toZIP: function() {
var this$1 = this;
var zip = createZip();
var docProps = zip.folder("docProps");
docProps.file("core.xml", CORE({
creator: this.options.creator || "Kendo UI",
lastModifiedBy: this.options.creator || "Kendo UI",
created: this.options.date || new Date().toJSON(),
modified: this.options.date || new Date().toJSON()
}));
var sheetCount = this._sheets.length;
docProps.file("app.xml", APP({ sheets: this._sheets }));
var rels = zip.folder("_rels");
rels.file(".rels", RELS);
var xl = zip.folder("xl");
var xlRels = xl.folder("_rels");
xlRels.file("workbook.xml.rels", WORKBOOK_RELS({ count: sheetCount }));
if (this._images) {
var media = xl.folder("media");
Object.keys(this._images).forEach(function (id) {
var img = this$1._images[id];
var filename = this$1.imageFilename(img.type);
media.file(filename, img.data);
img.target = "../media/" + filename;
});
}
var sheetIds = {};
xl.file("workbook.xml", WORKBOOK({
sheets: this._sheets,
filterNames: map(this._sheets, function(sheet, index) {
var options = sheet.options;
var sheetName = (options.name || options.title || "Sheet" + (index + 1));
sheetIds[sheetName.toLowerCase()] = index;
var filter = options.filter;
if (filter) {
if (filter.ref) {
// spreadsheet provides `ref`
var a = filter.ref.split(":");
var from = parseRef(a[0]);
var to = parseRef(a[1]);
return {
localSheetId: index,
name: sheetName,
from: $ref(from.row, from.col),
to: $ref(to.row, to.col)
};
} else if (typeof filter.from !== "undefined" && typeof filter.to !== "undefined") {
// grid does this
return {
localSheetId: index,
name: sheetName,
from: $ref(filterRowIndex(options), filter.from),
to: $ref(filterRowIndex(options), filter.to)
};
}
}
}),
userNames: map(this.options.names || [], function(def) {
return {
name: def.localName,
localSheetId: def.sheet ? sheetIds[def.sheet.toLowerCase()] : null,
value: def.value,
hidden: def.hidden
};
})
}));
var worksheets = xl.folder("worksheets");
var drawings = xl.folder("drawings");
var drawingsRels = drawings.folder("_rels");
var sheetRels = worksheets.folder("_rels");
var commentFiles = [];
var drawingFiles = [];
for (var idx = 0; idx < sheetCount; idx++) {
var sheet = this$1._sheets[idx];
var sheetName = "sheet" + (idx + 1) + ".xml";
var sheetXML = sheet.toXML(idx); // must be called before relsToXML
var relsXML = sheet.relsToXML();
var commentsXML = sheet.commentsXML();
var legacyDrawing = sheet.legacyDrawing();
var drawingsXML = sheet.drawingsXML(this$1._images);
if (relsXML) {
sheetRels.file(sheetName + ".rels", relsXML);
}
if (commentsXML) {
var name = "comments" + (sheet.options.sheetIndex) + ".xml";
xl.file(name, commentsXML);
commentFiles.push(name);
}
if (legacyDrawing) {
drawings.file(("vmlDrawing" + (sheet.options.sheetIndex) + ".vml"), legacyDrawing);
}
if (drawingsXML) {
var name$1 = "drawing" + (sheet.options.sheetIndex) + ".xml";
drawings.file(name$1, drawingsXML.main);
drawingsRels.file((name$1 + ".rels"), drawingsXML.rels);
drawingFiles.push(name$1);
}
worksheets.file(sheetName, sheetXML);
}
var borders = map(this._borders, parseJSON);
var styles = map(this._styles, parseJSON);
var hasFont = function(style) {
return style.underline || style.bold || style.italic || style.color || style.fontFamily || style.fontSize;
};
var convertFontSize = function(value) {
var fontInPx = Number(value);
var fontInPt;
if (fontInPx) {
fontInPt = fontInPx * 3 / 4;
}
return fontInPt;
};
var fonts = map(styles, function(style) {
if (style.fontSize) {
style.fontSize = convertFontSize(style.fontSize);
}
if (style.color) {
style.color = convertColor(style.color);
}
if (hasFont(style)) {
return style;
}
});
var formats = map(styles, function(style) {
if (style.format && defaultFormats[style.format] === undefined) {
return style;
}
});
var fills = map(styles, function(style) {
if (style.background) {
style.background = convertColor(style.background);
return style;
}
});
xl.file("styles.xml", STYLES({
fonts: fonts,
fills: fills,
formats: formats,
borders: borders,
styles: map(styles, function(style) {
var result = {};
if (hasFont(style)) {
result.fontId = indexOf(style, fonts) + 1;
}
if (style.background) {
result.fillId = indexOf(style, fills) + 2;
}
result.textAlign = style.textAlign;
result.indent = style.indent;
result.verticalAlign = style.verticalAlign;