gpt4 book ai didi

java - 如何使用 Android Google Spreadsheet API 创建列表范围验证

转载 作者:行者123 更新时间:2023-11-30 08:59:21 26 4
gpt4 key购买 nike

我正在创建一个 android 应用程序,它在 Google 云端硬盘中创建一个新的电子表格并在其中插入一些数据。目前我可以插入免费的文本和公式,但我需要添加一些特定的验证,特别是带有预定义值的下拉列表。

预期的结果应该是这样的:Dropdown Image

我正在使用这段代码:

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 而不是从 UI 插入此标准范围列表。

谢谢。

最佳答案

requireValueInList(值, showDropdown)

您可以使用 Google Apps Script 来完成,您可以从服务器调用 google apps 脚本,但无法使用 (gdata) 电子表格 API 来完成。

来自文档 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);

关于java - 如何使用 Android Google Spreadsheet API 创建列表范围验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27316098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com