英文:
Log File CopyTo Function Gives REF! Error With VLOOKUP Functions
问题
I'm attempting to capture data and have it be stored as log files. The cells in the original data contain VLOOKUP formulas with absolute references to a sheet called "Index". I'm able to copy everything over, but the destination cells with VLOOKUP show up as a #REF! error saying "Unresolved sheet name 'Index'". I believe this error has something to do with renaming sheets from "Copy of...[name]" to "[name]". How do I work around this?
var ss = SpreadsheetApp.openById(''); var sheet = ss.getSheetByName('Log'); var index = ss.getSheetByName("Index"); sheet.copyTo(log_file); index.copyTo(log_file); log_file.deleteSheet(log_file.getSheetByName('Sheet1')); log_file.getSheetByName("Copy of Log").setName("Log"); log_file.getSheetByName("Copy of Index").setName("Index");
This error can be resolved by entering edit mode in the cells and pressing enter, but it's not as automated as I'd like it to be.
英文:
I'm attempting to capture data and have it be stored as log files. The cells in the original data contain VLOOKUP formulas with absolute references to a sheet called "Index". I'm able to copy everything over, but the destination cells with VLOOKUP show up as a #REF! error saying "Unresolved sheet name 'Index'". I believe this error has something to do with renaming sheets from "Copy of...[name]" to "[name]". How do I work around this?
var ss = SpreadsheetApp.openById('');
var sheet = ss.getSheetByName('Log');
var index = ss.getSheetByName("Index");
sheet.copyTo(log_file);
index.copyTo(log_file);
log_file.deleteSheet(log_file.getSheetByName('Sheet1'));
log_file.getSheetByName("Copy of Log").setName("Log");
log_file.getSheetByName("Copy of Index").setName("Index");
This error can be resolved by entering edit mode in the cells and pressing enter, but it's not as automated as I'd like it to be.
答案1
得分: 0
以下是您要翻译的代码部分:
function test() {
try {
let spread = SpreadsheetApp.getActiveSpreadsheet();
let sheet1 = spread.getSheetByName("Sheet1");
let sheet2 = spread.getSheetByName("Sheet2");
spread = SpreadsheetApp.create("Testxxx");
sheet2 = sheet2.copyTo(spread);
sheet2.setName("Sheet2");
sheet1 = sheet1.copyTo(spread);
spread.deleteSheet(spread.getSheetByName("Sheet1"));
sheet1.setName("Sheet1");
sheet1.activate(); // required to move a sheet
spread.moveActiveSheet(1);
SpreadsheetApp.flush();
}
catch(err) {
console.log(err);
}
}
希望这对您有所帮助。
英文:
What you need to do is copy the sheet containing the lookup table first, rename it and then the other sheets. In my test case Sheet2 contains the lookup table. Not sure if the flush()
is need but doesn't hurt.
function test() {
try {
let spread = SpreadsheetApp.getActiveSpreadsheet();
let sheet1 = spread.getSheetByName("Sheet1");
let sheet2 = spread.getSheetByName("Sheet2");
spread = SpreadsheetApp.create("Testxxx");
sheet2 = sheet2.copyTo(spread);
sheet2.setName("Sheet2");
sheet1 = sheet1.copyTo(spread);
spread.deleteSheet(spread.getSheetByName("Sheet1"));
sheet1.setName("Sheet1");
sheet1.activate(); // required to move a sheet
spread.moveActiveSheet(1);
SpreadsheetApp.flush();
}
catch(err) {
console.log(err);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论