用Java在Google文档中替换文本

4
我有一个在Google Drive上的文档(原生Google文档),需要从我的Java应用程序中更新。我目前所做的是将该文档下载为HTML。
String downloadUrl = doc.getExportLinks().get("text/html");
HttpResponse resp = service.getRequestFactory()
                           .buildGetRequest(new GenericUrl(downloadUrl))
                           .execute();
String contents = IOUtils.toString(resp.getContent());

然后我更新了String对象中的内容,并将更新发送到Drive:

ByteArrayContent mediaContent = ByteArrayContent.fromString("text/html", contents);
service.files().update(doc.getId(), doc, mediaContent).execute();

这对于非常简单的文档可以正常工作。但如果文档中包含图片,则图片将消失。`img`标签的`src`属性为空。
谷歌是否提供其他更新谷歌文档内容的方法?是否有类似于谷歌表格API的API?

试着看一下http://stackoverflow.com/questions/12546070/does-google-app-engine-support-apache-poi - Scary Wombat
@IwishIcouldthinkofagood,感谢您提供的链接,但我不是在尝试更新Microsoft文档,而是本地的Google Drive文档。 - Martin Dimitrov
抱歉,我正在专注于Apache POI部分。 - Scary Wombat
1个回答

1

很遗憾,Google没有提供细粒度的REST API来操作Google文档的内容。Google Apps Script 提供了这样的服务,但将其整合到Java应用程序中可能会很困难。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接