Java 谷歌电子表格api-将所有表格导出为csv

Java 谷歌电子表格api-将所有表格导出为csv,java,google-drive-api,export,spreadsheet,Java,Google Drive Api,Export,Spreadsheet,我使用google drive api从drive.google.com导出文件: compile 'com.google.apis:google-api-services-drive:v2-rev201-1.21.0' 它的使用方式: Map<String, String> exportLinks = gFile.getExportLinks(); String exportLink = exportLinks.get("application/x-vnd.oasis.opend

我使用google drive api从drive.google.com导出文件:

compile 'com.google.apis:google-api-services-drive:v2-rev201-1.21.0'
它的使用方式:

Map<String, String> exportLinks = gFile.getExportLinks();
String exportLink =
exportLinks.get("application/x-vnd.oasis.opendocument.spreadsheet");

它只下载第一页。我可以指定工作表,如果我知道它的GID。如何获取所有页面的链接?

因此我决定使用谷歌工作表,这对我很有帮助:

compile (group: 'com.google.apis', name: 'google-api-services-sheets', version: 'v4-rev25-1.22.0')
compile (group: 'com.google.gdata', name: 'core', version: '1.47.1')

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                    httpTransport, jsonFactory, clientSecrets,
                    Arrays.asList(DriveScopes.DRIVE, SheetsScopes.SPREADSHEETS_READONLY))
                    .setDataStoreFactory(dataStoreFactory)
                    .setAccessType("offline")
                    .build();
Credential credential = flow.loadCredential(userId);
Sheets sheets = new Sheets.Builder(httpTransport, jsonFactory, credential)
                    .setApplicationName(APPLICATION_NAME)
                    .build();
List<Sheets> sheetsList = sheets.spreadsheets().get("mySpreadsheetId").execute().getSheets();
for (Sheet sh : sheetList) {
    sout(sh.getProperties().getSheetId());
}
compile(组:'com.google.api',名称:'googleapi服务表',版本:'v4-rev25-1.22.0')
编译(组:'com.google.gdata',名称:'core',版本:'1.47.1')
GoogleAuthorizationCodeFlow=新建GoogleAuthorizationCodeFlow.Builder(
httpTransport、jsonFactory、clientSecrets、,
数组.asList(DriveScopes.DRIVE,SheetsScopes.SPREADSHEETS\u只读))
.setDataStoreFactory(数据存储工厂)
.setAccessType(“脱机”)
.build();
凭证凭证=flow.loadCredential(userId);
Sheets Sheets=新建Sheets.Builder(httpTransport、jsonFactory、凭证)
.setApplicationName(应用程序名称)
.build();
List sheetsList=sheets.spreadsheets().get(“mySpreadsheetId”).execute().getSheets();
用于(图纸sh:图纸列表){
sout(sh.getProperties().getSheetId());
}

属性包含表单GID。

您需要在某个位置添加Covert=true。我没有java的强大功能,但我认为它应该是一些基于get方法的。假设您使用的是Google java客户端库。虽然不是一个解决方案,但您可以使用它在java中制作类似的东西。不过,对于我来说,这个问题与Sheets API更为相关,因此在这些工作表中循环可以帮助您获得可用于导出它的
gid
compile (group: 'com.google.apis', name: 'google-api-services-sheets', version: 'v4-rev25-1.22.0')
compile (group: 'com.google.gdata', name: 'core', version: '1.47.1')

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                    httpTransport, jsonFactory, clientSecrets,
                    Arrays.asList(DriveScopes.DRIVE, SheetsScopes.SPREADSHEETS_READONLY))
                    .setDataStoreFactory(dataStoreFactory)
                    .setAccessType("offline")
                    .build();
Credential credential = flow.loadCredential(userId);
Sheets sheets = new Sheets.Builder(httpTransport, jsonFactory, credential)
                    .setApplicationName(APPLICATION_NAME)
                    .build();
List<Sheets> sheetsList = sheets.spreadsheets().get("mySpreadsheetId").execute().getSheets();
for (Sheet sh : sheetList) {
    sout(sh.getProperties().getSheetId());
}