My question is very similar to this one, except I have formulas in my excel file which means all the data ends up being #error.
Importing XLSX file from the monthly e-mail (in Gmail) to the designated Google Sheet
Recap, I get an excel by email which I need to convert to google sheet where I already have a script which runs to pull data and then upload stock values.
Everything works well except for this one source where there are formulas in the excel file.
There's a few formulas in the excel sheet but only one column (P) I really need which has the below formula in it. It looks up the stock id to another sheet that I don't have.
=IF(ISERROR(VLOOKUP(A2,'W:\Stock\Stockboard.xlsx]Stock'!$B:$N,13,FALSE)),0,VLOOKUP(A2,'W:\Stock\[Stockboard.xlsx]Stock'!$B:$N,13,FALSE))
The sheet opens in excel and excel understandably has the ability to not refresh and therefore not show errors. When I manually export to csv it's also fine.
This is the code at the moment, which is the same as the original post.
var thread = GmailApp.search("from:(email) Stock Update has:attachment",0,1)[0];
var message = thread.getMessages()[0];
var xlFile = message.getAttachments()[0];
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlFile).id;
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // There is the data in 1st tab.
var data = sheet.getDataRange().getValues();
ss.getSheetByName("test").getRange(1,1,data.length, data[0].length).setValues(data);
Drive.Files.remove(convertedSpreadsheetId); // Remove the converted file.