function onOpen() {
var menu = SpreadsheetApp.getUi().createMenu("File Picker");
menu.addItem("Get XLSX","getXLSX");
menu.addToUi();
}
function getXLSX() {
try {
var threads = GmailApp.getInboxThreads();
// you will need to change the subject "XLSX Test" to your subject
var thread = threads.find( email => email.getFirstMessageSubject() == "XLSX Test" );
var messages = thread.getMessages();
// assuming the attachement is attached to message 1
var attachments = messages[0].getAttachments();
var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id;
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // There is the data in 1st tab.
var data = sheet.getDataRange().getValues();
Drive.Files.remove(convertedSpreadsheetId); // Remove the converted file.
var spread = SpreadsheetApp.getActiveSpreadsheet();
// you will need to change Sheet2 to your sheet name
var sheet = spread.getSheetByName("Sheet2");
// I can't really test this part because I don't use Excel and have no test file with more than 1 column
function extractColumns(row) {
row = row.slice(3); // remove columns D and up
row = row.slice(1,1); // remove column B
return row;
}
data.forEach( extractColumns );
console.log(data);
sheet.getRange(1,1,data.length,data[0].length).setValues(data);
}
catch(err) {
console.log(err);
}
}