UNPKG

@fusioncharts/features

Version:

FusionCharts JavaScript charting framework

1 lines 3.13 kB
"use strict";exports.__esModule=true;exports.default=void 0;var _xlutil=require("./xlutil.js");var CreateSheets=exports.default=function(){function CreateSheets(){this.sheets=[]}var _proto=CreateSheets.prototype;_proto.addSheet=function addSheet(sheetName){this.sheets.push({id:this.sheets.length+1,rId:"rId"+(3+this.sheets.length),name:sheetName,rows:{}})};_proto.createCell=function createCell(cellObj){if(!(cellObj.sheet===parseInt(cellObj.sheet,10)))throw new Error("Invalid sheet number"+cellObj.sheet);if(!(cellObj.row===parseInt(cellObj.row,10)))throw new Error("Invalid row number "+cellObj.row+"in sheet "+cellObj.sheet);if(!(cellObj.column===parseInt(cellObj.column,10)))throw new Error("Invalid column number "+cellObj.column+"in row "+cellObj.row+" in sheet "+cellObj.sheet);var sheet=cellObj.sheet,row=cellObj.row,column=cellObj.column,value=cellObj.value;if(this.sheets[sheet]){if(this.sheets[sheet].rows[row]){this.sheets[sheet].rows[row][column]=value}else{var _this$sheets$sheet$ro;this.sheets[sheet].rows[row]=(_this$sheets$sheet$ro={},_this$sheets$sheet$ro[column]=value,_this$sheets$sheet$ro)}}else{throw new Error(" Sheet"+sheet+" does not exists")}};_proto.createWorkBook=function createWorkBook(){var newsheet='<?xml version="1.0" standalone="yes"?>'+'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'+"<sheets>";for(var i=0;i<this.sheets.length;i++)newsheet=newsheet+(0,_xlutil.getWorkBookSheet)(this.sheets[i]);return newsheet+"</sheets><calcPr/></workbook>"};_proto.createworkBookRels=function createworkBookRels(){var newsheet='<?xml version="1.0" ?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">';newsheet=newsheet+'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>';for(var i=0;i<this.sheets.length;i++)newsheet=newsheet+(0,_xlutil.toWorkBookRel)(this.sheets[i],i+1);return newsheet+"</Relationships>"};_proto.createContentType=function createContentType(){var newsheet='<?xml version="1.0" standalone="yes" ?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default ContentType="application/xml" Extension="xml"/>';newsheet=newsheet+'<Default ContentType="application/vnd.openxmlformats-package.relationships+xml" Extension="rels"/>';newsheet=newsheet+'<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" PartName="/xl/workbook.xml"/>';newsheet=newsheet+'<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml" />';for(var i=1;i<=this.sheets.length;i++)newsheet=newsheet+'<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet'+i+'.xml"/>';return newsheet+"</Types>"};_proto.fileSheets=function fileSheets(folder){for(var i=0;i<this.sheets.length;i++){folder.file("worksheets/sheet"+(i+1)+".xml",(0,_xlutil.generateSheet)(this.sheets[i]))}};return CreateSheets}();