Reputation: 83
I'm looking for a script that I can run from Google Spreadsheet that will open a specific Excel file that is located on my computer.
Is it possible?
Thanks!
Upvotes: 1
Views: 7445
Reputation: 35
Not totally sure what you mean with running from Google Spreadsheet, if you want to execute a script by clicking a button in a specific Google Spreadsheet for example, that’s possible. See Google’s documentation: https://developers.google.com/apps-script/guides/menus.
As far as I know access local files is impossible, since GAS is a cloud based service so it won’t be able to connect to your personal computer. My solution would be to add the specific Excel file(s) to your Google Drive. When those file(s) are located in your Google Drive folder any Google App Script can access them.
EDIT
You can open a Excel file with Google Spreadsheet(only if the file is located in your drive). With a right-mouse-click you can choose open with > Google Spreadsheets, this creates an duplicate of your Excel file as Google Spreadsheet. If opened copy the URL, if written a simple script you can start with, which works fine for me:
function myFunction() {
var ss = SpreadsheetApp.openByUrl("url");
var sheets = ss.getSheets();
for(var i = 0; i < sheets.length; i++){
var range = sheets[i].getRange(1, 1, sheets[i].getLastRow(), sheets[i].getLastColumn());
var values = range.getValues();
for(var j = 0; j < sheets[i].getLastRow(); j++){
Logger.log(values[j][0].toString());
}
}
}
This code loops through all sheets in your Spreadsheet(outer for-loop) and get the range of each sheet, it convert this range to values and logs every value in the first column from every row(inner for-loop).
You can attach this script to a button in a Spreadsheet as explained in the Google documentation. Hope this will answer your question, good luck!
Upvotes: 1