Create spreadsheet using Google Spreadsheets API in Google Drive
It's just simple after some research I found this answer. We cannot create a new spreadsheet in google drive with Google Spreadsheet API.
NOTE: we can create new worksheet in already exist spreadsheet of google drive through Google Spreadsheet API but cannot create a new spreadsheet with spreadsheet api.
For creating and uploading new Spreadsheet or any other kind of document which google drive supports we have to use Google Drive api.
This is what I am looking for. By this we can create a new spreadsheet in google drive using google drive api.
DocsService docsService = new DocsService("MySampleApplication-v3");
docsService.setUserCredentials(USERNAME, PASSWORD);
URL GOOGLE_DRIVE_FEED_URL = new URL("https://docs.google.com/feeds/default/private/full/");
DocumentListEntry documentListEntry = new com.google.gdata.data.docs.SpreadsheetEntry();
documentListEntry.setTitle(new PlainTextConstruct("Spreadsheet_name"));
documentListEntry = docsService.insert(GOOGLE_DRIVE_FEED_URL, documentListEntry);
For creating a new spreadsheet we have to create new SpreadsheetEntry()
object and for any other document we have to create new DocumentEntry()
object.
NOW If we have to upload any kind of document(xls,doc,image etc) in google drive we can do like this
//File upload in google drive
DocumentListEntry uploadFile = new DocumentListEntry();
uploadFile.setTitle(new PlainTextConstruct("FILE_NAME_DISPLAY_IN_DRIVE"));
uploadFile.setFile(new File("FILE_PATH"), "MIME_TYPE_OF_FILE");
uploadFile = docsService.insert(GOOGLE_DRIVE_FEED_URL, uploadFile);
You should use the Google Documents List API to create new speadsheets.
What can this API do?
The Google Documents List API allows developers to create, retrieve, update, and delete Google Docs (including but not limited to text documents, spreadsheets, presentations, and drawings), files, and collections. It also provides some advanced features like resource archives, Optical Character Recognition, translation, and revision history.