Java 如何使用Android Google电子表格API创建列表范围验证
我正在创建一个android应用程序,在Google Drive中创建一个新的电子表格,并在其中插入一些数据。目前我可以插入自由文本和公式,但我需要添加一些特定的验证,特别是一个带有预定义值的下拉列表 预期结果应该是这样的: 我正在使用以下代码:Java 如何使用Android Google电子表格API创建列表范围验证,java,android,google-sheets,google-spreadsheet-api,google-drive-api,Java,Android,Google Sheets,Google Spreadsheet Api,Google Drive Api,我正在创建一个android应用程序,在Google Drive中创建一个新的电子表格,并在其中插入一些数据。目前我可以插入自由文本和公式,但我需要添加一些特定的验证,特别是一个带有预定义值的下拉列表 预期结果应该是这样的: 我正在使用以下代码: SpreadsheetFeed feed = spreadsheetService.getFeed( FeedURLFactory.getDefault() .getSpr
SpreadsheetFeed feed = spreadsheetService.getFeed(
FeedURLFactory.getDefault()
.getSpreadsheetsFeedUrl(),
SpreadsheetFeed.class);
// Creating the list of spreasheets in GDrive
List<com.google.gdata.data.spreadsheet.SpreadsheetEntry> spreadsheets = feed.getEntries();
// parsing trough the feed entries
for (int i = 0; i < spreadsheets.size(); i++) {
com.google.gdata.data.spreadsheet.SpreadsheetEntry e = (com.google.gdata.data.spreadsheet.SpreadsheetEntry) spreadsheets.get(i);
// IF WE LOCATE THE FILE BASED ON THE FILENAME
if( e.getTitle().getPlainText().equals(Constants.FILE_PREFIX + mFileName)) {
Log.d(TAG, "ENTRY: " + e.getTitle().getPlainText());
URL worksheetFeedUrl = e.getWorksheetFeedUrl();
Log.d(TAG, "worksheetFeedUrl: " + worksheetFeedUrl);
// The first time this feed is used to create the new worksheet
WorksheetFeed worksheetFeed = spreadsheetService.getFeed (worksheetFeedUrl, WorksheetFeed.class);
Log.d(TAG, "worksheetFeed OK !");
// Create the second worksheet
WorksheetEntry newWorksheet = new WorksheetEntry(15, 5);
newWorksheet.setTitle(new PlainTextConstruct("Sheet2"));
worksheetFeed.insert(newWorksheet);
// The second time this feed is used to get the worksheets
worksheetFeed = spreadsheetService.getFeed (worksheetFeedUrl, WorksheetFeed.class);
// Get the first worksheet and insert the titles
List <WorksheetEntry> worksheetEntrys = worksheetFeed.getEntries ();
WorksheetEntry sheet1 = worksheetEntrys.get(0);
WorksheetEntry sheet2 = worksheetEntrys.get(1);
URL sheet1CellFeedUrl = sheet1.getCellFeedUrl ();
CellFeed sheet1CellFeed = spreadsheetService.getFeed (sheet1CellFeedUrl, CellFeed.class);
sheet1CellFeed.insert (new CellEntry (1, 1, getResources().getString(R.string.cell_title_name)));
sheet1CellFeed.insert (new CellEntry (1, 2, getResources().getString(R.string.cell_title_description)));
sheet1CellFeed.insert (new CellEntry (3, 2, getResources().getString(R.string.some_string)));
sheet1CellFeed.insert (new CellEntry (13, 2, "=COUNTIF(Sheet1!F2:F,B3)"));
sheet1CellFeed.insert (new CellEntry (14, 2, "=B9 - TODAY()"));
break;
}
}
SpreadsheetFeed提要=spreadsheetService.getFeed(
FeedURLFactory.getDefault()
.getSpreadsheetsFeedUrl(),
电子表格feed.class);
//在GDrive中创建存储表列表
列表电子表格=feed.getEntries();
//通过提要条目进行解析
对于(int i=0;i
我需要一种方法以编程方式从API而不是从UI插入此条件范围列表
谢谢。RequiremeEinList(值,下拉列表)
您可以使用谷歌应用程序脚本,也可以从服务器调用谷歌应用程序脚本,但无法使用(gdata)电子表格api
来自文档
应用程序脚本主要是为谷歌应用程序之上的工作流自动化而设计的。没有简单的方法可以将它与客户联系起来,但有一种方法。取决于您的要求以及谁将使用该应用程序
我对Android与谷歌电子表格的集成更感兴趣。我希望DriveAPI能够处理Google电子表格的创建和修改。但谷歌电子表格API似乎是唯一的出路。你能重新格式化你的代码吗?似乎的
和如果
没有关闭。我正在从android应用程序中寻找创建电子表格的代码。你能分享创建电子表格的代码吗?非常感谢!我根本不知道谷歌应用程序脚本的存在。你为我节省了很多时间。我一定会尝试谷歌应用程序脚本。我只是不喜欢谷歌把所有事情都搞得乱七八糟,到处都是API…谷歌应用程序脚本是JavaScript,所以语法和内置函数都是JavaScript。我现在倾向于使用ethercalc,它是开源的,可以做很多Google sheets可以做的事情。org-有下拉列表和建议框的公式。它实际上可以创建和修改电子表格,但有严格的限制。例如,您不能设置背景颜色、字体样式、列表验证等。。。使用谷歌应用程序脚本,你可以完成所有这些事情。检查web服务基本上您可以通过web服务公开脚本的功能,例如用JSON与它通信。从Android客户端发送JSON数据,该服务将在谷歌电子表格中完成必要的工作。但正如我所说,这取决于用例场景是什么,因为所有谷歌应用服务都有配额和限制:
// Set the data validation for cell A1 to require "Yes" or "No", with no dropdown menu.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Yes', 'No'], false).build();
cell.setDataValidation(rule);