Download a Google Docs Spreadsheet as HTML

后端 未结 2 1879
太阳男子
太阳男子 2020-12-21 05:34

Im using the Google Drive api with php to do all sorts of wonderful things but getting stuck with downloading a Spreadsheet in HTML format. I can use the getExportLinks() me

相关标签:
2条回答
  • 2020-12-21 06:21

    Just change the exportformat in the exportLink to html.

    0 讨论(0)
  • 2020-12-21 06:23

    @Andre J's answer works, the code:

                                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);
    
    0 讨论(0)
提交回复
热议问题