我一直在努力解决这个问题。我对编写代码非常陌生,所以请耐心等待。
我想创建一个包含文件提交的表单,将响应解析为google电子表格,并将文件放入 my gdrive中的特定文件夹,而不是上传者的gdrive 。
我已经尝试过调试和询问,但似乎没有人能够弄清楚我的错误在哪里或如何将上传的文件放入我自己的文件夹中,所以我可以访问它们/看到它们。
以下是我的代码的链接:https://script.google.com/d/appID/edit?usp=sharing
我无法弄清楚出了什么问题。
答案 0 :(得分:0)
在这里,我可以为您提供一个非常简单的脚本来复制您希望的文件夹中的文件上载量 并将文本字段中的值写入工作表。
它写得很简单但可以给你第一步。
复制脚本文件中的代码并以google apps脚本运行。 在运行脚本之前,您必须在代码中进行更改 uloadfolder ID和工作表中的ID。 当您浏览googledrive中的这些元素时,您会找到自己的ID 并从浏览器的urlpath中读取ID。
function doGet() {
var app = UiApp.createApplication();
var text_lbl = app.createLabel('text: *');
var text = app.createTextBox().setName('text');
var replay_file_lbl = app.createLabel('Replay Upload:');
var replay_file = app.createFileUpload().setName('replay_file');
var submit_btn = app.createSubmitButton('Submit');
var battle_result_tbl = app.createFlexTable();
battle_result_tbl.setWidget(0, 0, text_lbl)
.setWidget(0, 1, text)
.setWidget(1, 0, replay_file_lbl)
.setWidget(1, 1, replay_file)
.setWidget(4, 1, submit_btn);
var form_panel = app.createFormPanel()
.setWidget(battle_result_tbl);
app.add(form_panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
// the uploads are writen in the root folder of google drive
var upload_root = DocsList.getFolder('');
// the dest folder for the uploads files
var upload_folder = DocsList.getFolderById('0B4Kg6cMbounaOHlMTXZUMUpTN3c');
var text = e.parameter.text;
var replay_file = e.parameter.replay_file;
var thx_lbl = app.createLabel('Thanks for your submission!');
app.add(thx_lbl);
// workaround, use try & catch cause if no file uploaded then error "File name cannot be empty"
try{
var replay_file_id = DocsList.createFile(replay_file); // create the uploaded file
replay_file = replay_file_id.getId(); // get the ID from uploaded file
replay_file_id.addToFolder(upload_folder); // copy uploaded file from root to dest folder
replay_file_id.removeFromFolder(upload_root); // delete uploaded file from root folder
}
catch(e){Logger.log('replay_file: '+e.message);}
// open ur sheet by id to write the value of text in
var ss = SpreadsheetApp.openById('1-c4MkF2TLigtMGuWNk45Df51oZBlgI0xK5bkVUWxRH8');
// this write the value from formelement text into cell A1
ss.getActiveSheet().getRange(1,1).setValue(text);
return app;
}