我使用文档列表api在google docs上创建了我的电子表格模板的副本,我意识到:
1. title queries works fine
2. content queries are not working(*) or partially working(**)
(*)for majority of spreadsheets: I searched every word from the content of a spreadsheet and I get no results
(**) for a few spreadsheets I find results for some words that are copied from template; the particular words queries are not working
3. If I update the spreadsheet after a few minutes all queries work fine.
(I make this searches from UI)
以下是创建此文件的步骤:
1. Copy spreadsheet template to root
private String sendPostCopyRequest(String authorizationToken, String resourceID, String title, int noRetries) throws IOException{
/*
resourceId = resource id for the template that i want to copy
title = the title of the new file created
*/
String urlStr = "https://docs.google.com/feeds/default/private/full";
URL url = new URL(urlStr);
HttpURLConnection copyHttpUrlConn = (HttpURLConnection) url.openConnection();
copyHttpUrlConn.setDoOutput(true);
copyHttpUrlConn.setRequestMethod("POST");
String outputString = "<?xml version='1.0' encoding='UTF-8'?>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\"> " +
"<id>https://docs.google.com/feeds/default/private/full/" + resourceID +"</id>" +
" <title>" + title + "</title></entry>";
copyHttpUrlConn.setRequestProperty("GData-Version", "3.0");
copyHttpUrlConn.setRequestProperty("Content-Type","application/atom+xml");
copyHttpUrlConn.setRequestProperty("Content-Length", outputString.length() + "");
copyHttpUrlConn.setRequestProperty("Authorization", "GoogleLogin auth=" + authorizationToken);
OutputStream outputStream = copyHttpUrlConn.getOutputStream();
outputStream.write(outputString.getBytes());
copyHttpUrlConn.getResponseCode();
return readIdFromResponse(copyHttpUrlConn.getInputStream());
}
2. I update some cells using this method:
public boolean setCellValue(SpreadsheetService spreadSheetService, SpreadsheetEntry entry, int worksheetNumber, String position, String value) throws IOException, ServiceException {
List<WorksheetEntry> worksheets = entry.getWorksheets();
WorksheetEntry worksheet = worksheets.get(worksheetNumber);
URL cellFeedUrl = worksheet.getCellFeedUrl();
CellQuery query = new CellQuery(cellFeedUrl);
query.setReturnEmpty(true);
query.setRange(position);
CellFeed cellFeed = spreadSheetService.query(query, CellFeed.class);
CellEntry cell = cellFeed.getEntries().get(0);
cell.changeInputValueLocal(value);
cell.update();
return true;
}
3. I move the created file to a new folder (collection)
public DocumentListEntry moveSpreadSheet(DocsService docsService, String entryId, String destinationFolderDocId) throws MalformedURLException, IOException, ServiceException {
DocumentListEntry newEntry = null;
newEntry = new com.google.gdata.data.docs.SpreadsheetEntry();
newEntry.setId(entryId);
String destFolderUri = "https://docs.google.com/feeds/default/private/full/folder%3A"+ destinationFolderDocId + "/contents";
return docsService.insert(new URL(destFolderUri), newEntry);
}
(the same results with gdata java sdk api 1.4.5, 1.4.6, 1.4.7)
这发生在2011-12-23(近似)。对于在此日期之前使用相同代码创建的所有电子表格,所有查询都可以正常工作。
我可以根据要求提供任何其他信息。
更新
答案 0 :(得分:0)
您的问题可能与Google电子表格内容的索引放缓有关。
https://groups.google.com/a/googleproductforums.com/d/msg/docs/vEhI_HkKX3I/MGKqkryrx90J
“目前可能需要大约10分钟才能将您写入电子表格的内容编入索引。因此,如果您输入内容,然后立即搜索,它可能不会显示在您的列表中记录结果。再给它几分钟(我们正在努力加快速度)“