I've been trying to copy only the content (no equations such as =IMPORTRANGE) of a spreadsheet into a new spreadsheet. I have found a solution however I was wondering if there was an easier way to do this?
I ended up iterating through each sheet in the original spreadsheet, getting the data range of each sheet, getting those values, copying each sheet into the new spreadsheet with .copyTo, deleting the "Sheet1" created with the new spreadsheet, then iterating through the new spreadsheet and pasting the values to each new sheet in the spreadsheet.
function copySpreadsheetContent() {
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var sheetNums = ss1.getNumSheets();
var ssNew = SpreadsheetApp.create('Test Spreadsheet').getId();
var ss2 = SpreadsheetApp.openById(ssNew);
var ss2Nums = ss2.getNumSheets();
var sheetVals = [];
for(var i = 0; i < sheetNums; i++){
var sheet = ss1.getSheets()[i];
sheetVals[i] = sheet.getDataRange().getValues();
var newSheet = sheet.copyTo(ss2);
newSheet.setName(sheet.getName());
}
var sheet1 = ss2.getSheetByName("Sheet1");
ss2.deleteSheet(sheet1);
for(var j = 0; j <= ss2Nums; j++){
var ss2Sheet = ss2.getSheets()[j];
ss2Sheet.getDataRange().setValues(sheetVals[j]);
}
}
This provides the desired results as far as I can tell, however it just seems like a really roundabout way of doing things and I was hoping someone might be able to point me to a more efficient or straightforward method.
Thanks for the help