如何使用API​​格式化Google表格电子表格单元格? [英] How can I format a Google Sheets spreadsheet cell with the API?

查看:129
本文介绍了如何使用API​​格式化Google表格电子表格单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序会生成一张数据表,并在用户的Google云端硬盘中创建一个新的电子表格文档。如何将格式(颜色,字体重量,宽度等)添加到单个单元格?我似乎无法找到任何文档,更不用说我可以通过 google-api-ruby-client



我的大部分发现都追溯到Google API邮件列表声明它不被支持。

但是,我发现另一个应用程序实现了我想要的结果。 Smartsheet将文档导出到Google Drive的示例:

来自Smartsheet.com:



然后在我的Google Drive:



解决方案

Smartsheet利用Google API导入Excel文件的功能。代码大致沿着以下几行:

  DocsService client =新的DocsService(< YOUR APP NAME>); 
client.setOAuthCredentials(< OAUTH PARAMETERS>);

DocumentListEntry newEntry = new SpreadsheetEntry();
newEntry.setMediaSource(new MediaByteArraySource(< EXCEL FILE BYTE ARRAY OUTPUT STREAM> ;, DocumentListEntry.MediaType.XLS.getMimeType()));
newEntry.setTitle(new PlainTextConstruct(< FILE NAME>));

DocumentListEntry insertedEntry = client.insert(new URL(https://docs.google.com/feeds/default/private/full/),newEntry);

//这是你到新文档的URL
String docUrl = insertedEntry.getDocumentLink()。getHref();

我们已经能够通过Apache POI格式化将Smartsheet导出到Excel文件。将导出添加到Google Spreadsheet对我们来说实现起来非常简单,它提供了一些额外的功能,超出了您通过API可以实现的功能。



对延迟响应抱歉 - 只是发生在这个问题上。


My application generates a table of data and creates a new spreadsheet document in a user's Google Drive. How can I add formatting (color, font-weight, width, etc.) to individual cells? I can't seem to find any documentation, much less how I could implement this through the google-api-ruby-client.

Most of my findings date back to Google API mailing lists that state it isn't supported.
However, I found that another application accomplishes my desired result. An example of "Smartsheet" exporting a document to Google Drive:

From Smartsheet.com:

And the resulting sheet in my Google Drive:

解决方案

Smartsheet utilizes the ability of the Google API to import an Excel file. The code is roughly along these lines:

DocsService client = new DocsService(<YOUR APP NAME>);
client.setOAuthCredentials(<OAUTH PARAMETERS>);

DocumentListEntry newEntry = new SpreadsheetEntry();
newEntry.setMediaSource(new MediaByteArraySource(<EXCEL FILE BYTE ARRAY OUTPUT STREAM>, DocumentListEntry.MediaType.XLS.getMimeType()));
newEntry.setTitle(new PlainTextConstruct(<FILE NAME>));

DocumentListEntry insertedEntry = client.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newEntry);

// This is your URL to the new doc
String docUrl = insertedEntry.getDocumentLink().getHref();

We already had the ability to export a Smartsheet to an Excel file with formatting via Apache POI. Adding export to a Google Spreadsheet was quite simple for us to implement and it provided some additional functionality beyond what you could do via the API.

Sorry for the delayed response - just happened across this question.

这篇关于如何使用API​​格式化Google表格电子表格单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆