Update index.js

This commit is contained in:
SkyKilla
2016-08-30 17:13:20 +07:00
committed by GitHub
parent ddf79ca02a
commit aeb2f9f5b1
+23 -23
View File
@@ -33,32 +33,32 @@ module.exports = (function() {
/**
* Delete unused sheets if needed
*/
Workbook.prototype.deleteSheet = function(sheetName){
var self = this;
var sheet = self.loadSheet(sheetName);
Workbook.prototype.deleteSheet = function(sheetName){
var self = this;
var sheet = self.loadSheet(sheetName);
Object.keys(self.archive.files).forEach(key=>{
if (key.indexOf(sheet.id) != -1)
delete self.archive.files[key];
})
Object.keys(self.archive.files).forEach(key=>{
if (key.indexOf(sheet.id) != -1)
delete self.archive.files[key];
})
var i = self.sheets.findIndex(el=> el.id == sheet.id);
self.sheets.splice(i, 1);
var el = self.workbook._children.find(item=>item.tag==='sheets');
if (!el) throw new Error("Template file contain errors");
//sheet.rId = el._children[i].attrib['r:id'];
el._children.splice(i,1);
var i = self.sheets.findIndex(el=> el.id == sheet.id);
self.sheets.splice(i, 1);
el = self.workbook._children.find(item=>item.tag==='definedNames');
if (el) {
el._children.splice(i,1);
el._children.forEach((item, index)=>{item.attrib.localSheetId = String(index)}) // fix to avoid opening errors
}
var el = self.workbook._children.find(item=>item.tag==='sheets');
if (!el) throw new Error("Template file contain errors");
// sheet.rId = el._children[i].attrib['r:id'];
el._children.splice(i,1);
el = self.workbook._children.find(item=>item.tag==='definedNames');
if (el) {
el._children.splice(i,1);
el._children.forEach((item, index)=>{item.attrib.localSheetId = String(index)}) // fix to avoid opening errors
}
self.archive.file(sheet.filename, etree.tostring(sheet.root));
self.archive.file(self.workbookPath, etree.tostring(self.workbook));
};
self.archive.file(sheet.filename, etree.tostring(sheet.root));
self.archive.file(self.workbookPath, etree.tostring(self.workbook));
};
/**
* Load a .xlsx file from a byte array.