首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Drive API更新Google Doc -格式丢失

使用Drive API更新Google Doc -格式丢失
EN

Stack Overflow用户
提问于 2018-06-26 01:24:18
回答 1查看 42关注 0票数 0

我正在尝试开发一个Java程序,从谷歌驱动器检索文件,并尝试重新上传它“是”。但是,在此过程中,它会丢失格式。

下面是我检索文件的方法:

代码语言:javascript
复制
private static java.io.File downloadFile(File uploadedFile)
        throws IOException {
    java.io.File downloadedFile = new java.io.File(parentDir, uploadedFile.getTitle() + UUID.randomUUID().toString());

    try (OutputStream out = new FileOutputStream(downloadedFile)) {
        drive.files().export(uploadedFile.getId(), "text/html").executeMediaAndDownloadTo(out);
    }

    return downloadedFile;
}

下面是我更新文件的方法:

代码语言:javascript
复制
private static File updateFile(Drive service, String fileId, File file, java.io.File newContent) throws IOException {
        FileContent mediaContent = new FileContent("text/html", newContent);
        return service.files().update(fileId, file, mediaContent).execute();
}

下面是我是如何组合这些方法的(相当虚拟的):

代码语言:javascript
复制
java.io.File downloaded = downloadFile(files.get(0));
updateFile(drive, files.get(0).getId(), files.get(0), downloaded);

这是前后的文件:

这个过程是很好的,当我导出和重新导入的谷歌文件作为RTF或PDF,但我真的需要一个可编辑的格式。我错过了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2018-06-26 13:14:20

这是预期的结果。PDF是确保格式得以保留的一种方式。对于Google Docs来说,就没那么多了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51028857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档