Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 导出为xlsx的Google脚本不工作 函数导出电子表格(){ var destination=SpreadsheetApp.create('Temp'); var dest1=destination.getActiveSheet().setName('출고입력 거래처정보(상단)'); var dest2=destination.insertSheet('출고입력 폼목정보(하단)'); var source1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 거래처정보(상단)').getDataRange(); var source2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 폼목정보(하단)').getDataRange(); var source1Data=source1.getValues(); var source2Data=source2.getValues(); var s1Rows=source1.getNumRows(); var s1Columns=source1.getNumColumns(); var s2Rows=source2.getNumRows(); var s2Columns=source2.getNumColumns(); //将数据复制到临时文件 对于(var i=0;对于Q 1:_Excel_Google Apps Script - Fatal编程技术网

Excel 导出为xlsx的Google脚本不工作 函数导出电子表格(){ var destination=SpreadsheetApp.create('Temp'); var dest1=destination.getActiveSheet().setName('출고입력 거래처정보(상단)'); var dest2=destination.insertSheet('출고입력 폼목정보(하단)'); var source1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 거래처정보(상단)').getDataRange(); var source2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 폼목정보(하단)').getDataRange(); var source1Data=source1.getValues(); var source2Data=source2.getValues(); var s1Rows=source1.getNumRows(); var s1Columns=source1.getNumColumns(); var s2Rows=source2.getNumRows(); var s2Columns=source2.getNumColumns(); //将数据复制到临时文件 对于(var i=0;对于Q 1:

Excel 导出为xlsx的Google脚本不工作 函数导出电子表格(){ var destination=SpreadsheetApp.create('Temp'); var dest1=destination.getActiveSheet().setName('출고입력 거래처정보(상단)'); var dest2=destination.insertSheet('출고입력 폼목정보(하단)'); var source1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 거래처정보(상단)').getDataRange(); var source2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 폼목정보(하단)').getDataRange(); var source1Data=source1.getValues(); var source2Data=source2.getValues(); var s1Rows=source1.getNumRows(); var s1Columns=source1.getNumColumns(); var s2Rows=source2.getNumRows(); var s2Columns=source2.getNumColumns(); //将数据复制到临时文件 对于(var i=0;对于Q 1:,excel,google-apps-script,Excel,Google Apps Script,在您的情况下,如何使用?例如,请将其放在下面 function exportSpreadsheet() { var destination = SpreadsheetApp.create('Temp'); var dest1 = destination.getActiveSheet().setName('출고입력 거래처정보(상단)'); var dest2 = destination.insertSheet('출고입력 폼목정보(하단)'); var source1 = S

在您的情况下,如何使用?例如,请将其放在下面

function exportSpreadsheet() {
  var destination = SpreadsheetApp.create('Temp');
  var dest1 = destination.getActiveSheet().setName('출고입력 거래처정보(상단)');
  var dest2 = destination.insertSheet('출고입력 폼목정보(하단)');  
  var source1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 거래처정보(상단)').getDataRange();
  var source2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('출고입력 폼목정보(하단)').getDataRange();
  var source1Data = source1.getValues();
  var source2Data = source2.getValues(); 
  var s1Rows = source1.getNumRows();
  var s1Columns = source1.getNumColumns();  
  var s2Rows = source2.getNumRows();
  var s2Columns = source2.getNumColumns();   

  // Copy Data to Temp file
  for(var i = 0; i<s1Rows; i++){ 
  for(var j = 0; j<s1Columns; j++) {
       dest1.getRange(i+1,j+1).setValue(source1Data[i][j]);
    }
  }  

  for(var i = 0; i<s2Rows; i++){ 
    for(var j = 0; j<s2Columns; j++) {
        dest2.getRange(i+1,j+1).setValue(source2Data[i][j]);
    }
  }

  // Export to xlsx
  var ssID = destination.getId();
  var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+"?format=xlsx";

  var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};

  var response = UrlFetchApp.fetch(url, params).getBlob();
  // Save to drive
  var folder = DriveApp.getFolderById('1vDFMM2EfRe1unR6hJOsKapfJrcwxRkxy');
  folder.createFile(response).setName('출고.xlsx');

  // Delete Temp file
  DriveApp.getFilesByName('Temp').next().setTrashed(true);

}
问题2的答案是: 更新脚本后,我注意到
DriveApp.removeFile(DriveApp.getFilesByName('Temp').next())
被修改为
DriveApp.getFilesByName('Temp').next().setTrashed(true)
。这样,
Temp
的文件就被扔进了垃圾桶。我想你已经知道了

如果这不是您想要的,我很抱歉。

请尝试此代码

// Export to xlsx
SpreadsheetApp.flush();
var ssID = destination.getId();

这是一个试图导出到excel的google应用程序脚本?@MichaelHong将鼠标悬停在标签上(或单击它),显示这是“Gnu汇编程序”的脚本…你能后退一点,解释一下你从什么开始,到什么结束吗?网上有无数不同的例子-你试过不止一个吗?可能是@ashleedawg的复制品哦,谢谢你的提醒。我编辑了我的评论。我花了两天的时间四处寻找不同的例子,它们都很有趣eem将是上述代码的变体(包括您发布的链接)。我正在尝试将我的两个选项卡保存为xlsx文件。其他ppl似乎没有上述代码的问题,但出于原因,我得到了一个空白文件,尽管URL为我提供了一个完美工作的xlsx文件。您所问的脚本是您的最新版本吗?
function exportSpreadsheet() {

  var ssID = "yourID";

  var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
                                                        "?format=xlsx&"+
                                                        "size=0&"+
                                                        "fzr=true&"+
                                                        "portrait=false&"+
                                                        "fitw=true&"+
                                                        "gridlines=false&"+
                                                        "printtitle=true&"+
                                                        "sheetnames=true&"+
                                                        "pagenum=CENTER&"+
                                                        "attachment=true";

  var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};

  var response = UrlFetchApp.fetch(url, params).getBlob();

  var folder = DriveApp.getFolderById("YourFolder");

  folder.createFile(response);

}