本文整理汇总了Java中com.google.gdata.data.spreadsheet.WorksheetFeed类的典型用法代码示例。如果您正苦于以下问题:Java WorksheetFeed类的具体用法?Java WorksheetFeed怎么用?Java WorksheetFeed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorksheetFeed类属于com.google.gdata.data.spreadsheet包,在下文中一共展示了WorksheetFeed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateWorksheet
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Updates the worksheet specified by the oldTitle parameter, with the given
* title and sizes. Note that worksheet titles are not unique, so this method
* just updates the first worksheet it finds. Hey, it's just sample code - no
* refunds!
*
* @param oldTitle a String specifying the worksheet to update.
* @param newTitle a String containing the new name for the worksheet.
* @param rowCount the number of rows the new worksheet should have.
* @param colCount the number of columns the new worksheet should have.
*
* @throws ServiceException when the request causes an error in the Google
* Spreadsheets service.
* @throws IOException when an error occurs in communication with the Google
* Spreadsheets service.
*/
private void updateWorksheet(String oldTitle, String newTitle, int rowCount,
int colCount) throws IOException, ServiceException {
WorksheetFeed worksheetFeed = service.getFeed(worksheetFeedUrl,
WorksheetFeed.class);
for (WorksheetEntry worksheet : worksheetFeed.getEntries()) {
String currTitle = worksheet.getTitle().getPlainText();
if (currTitle.equals(oldTitle)) {
worksheet.setTitle(new PlainTextConstruct(newTitle));
worksheet.setRowCount(rowCount);
worksheet.setColCount(colCount);
worksheet.update();
System.out.println("Worksheet updated.");
return;
}
}
// If it got this far, the worksheet wasn't found.
System.out.println("Worksheet not found: " + oldTitle);
}
示例2: deleteWorksheet
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Deletes the worksheet specified by the title parameter. Note that worksheet
* titles are not unique, so this method just updates the first worksheet it
* finds.
*
* @param title a String containing the name of the worksheet to delete.
*
* @throws ServiceException when the request causes an error in the Google
* Spreadsheets service.
* @throws IOException when an error occurs in communication with the Google
* Spreadsheets service.
*/
private void deleteWorksheet(String title) throws IOException,
ServiceException {
WorksheetFeed worksheetFeed = service.getFeed(worksheetFeedUrl,
WorksheetFeed.class);
for (WorksheetEntry worksheet : worksheetFeed.getEntries()) {
String currTitle = worksheet.getTitle().getPlainText();
if (currTitle.equals(title)) {
worksheet.delete();
System.out.println("Worksheet deleted.");
return;
}
}
// If it got this far, the worksheet wasn't found.
System.out.println("Worksheet not found: " + title);
}
示例3: getWorksheet
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Get the WorksheetEntry for the worksheet in the spreadsheet with the
* specified name.
*
* @param spreadsheet the name of the spreadsheet
* @param worksheet the name of the worksheet in the spreadsheet
* @return worksheet with the specified name in the spreadsheet with the
* specified name
* @throws Exception if error is encountered, such as no spreadsheets with the
* name, or no worksheet wiht the name in the spreadsheet
*/
public WorksheetEntry getWorksheet(String spreadsheet, String worksheet)
throws Exception {
SpreadsheetEntry spreadsheetEntry = getSpreadsheet(spreadsheet);
WorksheetQuery worksheetQuery
= new WorksheetQuery(spreadsheetEntry.getWorksheetFeedUrl());
worksheetQuery.setTitleQuery(worksheet);
WorksheetFeed worksheetFeed = service.query(worksheetQuery,
WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
if (worksheets.isEmpty()) {
throw new Exception("No worksheets with that name in spreadhsheet "
+ spreadsheetEntry.getTitle().getPlainText());
}
return worksheets.get(0);
}
示例4: getWsListHelper
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Retrieves a <code>List</code> of <code>WorksheetEntry</code> instances
* available from the list of Worksheets in the specified feed
*
* @param wsFeedUrl The feed of worksheets
* @throws EPAuthenticationException
* @return List of worksheets in the specified feed
*/
private List<WorksheetEntry> getWsListHelper(String wsFeedUrl)
throws EPAuthenticationException {
List<WorksheetEntry> returnList = null;
try {
SpreadsheetService ssService = getSsService();
WorksheetFeed wsFeed = ssService.getFeed(
new URL(wsFeedUrl),
WorksheetFeed.class);
returnList = wsFeed.getEntries();
} catch (com.google.gdata.util.AuthenticationException authEx) {
throw new EPAuthenticationException(
"WS list read access not available");
} catch (com.google.gdata.util.ServiceException svcex) {
System.err.println("ServiceException while retrieving " +
"available worksheets: " + svcex.getMessage());
returnList = null;
} catch (java.io.IOException ioex) {
System.err.println("IOException while retrieving " +
"available worksheets: " + ioex.getMessage());
returnList = null;
}
return returnList;
}
示例5: connectWorksheetFeed
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
public static WorksheetEntry connectWorksheetFeed(String user, String password, String documentId, String sheet) throws AuthenticationException
{
WorksheetFeed feed = connectWorksheetFeed(user, password, documentId);
List<WorksheetEntry> worksheets = feed.getEntries();
WorksheetEntry worksheet = null;
if (sheet == null || sheet.isEmpty())
{
worksheet = worksheets.get(0);
} else
{
for (WorksheetEntry we : worksheets)
{
if (we.getTitle().getPlainText().equalsIgnoreCase(sheet))
{
worksheet = we;
}
}
}
return worksheet;
}
示例6: retrieveData
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
public GSpreadResultSet retrieveData() throws Exception {
URL worksheetUrl = this.getConfig().generateWorksheetFeedURL();
WorksheetFeed feedw = this.getConfig().getFeed(worksheetUrl, WorksheetFeed.class);
WorksheetEntry worksheetEntry = feedw.getEntries().get(this.getWorksheetNumber() - 1);
CellFeed feedc = this.getConfig().getFeed(worksheetEntry.getCellFeedUrl(), CellFeed.class);
List<CellEntry> entries = feedc.getEntries();
GSpreadResultSet grs = new GSpreadResultSet();
/* store the data */
for (CellEntry entry : entries) {
grs.addCell(this.getPosStringFromId(entry.getId()),
entry.getTextContent().getContent().getPlainText());
}
return grs;
}
示例7: extractWorkSheetFeed
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
private WorksheetFeed extractWorkSheetFeed() throws SQLException {
if (this.getSpreadSheetFeed() == null) {
throw new SQLException("Spread Sheet Feed is null");
}
List<SpreadsheetEntry> entries = this.getSpreadSheetFeed().getEntries();
/* If no SpreadSheetEntry is available in the spreadsheet feed inferred using a
* SpreadSheetQuery, try getting it directly via a SpreadSheetFeed retrieved via the
* SpreadSheetService */
SpreadsheetEntry spreadsheetEntry =
(entries != null && entries.size() > 0) ? entries.get(0) :
this.extractSpreadSheetEntryFromUrl();
if (spreadsheetEntry == null) {
throw new SQLException("No SpreadSheetEntry is available, matching provided " +
"connection information");
}
WorksheetQuery worksheetQuery =
TDriverUtil.createWorkSheetQuery(spreadsheetEntry.getWorksheetFeedUrl());
return this.feedProcessor.getFeed(worksheetQuery, WorksheetFeed.class);
}
示例8: getWorksheetUrl
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Gets the worksheet url.
*
* @param spreadsheetService the spreadsheet service
* @param spreadsheetId the spreadsheet id
*/
private URL getWorksheetUrl(SpreadsheetService spreadsheetService, String spreadsheetId)
throws IOException, ServiceException {
if (isCancelled()) {
return null;
}
URL url = new URL(String.format(Locale.US, GET_WORKSHEETS_URI, spreadsheetId));
WorksheetFeed feed = spreadsheetService.getFeed(url, WorksheetFeed.class);
List<WorksheetEntry> worksheets = feed.getEntries();
if (worksheets.size() > 0) {
return worksheets.get(0).getListFeedUrl();
}
return null;
}
示例9: listAllWorksheets
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Lists all the worksheets in the loaded spreadsheet.
*
* @throws ServiceException when the request causes an error in the Google
* Spreadsheets service.
* @throws IOException when an error occurs in communication with the Google
* Spreadsheets service.
*/
private void listAllWorksheets() throws IOException, ServiceException {
WorksheetFeed worksheetFeed = service.getFeed(worksheetFeedUrl,
WorksheetFeed.class);
for (WorksheetEntry worksheet : worksheetFeed.getEntries()) {
String title = worksheet.getTitle().getPlainText();
int rowCount = worksheet.getRowCount();
int colCount = worksheet.getColCount();
System.out.println("\t" + title + " - rows:" + rowCount + " cols: "
+ colCount);
}
}
示例10: declareExtensions
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Declare the extensions of the feeds for the Google Spreadsheets service.
*/
private void declareExtensions() {
new CellFeed().declareExtensions(extProfile);
new ListFeed().declareExtensions(extProfile);
new RecordFeed().declareExtensions(extProfile);
new SpreadsheetFeed().declareExtensions(extProfile);
new TableFeed().declareExtensions(extProfile);
new WorksheetFeed().declareExtensions(extProfile);
}
示例11: init
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (GoogleSpreadsheetOutputMeta) smi;
data = (GoogleSpreadsheetOutputData) sdi;
if (super.init(smi, sdi)) {
try {
data.accessToken = GoogleSpreadsheet.getAccessToken(meta.getServiceEmail(), meta.getPrivateKeyStore());
if (data.accessToken == null) {
logError("Unable to get access token.");
setErrors(1L);
stopAll();
return false;
}
data.service = new SpreadsheetService("PentahoKettleTransformStep-v1");
data.service.setHeader("Authorization", "Bearer " + data.accessToken);
data.spreadsheetKey = meta.getSpreadsheetKey();
data.worksheetId = meta.getWorksheetId();
data.worksheetFeedURL = data.urlFactory.getWorksheetFeedUrl(data.spreadsheetKey, "private", "full");
data.worksheetFeed = data.service.getFeed(data.worksheetFeedURL, WorksheetFeed.class);
data.cellFeedURL = data.urlFactory.getCellFeedUrl(data.spreadsheetKey, data.worksheetId, "private",
"full");
data.cellFeed = data.service.getFeed(data.cellFeedURL, CellFeed.class);
data.cellBatchURL = new URL(data.cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM).getHref());
data.spreadsheet = new Spreadsheet();
} catch (Exception e) {
logError("Error: " + e.getMessage(), e);
setErrors(1L);
stopAll();
return false;
}
return true;
}
return false;
}
示例12: getCells
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Retrieve the cells of the worksheet designated by the current month from the spreadsheet
* specified in the parameter spreadsheet argument.
* For the specifics of my example, the empty cells of the sheet are retrieved as well.
* @param spreadsheet the spreadsheet to read the cells from (obtained by running getSpreadsheet)
* @param service SpreadsheetService obtained with token to manipulate Google spreadsheets (created in doInBackground)
* @return the cells from the spreadsheet
* @throws IOException
* @throws URISyntaxException
* @throws ServiceException
*/
private List<CellEntry> getCells( SpreadsheetEntry spreadsheet, SpreadsheetService service )
throws IOException, URISyntaxException, ServiceException {
// Get all the worksheets from the spreadsheet
WorksheetFeed worksheetFeed = service.getFeed(spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
// Fetch the desired worksheet (here corresponds to the current month)
WorksheetEntry worksheet = null;
Calendar cal = Calendar.getInstance();
String monthShort = new SimpleDateFormat("MMM").format(cal.getTime()).toLowerCase();
for (WorksheetEntry entry : worksheets) {
String worksheetTitle = entry.getTitle().getPlainText().toLowerCase();
if ( worksheetTitle.startsWith(monthShort) ) {
worksheet = entry;
break;
}
}
// Fetch the cell feed of the worksheet.
if ( worksheet == null )
return null;
else {
// For particular reasons linked to this example we also fetch the empty cells of the sheet
// remove + "?return-empty=true" if you do not need those.
URL cellFeedUrl = new URI(worksheet.getCellFeedUrl().toString() + "?return-empty=true").toURL();
CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
return cellFeed.getEntries();
}
}
示例13: getCurrentWorkSheetEntry
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
public static WorksheetEntry getCurrentWorkSheetEntry(TGSpreadConnection connection,
String sheetName) throws SQLException {
SpreadsheetEntry spreadsheetEntry = connection.getSpreadSheetFeed().getEntries().get(0);
WorksheetQuery worksheetQuery =
TDriverUtil.createWorkSheetQuery(spreadsheetEntry.getWorksheetFeedUrl());
WorksheetFeed worksheetFeed = connection.getFeedProcessor().getFeed(worksheetQuery,
WorksheetFeed.class);
for (WorksheetEntry entry : worksheetFeed.getEntries()) {
if (sheetName.equals(entry.getTitle().getPlainText())) {
return entry;
}
}
return null;
}
示例14: deleteSpreadsheetsRow
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Deletes Google Spreadsheets row.
*
* @param context the context
* @param accountName the account name
* @param trackName the track name
* @return true if deletion is success.
*/
public static boolean deleteSpreadsheetsRow(
Context context, String accountName, String trackName) {
try {
// Get spreadsheet Id
List<File> files = searchSpreadsheets(context, accountName);
if (files == null || files.size() == 0) {
return false;
}
String spreadsheetId = files.get(0).getId();
// Get spreadsheet service
SpreadsheetService spreadsheetService = new SpreadsheetService(
"MyTracks-" + SystemUtils.getMyTracksVersion(context));
Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod());
credential.setAccessToken(
SendToGoogleUtils.getToken(context, accountName, SendToGoogleUtils.SPREADSHEETS_SCOPE));
spreadsheetService.setOAuth2Credentials(credential);
// Get work sheet
WorksheetFeed worksheetFeed = spreadsheetService.getFeed(new URL(
String.format(Locale.US, SendSpreadsheetsAsyncTask.GET_WORKSHEETS_URI, spreadsheetId)),
WorksheetFeed.class);
Iterator<WorksheetEntry> worksheetEntryIterator = worksheetFeed.getEntries().iterator();
while (worksheetEntryIterator.hasNext()) {
WorksheetEntry worksheetEntry = (WorksheetEntry) worksheetEntryIterator.next();
String worksheetTitle = worksheetEntry.getTitle().getPlainText();
if (worksheetTitle.equals(SPREADSHEETS_WORKSHEET_NAME)) {
URL url = worksheetEntry.getListFeedUrl();
Iterator<ListEntry> listEntryIterator = spreadsheetService.getFeed(url, ListFeed.class)
.getEntries().iterator();
while (listEntryIterator.hasNext()) {
ListEntry listEntry = (ListEntry) listEntryIterator.next();
String name = listEntry.getCustomElements().getValue(SPREADSHEETS_TRANCK_NAME_COLUMN);
if (name.equals(trackName)) {
listEntry.delete();
return true;
}
}
}
}
} catch (Exception e) {
Log.e(TAG, "Unable to delete spreadsheets row.", e);
}
return false;
}
示例15: createRecordInSpreadsheet
import com.google.gdata.data.spreadsheet.WorksheetFeed; //导入依赖的package包/类
/**
* Recording a copy of the information somebody used the Streetlight Seattle Reporter app to send to Seattle City Light.
* Google Docs approach inspired by: https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row
* Spreadsheet viewable at: https://docs.google.com/spreadsheet/ccc?key=0AvDYc0olGEwRdE56dTlKMVVZdGYxQkc5eGJEQzJLNkE&usp=drive_web#gid=0
*
* @param parameters names and values from the activity; names are column headers in the spreadsheet.
* @throws AuthenticationException
* @throws MalformedURLException
* @throws IOException
* @throws ServiceException
*/
private void createRecordInSpreadsheet(List<NameValuePair> parameters)
throws AuthenticationException, MalformedURLException, IOException, ServiceException
{
String timeStamp = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(Calendar.getInstance().getTime());
parameters.add(new BasicNameValuePair("Date", timeStamp));
//parameters.remove(object)
SpreadsheetService service = new SpreadsheetService("CodeForSeattle-StreetlightSeattleReporter-v1");
// Authorize the service object for a specific user (see other sections)
final String user = "[email protected]";
final String pword = StringUtil.repeat(getString(R.string.app_initials), 3) + "333";
service.setUserCredentials(user, pword);
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
if (spreadsheets.size() == 0) {
// There were no spreadsheets, act accordingly.
return;
}
SpreadsheetEntry spreadsheet = null;
for (SpreadsheetEntry s : spreadsheets)
{
String title = s.getTitle().getPlainText();
if (title.equals("StreetlightSeattleReporter"))
{
spreadsheet = s;
break;
}
if (spreadsheet == null) // Backup plan.
spreadsheet = spreadsheets.get(0);
}
// Get the first worksheet of the first spreadsheet.
WorksheetFeed worksheetFeed = service.getFeed(spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);
// Fetch the list feed of the worksheet.
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
// Create a local representation of the new row.
ListEntry row = new ListEntry();
// Set the values of the new row.
for (NameValuePair param : parameters) {
String key = param.getName();
// Refrain from storing these 3 fields in the Google Docs spreadsheet.
if (key.equals("LastName") || key.equals("Phone") || key.equals("Email"))
continue;
row.getCustomElements().setValueLocal(key, param.getValue());
}
// Send the new row to the API for insertion.
row = service.insert(listFeedUrl, row);
}