如何使用 API 格式化 Google 表格电子表格单元格? [英] How can I format a Google Sheets spreadsheet cell with the API?
问题描述
我的应用程序会生成一个数据表并在用户的 Google 云端硬盘中创建一个新的电子表格文档.如何向单个单元格添加格式(颜色、字体粗细、宽度等)?我似乎找不到任何文档,更不用说如何通过 google-api-ruby-client
.
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
.
我的大部分发现都可以追溯到 Google API 邮件列表,这些邮件列表声明它不受支持.
但是,我发现另一个应用程序实现了我想要的结果.将文档导出到 Google Drive 的Smartsheet"示例:
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:
来自 Smartsheet.com:
From Smartsheet.com:
我的 Google Drive 中的结果表:
And the resulting sheet in my Google Drive:
推荐答案
Smartsheet 利用 Google API 的功能来导入 Excel 文件.代码大致如下:
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();
我们已经能够通过 Apache POI 将 Smartsheet 导出为 Excel 文件并进行格式化.将导出添加到 Google 电子表格对我们来说实现起来非常简单,并且它提供了一些额外的功能,超出了您可以通过 API 完成的功能.
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屋!