将Google工作表导出为.XLXS并重命名 [英] Exporting Google sheet as .XLXS and renaming

查看:51
本文介绍了将Google工作表导出为.XLXS并重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个脚本,可以将我的Google表格工作簿导出为.XLXS并将其通过电子邮件发送到一个地址.

I have found a script to export my google sheets workbook as .XLXS and email it to an address.

但是,当我尝试将.xlxs文件的名称设置为工作簿中的值时,它不起作用. 下面的代码:

However it is not working when i try and set the name of the .xlxs file to a value in the workbook. code below:

function getGoogleSpreadsheetAsExcel(){

  try {

    var ss = SpreadsheetApp.getActive();

    var name = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Project Details').getRange(2,A).getValue()

    var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=xlsx";

    var params = {
      method      : "get",
      headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
      muteHttpExceptions: true
    };

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

    blob.setName( name + ".xlsx");

    MailApp.sendEmail("(i know an email address goes here)", "Tablet Data Import", "The XLSX file is attached", {attachments: [blob]});

  } catch (f) {
    Logger.log(f.toString());
  }
} 

一些帮助将不胜感激

推荐答案

问题是由您使用方法getRange()

引起的

有两种方法可以正确执行此操作:

The problem is caused by the way you use the method getRange()

There are two ways to do it correctly:

getRange('A2')

getRange(2, 1)

这篇关于将Google工作表导出为.XLXS并重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆