简体   繁体   English

如何在Android / Java中以编程方式创建新的电子表格?

[英]How to create a new spreadsheet programmatically in Android/Java?

I am working on Google Spreadsheets API . 我正在使用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..). Google电子表格API仅说明了检索已创建的电子表格及其管理(包括单元格内容更新等)。 They also listed that it is possible to create a new spreadsheet by uploading a spreadsheet file via the Google Documents List API. 他们还列出了可以通过Google文档列表API上传电子表格文件来创建新的电子表格。 I have gone through Google Documents List API but I didn't find any documentation for Java. 我已经浏览了Google Documents List API,但我没有找到任何Java文档。 They only provided .Net documentation. 他们只提供.Net文档。 So my question is "Is it possible to create a new spreadsheet in Java/Android programmatically??". 所以我的问题是“是否有可能以编程方式在Java / Android中创建新的电子表格?”。

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. 更新:我不是在谈论在本地创建电子表格,而是在谈论通过API调用创建电子表格。 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. 电子表格的名称格式为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. 目前我在做什么,在年初,我将手动创建12个年度电子表格,并在每个月检索相应的电子表格,并根据我的需要插入或删除或修改月份的数据。 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 ). 所以我在这里搜索,我想让这个过程自动化(电子表格应该以编程方式创建。我也不喜欢安装Google Drive应用程序和将文件复制到Google Drive应用程序等依赖项,作为替代解决方案)。 Please let me know your thoughts and suggestions on it. 请让我知道你的想法和建议。

if you want to create spreadsheet better to user apache POI 如果你想更好地为用户apache POI创建电子表格

here is an exaample 这是一个例子

http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/ http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/

Yes. 是。 You can use jexcel for reading and writing to spreadsheets. 您可以使用jexcel读取和写入电子表格。 Check the tutorials of jexcel on www.andykhan.com/jexcelapi/tutorial.html‎ 在www.andykhan.com/jexcelapi/tutorial.html上查看jexcel的教程

Due to work requirements, I've been working with the google-apis, including the Sheets api. 由于工作要求,我一直在使用google-apis,包括Sheets api。 We have some test cases written in Google sheets, for that task we are using the gdata api. 我们有一些用Google表格编写的测试用例,为此我们正在使用gdata api。 For writing new data to the defects sheet that we already have we are using the google-api-services-sheets . 为了将新数据写入我们已经拥有的缺陷表,我们正在使用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. @eddyparkinson的回答是正确的,要使用java API以编程方式创建新的电子表格,您需要通过驱动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. 您必须通过OAuth permission脚本读/写权限,然后创建新的电子表格,然后根据需要进行更改。

Here is a link to the drive quickstart https://developers.google.com/drive/v3/web/quickstart/java 以下是驱动器快速入门的链接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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM