将文件夹中可用的所有xls文件转换为“Google Doc Spreadsheets”? [英] Convert all xls files available in a folder into "Google Doc Spreadsheets"?

查看:185
本文介绍了将文件夹中可用的所有xls文件转换为“Google Doc Spreadsheets”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传文件到Google云端硬盘时,基本的方法就是开启转换功能。



另一种方法是选择文件夹中的xls文件并手工一个一个地转换。



但是,如果某个文件夹中已经有许多xls文件上传,那么使用Google Apps脚本进行转换可能会比重新上传文件更快。



在我的情况下:



预先致谢)

解决方案

您应该使用高级云端硬盘服务

a>,文件更新



这个服务必须在使用前启用,但doc很清晰。




编辑以下是你的意见)



(抱歉,长时间延迟,我忘了这篇文章)



此代码会将驱动器中的每个XLS文件转换为Google电子表格格式(只要它们的名称具有.xls扩展名)。

您必须授权Drive扩展资源+ API控制台(按照ressour的说明进行操作/ b>

 函数importXLS(){
var files = DriveApp.searchFiles( 'title contains.xls'); //您也可以使用文件夹作为起点并获取该文件夹中的文件...在此仅使用DriveApp方法。
while(files.hasNext()){
var xFile = files.next();
var name = xFile.getName();
if(name.indexOf('。xls')> -1){//此检查并不是必需的,因为我使用搜索来获取文件,但是如果您获取的文件不同, 。
var ID = xFile.getId();
var xBlob = xFile.getBlob();
var newFile = {title:name +'_ converted',
key:ID
}
file = Drive.Files.insert(newFile,xBlob,{
convert:真
});



code $
$ p


The basic way to do that is turn conversion on when uploading files into Google Drive.

Another way is to select the xls file in the folder and convert it one by one by hand.

But if one has already many xls files uploaded in a folder, it may be faster to convert them with Google Apps Script than re-uploading again the files.

In my case:

  • once converted, I need to delete the xls files
  • all xls files are below the limits : "Uploaded spreadsheet files that are converted to the Google spreadsheets format can’t be larger than 100 MB, and need to be under 400,000 cells and 256 columns per sheet." https://support.google.com/drive/answer/37603?hl=en

Thanks in advance;)

解决方案

you should use the Advanced Drive Service, file update

This service must be enabled before use but the doc is pretty clear.


EDIT (following your comments)

(sorry for the long delay, I forgot this post)

This code will convert every XLS files in your drive to Google spreadsheet format (as long as their names have an .xls extension)

You must authorize the Drive extended ressource + API console (follow the instructions from the ressource/advanced services menu, see illustration below)

function importXLS(){
  var files = DriveApp.searchFiles('title contains ".xls"');// you can also use a folder as starting point and get the files in that folder... use only DriveApp method here.
  while(files.hasNext()){
    var xFile = files.next();
    var name = xFile.getName();
    if (name.indexOf('.xls')>-1){ // this check is not necessaey here because I get the files with a search but I left it in case you get the files differently...
      var ID = xFile.getId();
      var xBlob = xFile.getBlob();
      var newFile = { title : name+'_converted',
                     key : ID
                    }
      file = Drive.Files.insert(newFile, xBlob, {
        convert: true
      });
    }
  }
}

这篇关于将文件夹中可用的所有xls文件转换为“Google Doc Spreadsheets”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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