问题
I've build Spreadsheet with a lot of google script code. It started as a personal spreadsheet and script, but more people want to use my spreadsheet. I doesn't want to share the google script code to the other people, but sharing the spreadsheet is ok.
So I've created a separate Google Script project and published a version and included that version in the spreadsheet. This works great for me as owner of the spreadsheet and script.
Now I've shared the spreadsheet. That people make a custom copy of the sheet and tried to use it. When running the function in the sheet (referencing to the library): 1) getting the question to give the script the right authorisation, on base of the functions in the custom library. 2) After that Google gives a error: You do not have access to library xxx, used by your script, or it has been deleted.
So the enduser have edit right to the sheet, but the custom library is only for me. I can make this working by publishing the custom library as available for anyone with the link with EDIT rights.
Is there a way to fix this? The code in script is very important to ensure that nobody may see what's happening there.
hmmm giving al users read right, means they can access my sourcecode. Will there be no option to prevent that? Loading sourcecode form external source for example?
Another issue with giving the user read rights. I've created two custom libraries, one with the public functions and one with the private functions. The public functions library holds all the public getter and setters.
So in the sheet code there's a function:
function GetInformation()
{
LKfunctions.GetInformation();
}
LKFunctions is the public library. In the public library i've included the private library as LKfunctionsPrivate. So the function in the public library is:
function GetInformation()
{
var parsedData = LKfunctionsPrivate.getLK_JSON();
if (parsedData != "")
{
LKfunctionsPrivate.FillSettingsSheet(parsedData);
LKfunctionsPrivate.FillCastleSheet(parsedData);
}
}
When I execute the function the sheet I get the error: "ReferenceError: 'LKfunctions' is not defined. (line 6, file 'publicFunctions.gs'
That's very strange because publicFunctions that function has the content: LKfunctionsPrivate.getLK_JSON();
So how can the script gives me a error on LKfunctions, when using LKfunctionsPrivate. When I debug I indeed that the line is edited to LKfunctions.getLK_JSON();
Very strange.
Looks this works indead. I've merged my private and public function library to one.
One problem. I'm using a external library called Moment in my function library. https://script.google.com/macros/library/versions/d/MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48
When including my library, I must enable development mode on the function library to work correctly. When anyone else using my script or I disable development mode, we got the error message: ReferenceError: "Moment" is not defined. (line 5, file "constants", project "Lords and Knights functions")
回答1:
Here is an example for you to test and to check that users don't have to have edit rights on the script source. Use this example in a spreadsheet :
//Library Project key : M_ZIuMRltotjhyMdhBDVG76tIT_UhbT9n
// choose stable version.
function test(){
testLib.searchUI();
}
it will create a small UI in your spreadsheet... the library script is viewable to anyone with the link but no one has the link
来源:https://stackoverflow.com/questions/22183246/how-to-share-spreadsheet-with-reference-to-a-custom-private-library