public com.google.gdata.data.docs.SpreadsheetEntry createSpreadsheet( String _title, DocumentListEntry _destinationFolderEntry, String _defaultWorksheetName, int _rows, int _columns) throws IOException, ServiceException { com.google.gdata.data.docs.SpreadsheetEntry newEntry = new com.google.gdata.data.docs.SpreadsheetEntry(); newEntry.setTitle(new PlainTextConstruct(_title)); String destFolder = ((MediaContent) _destinationFolderEntry.getContent()).getUri(); URL destinationURL = new URL(destFolder); com.google.gdata.data.docs.SpreadsheetEntry newSpreadsheetEntry = docsService.insert(destinationURL, newEntry); // convert from Docs API Spreadsheet to Spreadsheet API Spreadsheet WorksheetEntry worksheet = getSpreadsheetEntryFromDocumentListEntry(newSpreadsheetEntry).getDefaultWorksheet(); worksheet.setTitle(new PlainTextConstruct(_defaultWorksheetName)); worksheet.setRowCount(_rows); worksheet.setColCount(_columns); worksheet.update(); return newSpreadsheetEntry; }
public List<WorksheetEntry> copyDocument( DocumentListEntry documentListEntry, String newDocumentTitle, DocumentListEntry destinationFolderEntry) throws IOException, ServiceException { documentListEntry.setTitle(new PlainTextConstruct(newDocumentTitle)); URL url = new URL("https://docs.google.com/feeds/default/private/full/"); DocumentListEntry newDoc = docsService.insert(url, documentListEntry); String destFolder = ((MediaContent) destinationFolderEntry.getContent()).getUri(); URL newUrl = new URL(destFolder); // Convert DocumentListEntry to SpreadsheetEntry DocumentListEntry newDocumentListEntry = docsService.insert(newUrl, newDoc); String spreadsheetURL = "https://spreadsheets.google.com/feeds/spreadsheets/" + newDocumentListEntry.getDocId(); SpreadsheetEntry spreadsheetEntry = spreadsheetService.getEntry(new URL(spreadsheetURL), SpreadsheetEntry.class); return spreadsheetEntry.getWorksheets(); }
public String getFolderURI(String _folderName) throws IOException, ServiceException { URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/-/folder"); DocumentListFeed feed = docsService.getFeed(feedUri, DocumentListFeed.class); DocumentListEntry folderEntry = new DocumentListEntry(); for (DocumentListEntry entry : feed.getEntries()) { if (_folderName.equalsIgnoreCase(entry.getTitle().getPlainText())) { folderEntry = entry; break; } } String folderURIString = null; if (folderEntry.getContent() != null) { folderURIString = getDocumentFeedUri(folderEntry); } return folderURIString; }
public String getDocumentFeedUri(DocumentListEntry documentListEntry) { return ((MediaContent) documentListEntry.getContent()).getUri(); }