如何通过Google Apps脚本从xlsx gmail附件中提取Google表格中的信息 [英] How can I extract Information in a Google Sheet from a xlsx gmail attachment via google apps script

查看:59
本文介绍了如何通过Google Apps脚本从xlsx gmail附件中提取Google表格中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Google Apps脚本从xlsx gmail附件中提取内容.然后将信息放入Google表格中.对于CSV文件,它工作正常,但我没有得到xlsx文件的内容.

I want to extract the content from an xlsx gmail attachment via google apps script. And then put the information into a Google Sheet. It's working fine for CSV files, but I don't get the content of a xlsx file.

推荐答案

与csv文件不同,xlsx文件数据不能直接插入电子表格中

您可以做什么:

Unlike csv files, xlsx file data cannot be directly inserted into a spreadsheet

What you can do instead:

  • 将附件以其原始mimeType保存在光盘上
  • 将其转换为Google表格文档,例如 Drive.Files.copy
  • 从光盘中删除Excel文件

示例:

function GmailToDrive() {  
  var threads = GmailApp.getInboxThreads();
  var message = threads[0].getMessages()[0];
  var attachment = message.getAttachments()[0];
  var blob = attachment.getAs(attachment.getContentType());
  blob.setName(attachment.getName())
  var excel = DriveApp.createFile(blob);
  Drive.Files.copy({mimeType: MimeType.GOOGLE_SHEETS}, excel.getId());
  excel.setTrashed(true)
}

请注意, Drive 是一项高级服务,需要

Note that Drive is an advances service that needs to be enabled beforehand.

这篇关于如何通过Google Apps脚本从xlsx gmail附件中提取Google表格中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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