我使用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");
我想将电子表格下载为csv而非ods,但如果我使用
String exportLink = exportLinks.get("text/csv");
它仅下载第一张纸。如果我知道它的表格,我可以指定表格。导报。如何获取所有页面的链接?
答案 0 :(得分:0)
所以我决定使用Google表格,这就是有帮助的:
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());
}
并且属性包含工作表gids。