如何创建一个使用谷歌Android US preadsheet API列表范围验证 [英] How to create a list range validation using the Android Google Spreadsheet API
问题描述
我创建,创建在谷歌驱动新的S preadsheet和里面插入一些数据的Android应用。目前,我可以插入自由文本和公式,但我需要添加一些特定的验证,具体降下来predefined值列表。
I am creating an android application that creates a new Spreadsheet in Google Drive and inserts some data inside. Currently I can insert free Text and Formulas, but I need to add some specific validations and specifically a drop down list with predefined values.
预期的结果应该是这样的:
The expected result should be something like this:
我用这code:
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;
}
}
我需要一种方法来从用户界面编程,而不是插入此标准范围列表从API。
I need a way to insert this Criteria Range List From the API programmatically and not from the UI.
感谢您。
推荐答案
您可以使用谷歌Apps脚本,你可以调用谷歌从一台服务器Apps脚本,但也没办法用(GDATA)做IT方面preadsheet-API做到这一点。
requireValueInList(values, showDropdown)
You can do it with Google Apps Script, you can call google apps script from a server, but there is no way to do it with the (gdata) spreadsheet-api.
从文档<一个href=\"https://developers.google.com/apps-script/reference/s$p$padsheet/data-validation-builder#requireValueInList(String,Boolean)\"相对=nofollow> requireValueInList
// 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);
这篇关于如何创建一个使用谷歌Android US preadsheet API列表范围验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!