将zip数据导入Google电子表格 [英] Import zip data into google spreadsheet

查看:120
本文介绍了将zip数据导入Google电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



zip包含一个CSV数据文件。

我试图从网址获取zip文件并自动将其导入Google Spreadsheet。

我知道我可以将CSV数据导入到Google电子表格中,但是我希望能够在上传之前切断下载zip文件并提取文件的步骤转换为Google Spreadsheet。



因此,我的查询是否可以将URL中的压缩CSV文件直接导入Google Spreadsheet中?如果不是这样,Google Apps脚本将如何实现?

解决方案

感谢道格拉斯的投入。在你的代码的帮助下,我可以设法简化它,并直接从链接读取zip到电子表格。这里是我的代码:

function testzip(){

  var url =url goes here
var zipblob = UrlFetchApp.fetch(url).getBlob();
var unzipblob = Utilities.unzip(zipblob);
var unzipstr = unzipblob [0] .getDataAsString();
var csv = Utilities.parseCsv(unzipstr);

var ss = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName('Sheet1');
ss.getRange(1,1,csv.length,csv [0] .length).setValues(csv);

}


I am trying to fetch a zip from a URL and import it automatically into a Google Spreadsheet.

The zip contains one file of CSV data.

I know I can import the CSV data into a Google Spreadsheet but I would like to be able to cut out the step of me having to download the zip and extract the file first before uploading it into a Google Spreadsheet.

So my queries, is it possible to import a zipped CSV file from a URL directly into a Google Spreadsheet? If not, how would this be done with a Google Apps Script?

解决方案

Thanks Douglas for your inputs. With the help of your code i could manage to simplify it and read the zip from the link directly to spreadsheets. Here is my code:

function testzip(){

var url = "url goes here" 
var zipblob = UrlFetchApp.fetch(url).getBlob(); 
var unzipblob = Utilities.unzip(zipblob); 
var unzipstr=unzipblob[0].getDataAsString();
var csv = Utilities.parseCsv(unzipstr);

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
ss.getRange(1, 1, csv.length, csv[0].length).setValues(csv);

}

这篇关于将zip数据导入Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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