问题描述
我正在尝试从URL提取gzip并将其自动导入到Google表格中. gzip包含一个CSV数据文件.
I am trying to fetch a gzip from a URL and import it automatically into a Google Sheets. The gzip contains one file of CSV data.
我知道我可以将CSV数据导入到Google表格中,但是我希望能够省去下载gzip并先提取文件的步骤,然后再将其上传到Google表格中.
I know I can import the CSV data into a Google Sheets but I would like to be able to cut out the step of me having to download the gzip and extract the file first before uploading it into a Google Sheets.
所以我的查询:
是否可以将URL中的压缩CSV文件直接导入到Google表格中?
Is it possible to import a gzipped CSV file from a URL directly into a Google Sheets?
如果没有,那么如何使用Google Apps脚本来完成此操作?
If not, how would this be done with a Google Apps Script?
推荐答案
GAS中有一个未记录的实用程序,称为unzip,我知道它可以解压缩普通的.zip文件,但不知道是否支持GNU zip ...也许值得尝试一下吗?这是我为google文档/驱动器中的一个zip写的快速测试
There is an undocumented utility in GAS called unzip, I know it can unzip ordinary .zip files but have no idea if GNU zip are supported... maybe it's worth give it a try ?here is a quick test I wrote for a zip that was in my google documents/drive
function testzip(){
var files=DocsList.getRootFolder().find('Sans titre.txt.zip');
var zipblob=files[0].getBlob();
var unzipblob = Utilities.unzip(zipblob);
var unzipstr=unzipblob[0].getDataAsString();// it is a text file
DocsList.createFile('Sans titre.txt',unzipstr);// I kept the original name to make it simple
}
如果对您没有帮助,请不要怪我...这只是一个建议;-)
Don't blame me if it doesn't work for you... it's just a proposal ;-)
这篇关于将压缩的数据导入Google表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!