Google スプレッドシートにバッチ データを挿入しようとしています。テスト目的で。ワークシート ( W1 ) をスプレッドシート ファイル (F1) に挿入しました。w1 からファイル (F2) のワークシート (W2) にすべてのデータをコピーしようとしています。助けてください。
これが私のコードです:
SpreadsheetService service = ServiceFactory.getService();
metafeedUrl = new URL(Constants.SPREADSHEET_URL);
/*
* Get files first
*/
SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> myFiles = feed.getEntries();
/*
* loop through the files and get your required file
*/
SpreadsheetEntry originalFile = null;
SpreadsheetEntry newFile = null;
WorksheetEntry workSheet = null;
for(SpreadsheetEntry file : myFiles){
if(file.getTitle().getPlainText().equalsIgnoreCase(originalSpreadSheet)){
originalFile = file;
List<WorksheetEntry> worksheets = file.getWorksheets();
for(WorksheetEntry worksheet : worksheets){
if(worksheet.getTitle().getPlainText().equals(worksheetName)){
workSheet = worksheet;
}
}
}
if(file.getTitle().getPlainText().equalsIgnoreCase(newSpreadSheet)){
newFile = file;
}
}
if(!(originalFile == null || newFile == null || workSheet == null)){
/*
* Insert a new work sheet in new file.
*/
WorksheetEntry newEntry = service.insert(newFile.getWorksheetFeedUrl(), workSheet);
/*
* Get all the rows from old work sheet
*/
URL listFeedUrl = workSheet.getListFeedUrl();
ListQuery query = new ListQuery(listFeedUrl);
query.setReverse(false);
ListFeed listFeed = service.query(query, ListFeed.class);
List<ListEntry> entries = listFeed.getEntries();
/*
* Batch update in the new work sheet
*/
ListFeed batchRequest = new ListFeed();
for(ListEntry entry : entries){
BatchUtils.setBatchId(entry, entry.getId());
BatchUtils.setBatchOperationType(entry, BatchOperationType.UPDATE);
batchRequest.getEntries().add(entry);
System.err.println("Adding entry " + entry.toString());
}
FeedURLFactory urlFactory = FeedURLFactory.getDefault();
URL list_FeedUrl = urlFactory.getListFeedUrl(newFile.getKey(), newEntry.getId(), "private", "full");
System.err.println("URL " + list_FeedUrl);
ListFeed list_Feed = service.getFeed(list_FeedUrl, ListFeed.class);
// Error at above line
Link batchLink = list_Feed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
System.err.println("Link " + batchLink);
ListFeed batchResponse = service.batch(new URL(batchLink.getHref()), batchRequest);
boolean isSuccess = true;
for (ListEntry entry : batchResponse.getEntries()) {
String batchId = BatchUtils.getBatchId(entry);
if (!BatchUtils.isSuccess(entry)) {
isSuccess = false;
BatchStatus status = BatchUtils.getBatchStatus(entry);
System.out.printf("%s failed (%s) %s", batchId, status.getReason(), status.getContent());
}
}
System.err.println("ALL OK");
}
次の例外が発生しています:
com.google.gdata.util.InvalidEntryException: Bad Request
Invalid query parameter value for grid-id.
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)