2016-09-26 96 views
0

我使用谷歌雲端硬盤API從drive.google.com導出文件:谷歌電子表格API - 導出所有的表爲CSV

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"); 

它只下載第一張。如果我知道它的'gid',我可以指定表格。我如何獲得所有頁面的鏈接?

+0

你需要添加Covert = true某個地方。我沒有java的力量,但它應該是一些在我想的get方法上。假設你正在使用Google的Java客戶端庫。 – DaImTo

+0

雖然不是解決方案,但您可以使用[this appscript](https://gist.github.com/mderazon/9655893)在Java中製作類似的東西。雖然這個問題與Sheets API更相關,所以通過表單循環可以幫助您獲得可用於導出它的'gid'。 – adjuremods

回答

0

所以我決定使用谷歌表,這就是幫助:

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()); 
} 

而且屬性包含表導報。