0
我对Java很陌生,对Google Data API也是新手。我正尝试在公开共享的电子表格中更改工作表的大小。我使用下面的代码:Java Google Spreadsheet API:更新公共工作表'java.lang.UnsupportedOperationException:条目无法更新'
import com.google.gdata.client.authn.oauth.*;
import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.*;
import com.google.gdata.data.batch.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.net.*;
import java.util.*;
static void writeToGoogleSpreadsheet(String spreadsheetKey) throws IOException, ServiceException {
SpreadsheetService service = new SpreadsheetService("com.example");
String urlString = "https://spreadsheets.google.com/feeds/worksheets/" + spreadsheetKey + "/public/basic";
URL url = new URL(urlString);
try {
WorksheetFeed worksheetFeed = service.getFeed(url, WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);
System.out.println(worksheet.getTitle().getPlainText());
System.out.println(worksheet.getCanEdit());
// Update the local representation of the worksheet.
worksheet.setTitle(new PlainTextConstruct("Updated Worksheet"));
worksheet.setColCount(40);
worksheet.setRowCount(40);
// Send the local representation of the worksheet to the API for
// modification.
worksheet.update();
} finally{}
}
控制台显示正确的工作表名称和大小,所以我敢肯定,我访问权工作。但是,worksheet.update()会引发以下异常:
Exception in thread "main" java.lang.UnsupportedOperationException: Entry cannot be updated
at com.google.gdata.data.BaseEntry.update(BaseEntry.java:635)
atcom.example.GoogleSpreadsheetCommunicator.writeToGoogleSpreadsheet(GoogleSpreadsheetCommunicator.java:119)
at com.example.Main.guildSim(Main.java:114)
at com.example.Main.main(Main.java:73)
有没有人知道我在做什么错?
感谢您的阅读和亲切的问候,
卡雷尔
这将解释很多!谢谢!你有没有关于这方面的未来参考文件?由于https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds'注意:单元格Feed支持私人和公共的可见性,以及完整和基本投影。“表明可以编辑公共流。 – user3613853
np!我从经验中了解到这一点,面临同样的问题,所以我查看了BaseEntry.java的源代码。同时请将答案标记为已接受,以便可以帮助他人 –