【问题标题】:Download a Google Docs Spreadsheet as HTML以 HTML 格式下载 Google Docs 电子表格
【发布时间】:2012-10-26 07:50:58
【问题描述】:

我正在使用带有 php 的 Google Drive api 来做各种美妙的事情,但在下载 HTML 格式的电子表格时遇到了麻烦。我可以使用 getExportLinks() 方法以各种格式下载它,但我想要的只是表格中的文本,而不是 docx 或 ods 中的格式化文件。

这可以通过使用 /feeds/download/spreadsheets/Export?exportFormat=html&format=html&key=ID url 的 google docs api 实现。但目前在我使用时被重定向。

是否可以使用驱动 api 将电子表格下载为 html?

【问题讨论】:

  • 你找到解决办法了吗?电子表格可以导出为 xlsx、ods 和 pdf,但不能导出 HTML!

标签: google-drive-api google-docs-api


【解决方案1】:

@Andre J 的回答有效,代码:

                            Drive driveService = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).build();
                            File file = driveService.files().get(____documentKey____).execute();
                            String downloadUrl = file.getExportLinks().get("application/pdf");
                            downloadUrl = downloadUrl.replaceFirst("exportFormat=pdf", "exportFormat=html");
                            HttpResponse resp =
                                    driveService.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
                                        .execute();
                            System.out.println("downloadUrl:"+downloadUrl);
                            InputStream fileContent = resp.getContent();
                            String htmlContent = new Scanner(fileContent).useDelimiter("\\A").next();
                            System.out.println("htmlContent:"+htmlContent);

【讨论】:

    【解决方案2】:

    只需将exportLink中的exportformat改为html即可。

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多