Browse Source

Fixed issues when copying sheets:

sheet name length could exceed 31 char
sheet name could take into account another sheet name that contains but not starts with the name (sheets: ABCD(Copy), BCD; copying BCD results in BCD(Copy2))
master
Andrey Khaneev 3 years ago
parent
commit
49bafe3443
  1. 93
      src/controllers/sheetmanage.js

93
src/controllers/sheetmanage.js

@ -73,77 +73,52 @@ const sheetmanage = {
} }
}, },
generateCopySheetName: function(file, name) { generateCopySheetName: function(file, name) {
let copySheetName = "";
let _locale = locale(); let _locale = locale();
let locale_info = _locale.info; let locale_info = _locale.info;
let copyWord = "(" + locale_info.copy;
const copy_i = name.toString().indexOf(copyWord);
if(name.toString().indexOf("("+locale_info.copy) > -1){ if (copy_i > -1) {
let copy_i = name.toString().indexOf("("+locale_info.copy); name = name.toString().substring(0, copy_i);
let name2 = name.toString().substring(0, copy_i) + "("+locale_info.copy; }
let index = null;
for(let i = 0; i < file.length; i++){
let fileName = file[i].name.toString();
let st_i = fileName.indexOf(name2);
if(st_i > -1){ let index = "";
let ed_i = fileName.indexOf(")", st_i + name2.length); let nameCopy = name + copyWord;
let num = fileName.substring(st_i + name2.length, ed_i); const sheetNames = [];
if(isRealNum(num)){ for(let i = 0; i < file.length; i++){
if(index == null || parseInt(num) > index){ let fileName = file[i].name.toString();
index = parseInt(num); sheetNames.push(fileName);
} let st_i = fileName.indexOf(nameCopy);
if(st_i === 0){
index = index || 2;
let ed_i = fileName.indexOf(")", st_i + nameCopy.length);
let num = fileName.substring(st_i + nameCopy.length, ed_i);
if(isRealNum(num)){
if(parseInt(num) >= index){
index = parseInt(num) + 1;
} }
} }
} }
if(index == null){
copySheetName = name2 + "2)";
}
else{
index++;
copySheetName = name2 + index + ")";
}
} }
else{
let index = null;
let hascopy = false;
let name2 = name + "("+locale_info.copy;
for(let i = 0; i < file.length; i++){
let fileName = file[i].name.toString();
let st_i = fileName.indexOf(name2);
if(st_i > -1){
hascopy = true;
let ed_i = fileName.indexOf(")", st_i + name2.length);
let num = fileName.substring(st_i + name2.length, ed_i);
if(isRealNum(num)){
if(index == null || parseInt(num) > index){
index = parseInt(num);
}
}
}
}
if(hascopy){ let sheetCopyName;
if(index == null){
copySheetName = name + "("+ locale_info.copy +"2)"; do {
} let postfix = copyWord + index + ")";
else{
index++; const lengthLimit = 31 - postfix.length;
copySheetName = name + "("+ locale_info.copy +"" + index + ")"; sheetCopyName = name;
} if (sheetCopyName.length > lengthLimit) {
} sheetCopyName = sheetCopyName.slice(0, lengthLimit - 1) + "…";
else{
copySheetName = name + "("+ locale_info.copy +")";
} }
}
return copySheetName; sheetCopyName = sheetCopyName + postfix;
} while (~sheetNames.indexOf(sheetCopyName) && (index = (index || 1) + 1))
return sheetCopyName;
}, },
getSheetByIndex: function(index) { getSheetByIndex: function(index) {
let _this = this; let _this = this;

Loading…
Cancel
Save