Google表格插件应在客户端驱动器中创建该文件的副本,而不是在原始驱动器中创建一个副本。
我的Code.gs文件中的以下脚本应该执行此操作,但似乎无法正常工作:
function createACopy(id){
var docName = DriveApp.getFileById(id).getName();
incrementDownloadCount(id);
return DriveApp.getFileById(id).makeCopy(docName).getUrl();
}
function incrementDownloadCount(id){
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(DATA_SHEET);
var data = sheet.getRange(2, 1, sheet.getLastRow()-1, 1).getValues();
var pos =data.map(function (obj) { return obj[0]; }).indexOf(id)
if(pos > -1){
var val = sheet.getRange("J"+(pos+2)).getValue()+1;
sheet.getRange("J"+(pos+2)).setValue(val);
}
}
这是HTML文件中的脚本:
function makeACopy(){
$("#templtDtl button").remove();
$("#templtDtl").prepend(
"<div id='copying'><img src='https://cdn.spreadsheet123.com/images/app/loading.gif' style='float:left;margin-right: 10px;'/>Making a copy...</div>"
);
google.script.run.withSuccessHandler(afterMakingCopy).createACopy(DETAIL[0]);
}
function afterMakingCopy(url){
$("#copying").remove();
$(document.createElement("div"))
.html(
'File has been successfully copied to your Google Drive! Open the file by clicking on the button below, or check your Google Drive for the file named:<br/> "'+DETAIL[4]+'"<br/><br/>'+
"<a href='"+url+"' target='_blank'><button class='action' style='margin-left: 0px'>Open file</button></a>"
)
.prependTo($("#templtDtl"));
}
这是HTML:
<div id="section3" style="display:none;">
<div style="margin-bottom:10px;">
<button onClick="backButtonPressed(3)">◄ Back</button>
</div>
<div class="scrollable-wrapper" style="padding:10px 4px;height:320px;">
<div id="templtTitle"></div>
<div id="templtImg"><div id="templtThumb"></div></div>
<div id="templtDtl" style="padding-left: 26px;"></div>
</div>
</div>
请让我知道您是否需要其他代码?
谢谢