Reputation: 1486
I am working on Google Spreadsheets API. I stuck at a point where I want to create a new spreadsheet. Google spreadsheets API says only about retrieving already created spreadsheets and their management(including cell content updating etc..). They also listed that it is possible to create a new spreadsheet by uploading a spreadsheet file via the Google Documents List API. I have gone through Google Documents List API but I didn't find any documentation for Java. They only provided .Net documentation. So my question is "Is it possible to create a new spreadsheet in Java/Android programmatically??".
If possible, could anyone guide me to a good link or blog or a piece of article. It will be a great help to me.
Any help will be appreciated !!
UPDATE : I am not talking about creating a spreadsheet locally, rather I am talking about creating a spreadsheet through API call. Here is my scenario : I want to update some statistics to a spreadsheet. The name of spreadsheet will be in the format CURRENT_MONTH-SOME NAME.xls. So a spreadsheet must be automatically created on the beginning of each month. Currently what I doing, at the year start, I will create 12 spreadsheets for the year manually and on each month, corresponding spreadsheets are retrieved and that's month's data is inserted or deleted or modified depending on my needs. So what I am searching here, I want to make this process automated ( spreadsheet should be created programmatically. I don't also prefer dependencies like installing Google Drive app and copying files to Google Drive app, as an alternative solution ). Please let me know your thoughts and suggestions on it.
Upvotes: 5
Views: 6638
Reputation: 465
Due to work requirements, I've been working with the google-apis, including the Sheets api. We have some test cases written in Google sheets, for that task we are using the gdata api. For writing new data to the defects sheet that we already have we are using the google-api-services-sheets
.
@eddyparkinson answer is right, to create a new spreadsheet programmatically, using a java API, you will need to do the management through the drive API. You have to give the script read/write permissions, through an OAuth permission
and then create a new spreadsheet and then alter it as you wish.
Here is a link to the drive quickstart https://developers.google.com/drive/v3/web/quickstart/java
You will have to change the scopes, to read write below
private static final List<String> SCOPES =
Arrays.asList(DriveScopes.DRIVE_METADATA_READONLY);
and then change the main to something like this
public static void main(String[] args) throws IOException{
//Insert a file
final Drive service = getDriveService();
final File body = new File();
body.setName("IntelliJ_Shortcuts");
body.setDescription("A test document");
body.setMimeType("text/plain");
final java.io.File fileContent = new java.io.File("D:\\MyFiles\\nkonstantinidis\\Study\\IntelliJ_Shortcuts.txt");
final FileContent mediaContent = new FileContent("text/plain", fileContent);
final File file = service.files().create(body, mediaContent).execute();
System.out.println("file ID: " + file.getId() + " file name: " + file.getName());
}
Upvotes: 0
Reputation: 2102
if you want to create spreadsheet better to user apache POI
here is an exaample
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
Upvotes: 1
Reputation: 123
Yes. You can use jexcel for reading and writing to spreadsheets. Check the tutorials of jexcel on www.andykhan.com/jexcelapi/tutorial.html
Upvotes: 0