SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
Overview of Google
Spreadsheet 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
Authorization
SpreadsheetService service =
    new SpreadsheetService("service name"); - create spreadsheet
service

service.setUserCredentials("username", "password"); - send user
credentials
Getting spreadsheet feed
String 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 spreadsheet
feed with entries.
Worksheet
List<SpreadsheetEntry> spreadsheetEntries = feed.getEntries();
SpreadsheetEntry spreadsheet = spreadsheetEntries.get(0); - get
spreadsheet



List<WorksheetEntry> worksheets =
    spreadsheetEntry.getWorksheets();
WorksheetEntry worksheet = worksheets.get(0); - get worksheet;
Worksheet info
List<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: 93
Worksheet name: Worksheet 2, Cols: 20, Rows: 50
Worksheet name: New worksheet, Cols: 20, Rows: 100
Working with worksheet
WorksheetEntry 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 feeds
URL listFeedUrl = worksheetEntry.getListFeedUrl();
ListFeed feed =
    service.getFeed(listFeedUrl, ListFeed.class); - get list-based feed
with list of rows

for (ListEntry entry : feed.getEntries()) {
     System.out.println(entry.getTitle().getPlainText());
}
List based working
URL 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 row
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
ListEntry row = new ListEntry();
        row.getCustomElements().setValueLocal("Component", "New
component");
        row.getCustomElements().setValueLocal("width", "25");
        row.getCustomElements().setValueLocal("height", "19");

row = service.insert(listFeedUrl, row); - insert new row
Delete row
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

for (ListEntry row : listFeed.getEntries()) {
             if (...) {
                   row.delete();
             }
Cell-based feeds
URL cellFeedUrl = worksheetEntry.getCellFeedUrl();
CellFeed feed =
    service.getFeed(celFeedUrl, CellFeed.class); - get cell-based feed
with list of cells

for (CellEntry cell : feed.getEntries()) {
  System.out.println(entry.getTitle().getPlainText());
}
Cell based working
URL 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 working
URL 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 manipulation
if (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 Kostiv
Email: nazar.kostiv@gmail.com

Más contenido relacionado

La actualidad más candente

Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublic
Kaing Menglieng
 
Indexing and Query Optimisation
Indexing and Query OptimisationIndexing and Query Optimisation
Indexing and Query Optimisation
MongoDB
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 bt
Shinichi Ogawa
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
Glan Thomas
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
Jeff Smith
 
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
djkucera
 
Hitchhiker's guide to the win8
Hitchhiker's guide to the win8Hitchhiker's guide to the win8
Hitchhiker's guide to the win8
Jua Alice Kim
 

La actualidad más candente (19)

Lu solr32 34-20110912
Lu solr32 34-20110912Lu solr32 34-20110912
Lu solr32 34-20110912
 
Intro to Parse
Intro to ParseIntro to Parse
Intro to Parse
 
Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublic
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
 
Indexing and Query Optimisation
Indexing and Query OptimisationIndexing and Query Optimisation
Indexing and Query Optimisation
 
What's Parse
What's ParseWhat's Parse
What's Parse
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 bt
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
Swing database(mysql)
Swing database(mysql)Swing database(mysql)
Swing database(mysql)
 
Sql-Injection
Sql-InjectionSql-Injection
Sql-Injection
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
 
Python database access
Python database accessPython database access
Python database access
 
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
Oracle OpenWorld 2010 - Consolidating Microsoft SQL Server Databases into an ...
 
Hitchhiker's guide to the win8
Hitchhiker's guide to the win8Hitchhiker's guide to the win8
Hitchhiker's guide to the win8
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentation
 
知っておきたいSpring Batch Tips
知っておきたいSpring Batch Tips知っておきたいSpring Batch Tips
知っておきたいSpring Batch Tips
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 

Destacado

Validating a smartphone-based pedestrian navigation system prototype - An inf...
Validating a smartphone-based pedestrian navigation system prototype - An inf...Validating a smartphone-based pedestrian navigation system prototype - An inf...
Validating a smartphone-based pedestrian navigation system prototype - An inf...
Beniamino Murgante
 

Destacado (11)

ArcGIS Server Javascript API
ArcGIS Server Javascript APIArcGIS Server Javascript API
ArcGIS Server Javascript API
 
Jan. 2009 CBN
Jan. 2009 CBNJan. 2009 CBN
Jan. 2009 CBN
 
Social Path Routing Optimization 1.1
Social Path Routing Optimization 1.1Social Path Routing Optimization 1.1
Social Path Routing Optimization 1.1
 
Iirs - Overview of GIS
Iirs - Overview of GISIirs - Overview of GIS
Iirs - Overview of GIS
 
Validating a smartphone-based pedestrian navigation system prototype - An inf...
Validating a smartphone-based pedestrian navigation system prototype - An inf...Validating a smartphone-based pedestrian navigation system prototype - An inf...
Validating a smartphone-based pedestrian navigation system prototype - An inf...
 
An Open Source GIS System for Earthquake Early Warning and Post-Event Emergen...
An Open Source GIS System for Earthquake Early Warning and Post-Event Emergen...An Open Source GIS System for Earthquake Early Warning and Post-Event Emergen...
An Open Source GIS System for Earthquake Early Warning and Post-Event Emergen...
 
A Multiobjective Evolutionary Algorithm for Infrastructure Location in Vehicu...
A Multiobjective Evolutionary Algorithm for Infrastructure Location in Vehicu...A Multiobjective Evolutionary Algorithm for Infrastructure Location in Vehicu...
A Multiobjective Evolutionary Algorithm for Infrastructure Location in Vehicu...
 
Vehicle Tracking System (VTS)
Vehicle Tracking System (VTS)Vehicle Tracking System (VTS)
Vehicle Tracking System (VTS)
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
 
Internet-enabled GIS Using Free and Open Source Tools
Internet-enabled GIS Using Free and Open Source ToolsInternet-enabled GIS Using Free and Open Source Tools
Internet-enabled GIS Using Free and Open Source Tools
 
Cisco Network Icon Library
Cisco Network Icon LibraryCisco Network Icon Library
Cisco Network Icon Library
 

Similar a Overview of Google spreadsheet API for Java by Nazar Kostiv

Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
Rob Windsor
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
Kaz Watanabe
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
Truls Jørgensen
 

Similar a Overview of Google spreadsheet API for Java by Nazar Kostiv (20)

Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Requery overview
Requery overviewRequery overview
Requery overview
 
SERVIET
SERVIETSERVIET
SERVIET
 
Web api's
Web api'sWeb api's
Web api's
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Apache Click
Apache ClickApache Click
Apache Click
 
Servlets
ServletsServlets
Servlets
 
Hibernate Query Language
Hibernate Query LanguageHibernate Query Language
Hibernate Query Language
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven framework
 
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache FilterUnit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
SQLite with UWP
SQLite with UWPSQLite with UWP
SQLite with UWP
 
AJAX.ppt
AJAX.pptAJAX.ppt
AJAX.ppt
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
 
WP_Query, pre_get_posts, and eliminating query_posts()
WP_Query, pre_get_posts, and eliminating query_posts()WP_Query, pre_get_posts, and eliminating query_posts()
WP_Query, pre_get_posts, and eliminating query_posts()
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 

Más de IT Booze

Erlang - concurrency-oriented programming by Serhiy Yvtyshenko
Erlang - concurrency-oriented programming by Serhiy YvtyshenkoErlang - concurrency-oriented programming by Serhiy Yvtyshenko
Erlang - concurrency-oriented programming by Serhiy Yvtyshenko
IT Booze
 
Cloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
Cloud Providers: Amazon, Rackspace, Azure by Andriy TsokCloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
Cloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
IT Booze
 
Introduction to mercurial
Introduction to mercurialIntroduction to mercurial
Introduction to mercurial
IT Booze
 

Más de IT Booze (9)

Erlang - concurrency-oriented programming by Serhiy Yvtyshenko
Erlang - concurrency-oriented programming by Serhiy YvtyshenkoErlang - concurrency-oriented programming by Serhiy Yvtyshenko
Erlang - concurrency-oriented programming by Serhiy Yvtyshenko
 
Cloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
Cloud Providers: Amazon, Rackspace, Azure by Andriy TsokCloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
Cloud Providers: Amazon, Rackspace, Azure by Andriy Tsok
 
Let's teach your child programming with Greenfoot by Oleg Pashkevych
Let's teach your child programming with Greenfoot by Oleg Pashkevych Let's teach your child programming with Greenfoot by Oleg Pashkevych
Let's teach your child programming with Greenfoot by Oleg Pashkevych
 
Microsoft Dynamics CRM Overview by Anatoly Kvasnikov
Microsoft Dynamics CRM Overview by Anatoly KvasnikovMicrosoft Dynamics CRM Overview by Anatoly Kvasnikov
Microsoft Dynamics CRM Overview by Anatoly Kvasnikov
 
Windows Phone and mobile application development
Windows Phone and mobile application developmentWindows Phone and mobile application development
Windows Phone and mobile application development
 
Windows 8 and Metro design applications
Windows 8 and Metro design applicationsWindows 8 and Metro design applications
Windows 8 and Metro design applications
 
Savana
SavanaSavana
Savana
 
Introduction to mercurial
Introduction to mercurialIntroduction to mercurial
Introduction to mercurial
 
Git
GitGit
Git
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Overview of Google spreadsheet API for Java by Nazar Kostiv

  • 1. Overview of Google Spreadsheet API for Java Nazarii Kostiv
  • 2. Agenda ● Overview ● Authorization; ● Work with worksheet; ● List-based feeds; ● Cell-based feeds; ● Questions.
  • 3. What we need to start ● jdk 1.5 or greater; ● gdata-java-client jars; ● java mail API 1.4 or greater; ● javaBeans Activation Framework.
  • 4. Overview Creating spreadsheet Set spreadsheet Authorizing service URL and name Get row or cell Get spreadsheet Get worksheet feed
  • 5. Authorization SpreadsheetService service = new SpreadsheetService("service name"); - create spreadsheet service service.setUserCredentials("username", "password"); - send user credentials
  • 6. Getting spreadsheet feed String 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 spreadsheet feed with entries.
  • 7. Worksheet List<SpreadsheetEntry> spreadsheetEntries = feed.getEntries(); SpreadsheetEntry spreadsheet = spreadsheetEntries.get(0); - get spreadsheet List<WorksheetEntry> worksheets = spreadsheetEntry.getWorksheets(); WorksheetEntry worksheet = worksheets.get(0); - get worksheet;
  • 8. Worksheet info List<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: 93 Worksheet name: Worksheet 2, Cols: 20, Rows: 50 Worksheet name: New worksheet, Cols: 20, Rows: 100
  • 9. Working with worksheet WorksheetEntry 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;
  • 10. Working with worksheet title = worksheet.getTitle().getPlainText(); eTag = worksheet.getEtag(); if (title.equals("New worksheet") && eTag.equals(worksheetETag)) { try { worksheet.delete(); } catch .... - delete worksheet;
  • 11. List-based feeds URL listFeedUrl = worksheetEntry.getListFeedUrl(); ListFeed feed = service.getFeed(listFeedUrl, ListFeed.class); - get list-based feed with list of rows for (ListEntry entry : feed.getEntries()) { System.out.println(entry.getTitle().getPlainText()); }
  • 12. List based working URL 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...); }
  • 13. Add row ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class); ListEntry row = new ListEntry(); row.getCustomElements().setValueLocal("Component", "New component"); row.getCustomElements().setValueLocal("width", "25"); row.getCustomElements().setValueLocal("height", "19"); row = service.insert(listFeedUrl, row); - insert new row
  • 14. Delete row ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class); for (ListEntry row : listFeed.getEntries()) { if (...) { row.delete(); }
  • 15. Cell-based feeds URL cellFeedUrl = worksheetEntry.getCellFeedUrl(); CellFeed feed = service.getFeed(celFeedUrl, CellFeed.class); - get cell-based feed with list of cells for (CellEntry cell : feed.getEntries()) { System.out.println(entry.getTitle().getPlainText()); }
  • 16. Cell based working URL 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(); }
  • 17. Cell based working URL 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(...)
  • 18. Cell data manipulation if (cell.getTitle().getPlainText().equals("A1")){ cell.changeInputValueLocal("123"); - set value to cell cell.update(); } ..... cell.changeInputValueLocal("=SUM(A1:B1)"); - set cell formula
  • 20. Links ● https://developers.google.com/google-apps/spreadsheets/ ● https://developers.google.com/google-apps/documents-list/ ● https://developers.google.com/apps-script/guide