• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Overview of Google spreadsheet API for Java by Nazar Kostiv
 

Overview of Google spreadsheet API for Java by Nazar Kostiv

on

  • 5,750 views

 

Statistics

Views

Total Views
5,750
Views on SlideShare
5,624
Embed Views
126

Actions

Likes
1
Downloads
49
Comments
0

1 Embed 126

http://www.itbooze.com.ua 126

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Overview of Google spreadsheet API for Java by Nazar Kostiv Overview of Google spreadsheet API for Java by Nazar Kostiv Presentation Transcript

    • Overview of GoogleSpreadsheet API for Java Nazarii Kostiv
    • Agenda● Overview● Authorization;● Work with worksheet;● List-based feeds;● Cell-based feeds;● Questions.
    • What we need to start● jdk 1.5 or greater;● gdata-java-client jars;● java mail API 1.4 or greater;● javaBeans Activation Framework.
    • Overview Creating spreadsheet Set spreadsheet Authorizing service URL and name Get row or cell Get spreadsheet Get worksheet feed
    • AuthorizationSpreadsheetService service = new SpreadsheetService("service name"); - create spreadsheetserviceservice.setUserCredentials("username", "password"); - send usercredentials
    • Getting spreadsheet feedString SPREADSHEET_URL = "https://spreadsheets.google.com/feeds/spreadsheets/private/full";URL sheetListUrl = new URL(SPREADSHEET_URL);- set spreadsheer URL;SpreadsheetQuery query = new SpreadsheetQuery(sheetListUrl);query.setTitleQuery("Spreadsheet name"); - set spreadsheet name;SpreadsheetFeed feed = service.getFeed(query, SpreadsheetFeed.class); - get spreadsheetfeed with entries.
    • WorksheetList<SpreadsheetEntry> spreadsheetEntries = feed.getEntries();SpreadsheetEntry spreadsheet = spreadsheetEntries.get(0); - getspreadsheetList<WorksheetEntry> worksheets = spreadsheetEntry.getWorksheets();WorksheetEntry worksheet = worksheets.get(0); - get worksheet;
    • Worksheet infoList<WorksheetEntry> worksheets = SpreadsheetDemoUtil.getWorksheets(); for (WorksheetEntry worksheet : worksheets) { System.out.println("Worksheet name: " + worksheet.getTitle().getPlainText() + ", Cols: " + worksheet.getColCount() + ", Rows: " + worksheet.getRowCount()); }Worksheet name: Worksheet 1, Cols: 20, Rows: 93Worksheet name: Worksheet 2, Cols: 20, Rows: 50Worksheet name: New worksheet, Cols: 20, Rows: 100
    • Working with worksheetWorksheetEntry worksheet = new WorksheetEntry();URL worksheetFeedUrl = spreadsheetEntry.getWorksheetFeedUrl();insertedWorksheet = service.insert( worksheetFeedUrl, worksheet); - add new worksheet;worksheetETag = insertedWorksheet.getEtag();worksheet.setColCount(30);worksheet.update(); - update worksheet;
    • Working with worksheet title = worksheet.getTitle().getPlainText(); eTag = worksheet.getEtag(); if (title.equals("New worksheet") && eTag.equals(worksheetETag)) { try { worksheet.delete(); } catch .... - delete worksheet;
    • List-based feedsURL listFeedUrl = worksheetEntry.getListFeedUrl();ListFeed feed = service.getFeed(listFeedUrl, ListFeed.class); - get list-based feedwith list of rowsfor (ListEntry entry : feed.getEntries()) { System.out.println(entry.getTitle().getPlainText());}
    • List based workingURL listFeedUrl = new URI(null, null, worksheet.getListFeedUrl().toString(), "sq=width>25 and height<175", null).toURL();listFeed = service.getFeed(listFeedUrl, ListFeed.class);for (ListEntry row : listFeed.getEntries()) { System.out.println(row.get...);}
    • Add rowListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);ListEntry row = new ListEntry(); row.getCustomElements().setValueLocal("Component", "Newcomponent"); row.getCustomElements().setValueLocal("width", "25"); row.getCustomElements().setValueLocal("height", "19");row = service.insert(listFeedUrl, row); - insert new row
    • Delete rowListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);for (ListEntry row : listFeed.getEntries()) { if (...) { row.delete(); }
    • Cell-based feedsURL cellFeedUrl = worksheetEntry.getCellFeedUrl();CellFeed feed = service.getFeed(celFeedUrl, CellFeed.class); - get cell-based feedwith list of cellsfor (CellEntry cell : feed.getEntries()) { System.out.println(entry.getTitle().getPlainText());}
    • Cell based workingURL cellFeedUrl = new URI(null, null, worksheet.getCellFeedUrl().toString(), "?min-row=2&min-col=4&max-col=4",null).toURL();CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);for (CellEntry cell : cellFeed.getEntries()) { System.out.println(cell.getTitle().getPlainText();}
    • Cell based workingURL cellFeedUrl = mainWorksheet.getCellFeedUrl(); CellQuery cellQuery = new CellQuery(cellFeedUrl); cellQuery.setMinimumCol(2); cellQuery.setMaximumCol(4); cellQuery.setMinimumRow(4); cellQuery.setMaximumRow(4); CellFeed cellFeed = null; try { cellFeed = service.query(cellQuery, CellFeed.class); } catch(...)
    • Cell data manipulationif (cell.getTitle().getPlainText().equals("A1")){ cell.changeInputValueLocal("123"); - set value to cell cell.update();}..... cell.changeInputValueLocal("=SUM(A1:B1)"); - set cell formula
    • Questions?
    • Links● https://developers.google.com/google-apps/spreadsheets/● https://developers.google.com/google-apps/documents-list/● https://developers.google.com/apps-script/guide
    • Nazarii KostivEmail: nazar.kostiv@gmail.com