我使用 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");
它仅下载第一张表。如果我知道它的 gids,我可以指定工作表。如何获取所有页面的链接?
最佳答案
因此我决定使用 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。
关于java - Google 电子表格 api - 将所有工作表导出为 csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39702622/