gpt4 book ai didi

java - 如何使用 API 在新的 Google 电子表格中创建第一行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:48:00 24 4
gpt4 key购买 nike

这是我创建电子表格的方式:

DocsService client= new DocsService ("idea");
client.useSsl ();
client.setOAuthCredentials (oauthParameters, new OAuthHmacSha1Signer ());

DocumentListEntry newEntry= new com.google.gdata.data.docs.SpreadsheetEntry ();
newEntry.setTitle (new PlainTextConstruct ("GIdeaDB"));
DocumentListEntry insertedEntry= client.insert (new URL (
"https://docs.google.com/feeds/default/private/full/?xoauth_requestor_id="+ userEmail), newEntry);

现在我想把第一行写进去。

但不幸的是,所有 API 调用都基于这样一个事实,即已经有第一行,供您插入名称-值-对(名称是我要创建的标题)。 http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#CreatingTableRecords

有什么想法可以创建第一行吗?定义字段名称的那个。

最佳答案

终于找到了。你必须一个细胞一个细胞地做:

  oauthParameters= new GoogleOAuthParameters ();
oauthParameters.setOAuthConsumerKey (CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret (CONSUMER_SECRET);
oauthParameters.setOAuthType (OAuthType.TWO_LEGGED_OAUTH);
oauthParameters.setScope ("https://spreadsheets.google.com/feeds/");

SpreadsheetService spreadsheetService= new SpreadsheetService ("appname");
spreadsheetService.useSsl ();
spreadsheetService.setOAuthCredentials (oauthParameters,
new OAuthHmacSha1Signer ());

URL feedUrl= new URL (
"https://spreadsheets.google.com"
+ "/feeds/spreadsheets/private/full?title=Spreadsheetname&xoauth_requestor_id="
+ userEmail);

SpreadsheetFeed resultFeed= spreadsheetService.getFeed (feedUrl,
SpreadsheetFeed.class);

List <SpreadsheetEntry> spreadsheets= resultFeed.getEntries ();
SpreadsheetEntry spreadsheetEntry= spreadsheets.get (0);

URL worksheetFeedUrl= spreadsheetEntry.getWorksheetFeedUrl ();
log.severe (worksheetFeedUrl.toString ());
WorksheetFeed worksheetFeed= spreadsheetService.getFeed (
worksheetFeedUrl, WorksheetFeed.class);

List <WorksheetEntry> worksheetEntrys= worksheetFeed.getEntries ();
WorksheetEntry worksheetEntry= worksheetEntrys.get (0);

// Write header line into Spreadsheet
URL cellFeedUrl= worksheetEntry.getCellFeedUrl ();
CellFeed cellFeed= spreadsheetService.getFeed (cellFeedUrl,
CellFeed.class);

CellEntry cellEntry= new CellEntry (1, 1, "headline1");
cellFeed.insert (cellEntry);
cellEntry= new CellEntry (1, 2, "headline2");
cellFeed.insert (cellEntry);

关于java - 如何使用 API 在新的 Google 电子表格中创建第一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4348610/

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