问题
I am sharing this with hopes I workaround solution to this problem I am facing. I am using data validation to get values of a drop down menu. The values come from Range(“A1:A40”) in a sheet I called “calculation”
Since I have about 50 spreadsheets that use the same drop down values and same pattern, I simply decided to use an importRange function to fill the information in Sheet(“Calculation”).Range(“A1:A50”). The importRange was taking the list from a separate spreadsheet that I dedicated for that purpose.
The purpose of doing that was simply because this is a list of categories that I want to update and change, and I want the drop down menu to take into consideration these changes without have to manually change the values in the 50+ spreadsheets.
Now theoretically this would work with no problem , but the importRange function is so temperamental and it shows a #REF error that happens with random spreadsheets. I saw posts with complains from the same problem so I gave up hope the importRange would be a viable solution.
I would like your opinion in a good workaround to avoid such problem.
One solution I thought of is to have a script copying values from one sheet to all these sheets and have this script work every day but I did not know how to copy entire range from one spreadsheet to another, and frankly I am not sure if this solution is the best.
My experience working with cross-spreadsheet scripts is that a script getting data from couple of cells in 50+ sheets would probably take more than 5 minutes and eventually stop for exceeding the time allowed.
回答1:
Try to add a menu item that will cause a flush function to run.
I found that this function causes the importRange
to work.
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Refresh", functionName: "SheetFlush"});
ss.addMenu("Menu", menuEntries);
}
function SheetFlush(worksheet) {
worksheet = worksheet || SpreadsheetApp.getActive();
var sheets = worksheet.getSheets();
SpreadsheetApp.flush();
}
回答2:
How many of your 50 spreadsheets get this error ? Also, does the user have access to the original spreadsheet so that it can run the importRange() ?
A script may not be ideal for your case and you would be better off pursuing the importRange and getting it to work.
回答3:
We had problems with the reliability of the import function as well. In our case, we needed information to be automatically updated, but once per day was fine for our application.
Our solution was a script that copied and pasted the values once per evening. We also included a menu item where a user can force an update on demand.
We didn't have 50 sheets to maintain so writing the script was straight-forward. Depending on your situation, you could maintain the ids in one place and have the script loop through each spreadsheet, or you could have each spreadsheet run its own script.
Note - We were rolling up a public report from information on a private sheet. The report was being displayed on a website using embedded charts. The charts would often display an error, which was fixed by going back into the public sheet and letting the import function refresh.
回答4:
Could you specify how you try to access your spreadsheet ? I don't think there is such thing as a temperamental function... it is generally something that is not sufficiently defined that causes random errors.
回答5:
Force recalculation of importrange by reinstating the cell formula
Required:
Imported Data - Your target where everything will be copied to.
Imported Data Config - Has the following fields:
+---------------------------------------------+--------------------------------+ | A | B | +---------------------------------------------+--------------------------------+ | Import Data from Spreadsheet with the key: | key | | Import Data from Spreadsheet between range: | A:AA | | Imported Data select columns: | SELECT * | | Imported Data criteria: | WHERE Col15 contains 'Offered' | | Imported Data should by ordered by column: | ORDER BY Col1 | +---------------------------------------------+--------------------------------+
Script:
function onOpen() {
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
}
catch(err)
{
Browser.msgBox(err);
}
var configsheet = ss.getSheetByName("Imported Data Config");
var configkey = configsheet.getRange("B1").getValue();
var configrange = configsheet.getRange("B2").getValue();
var configselect = configsheet.getRange("B3").getValue();
var configwhere = configsheet.getRange("B4").getValue();
var configorderby = configsheet.getRange("B5").getValue();
var importedsheet = ss.getSheetByName("Imported Data");
importedsheet.getRange("A1").setValue('=QUERY(IMPORTRANGE("' + configkey + '","' + configrange + '"),"' + configselect + ' ' + configwhere + ' ' + configorderby + '")');
SpreadsheetApp.flush();
// Solution of sourcecode is: http://stackoverflow.com/questions/13631584/how-can-i-force-a-recalculation-of-cell-using-importrange-function-in-a-google-s
// OnOpen Trigger: https://developers.google.com/apps-script/understanding_triggers
// Active Spreadsheet solution: https://productforums.google.com/forum/#!topic/docs/XIY0WNX0uL8
Browser.msgBox("Sync Complete!");
}
This allows you to change your formula without editing the script, and make it easier to transfer the script across various sheets.
来源:https://stackoverflow.com/questions/11254977/script-workaround-to-solve-importrange-problems-for-drop-down-list