gpt4 book ai didi

python - 使用应用程序脚本将 MS Word 文件(保存在云端硬盘中)转换为 Google 文档

转载 作者:行者123 更新时间:2023-12-01 23:10:43 31 4
gpt4 key购买 nike

我遇到了一些问题,找不到解决方案。有没有办法使用文件 url 或 id 将存储在 Google Drive 中的 MS Word 文件转换为 Google Docs?我目前有一个包含文件 URL 的电子表格。或者,也可以使用 python 脚本。任何帮助或想法将不胜感激!谢谢!

最佳答案

这可以很容易地完成。这是电子表格应用程序的脚本(不过不是 Python):

function main() {

var ids = [
'1MSZwvWwZFwiS0LfDYpUL9vvKXCvbeZkO',
'1BxECZrrIQpKFJYN5zHUeUDxeEiB8NjEb'
];

for (var id of ids) convert_docx_to_google_doc(id);

}

function convert_docx_to_google_doc(id) {
var docx = DriveApp.getFileById(id);
var folder = docx.getParents().next();
var blob = docx.getBlob();
var new_file = Drive.newFile(); // Enable the Advanced Drive API Service
var google_doc = Drive.Files.insert(new_file, blob, {convert:true});

DriveApp.getFileById(google_doc.id)
.setName(docx.getName()
.replace(/\.docx$/,''))
.moveTo(folder);
}

它获取 ID 数组并将 docx 文件作为 google 文档保存到相同的原始文件夹中。并从 Google 文档文件的名称中删除“.docx”扩展名。

但是你确定你需要它吗? Google 文档可以在 native 打开和保存 MS Word 文档。

关于python - 使用应用程序脚本将 MS Word 文件(保存在云端硬盘中)转换为 Google 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69977186/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com