2

使用通过单击 Google 电子表格上的按钮调用的自定义函数,我想将文本文件上传到特定文件夹,然后将内容放入电子表格的特定工作表中?

我知道如何创建一个按钮并在单击它时调用一个自定义函数。现在通过我的自定义功能,我想:

  1. 要求用户浏览到文本文件位置,然后选择文件并上传。
  2. 将其上传到特定位置,并将文件名更改为我想要的特定名称。
  3. 阅读文本文件的内容并将它们放入电子表格的工作表中。

谢谢!

4

1 回答 1

1

Creating a button, and assigning a macro (function) to that button, or you could just as easily create a new menu item in your Google spreadsheet. The new menu item would be achieved programmatically using a custom function, and executed using the onOpen trigger for your spreadsheet.

 function onOpen(){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var menuEntries = [ {name: "Text File Upload", functionName: "text_file_upload"},
                        {name: "Change Name", functionName: "change_name"},
                        {name: "TextFile to S.sheet", functionName: "t_file_ssheet"} ];
    ss.addMenu("Text Files", menuEntries);
 } //this onOpen function will add a new menu to your spreadsheet called "Text Files" with 3 submenu items you can use to work with your text files.

 function text_file_upload() {
    Browser.msgBox("You are about to upload new text file");
  //insert code here to get textfile location/Url and  Textfile Data, this can be stored in array 
 }

 function change_name() {
    var newName = Browser.inputBox("Enter the new name for the text file:");
  //insert code here to assign new file name to the text file
 }

 function t_file_ssheet(){
    //insert code here to copy data from your textfile to a sheet in your spreadsheet
 }

There is a very nice tutorial here Tutorial: Interacting With Your Docs List that covers most of the coding your looking for.

于 2012-11-22T08:08:03.027 回答