mirror of
https://github.com/optilude/xlsx-template.git
synced 2026-07-02 08:27:39 +08:00
Update index.js
This commit is contained in:
+23
-23
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user