亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過文檔 API 向 Google 文檔添加文本?

如何通過文檔 API 向 Google 文檔添加文本?

Go
眼眸繁星 2022-08-30 21:59:17
我正在嘗試通過Google Docs API將文本添加到現有的Google Docs文件中,并且我正在使用Golang來實現此目的。我按照 https://developers.google.com/docs/api/quickstart/go 中的步驟操作,但我不知道如何編輯此文件?我發現如何將文本添加到文件中是我的代碼的相關部分:b := &docs.BatchUpdateDocumentRequest{        Requests: []*docs.Request{            {                InsertText: &docs.InsertTextRequest{                    Text: "texttoadd",                    Location: &docs.Location{                        Index: md.Body.Content[len(md.Body.Content)-1].EndIndex - 1,                    },                },            },        },    }    _, err = srv.Documents.BatchUpdate("your_document_id", b).Do()    if err != nil {        fmt.Println(err)    }
查看完整描述

2 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

查看他們的文檔,您可以看到InsertTextRequest,這可能就是您正在尋找的。

雖然文檔沒有給你任何Go示例,但API在其他語言中是相似的:https://developers.google.com/docs/api/how-tos/move-text

(我不能評論,這就是為什么這是一個答案)。


查看完整回答
反對 回復 2022-08-30
?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

這個答案有點晚了:

  1. go api 現在可以在這里找到:

  2. 關于代碼的細節,它應該有效。我在下面添加了一個步驟對步驟的方法。您必須首先創建結構,然后將其指針分配給請求結構。

長路代碼:

var batchreqs docs.BatchUpdateDocumentRequest    


var instxtreq docs.InsertTextRequest     


var txtloc docs.Location   


var breq docs.Request    


txtloc.Index = {your index}    


txtloc.SegmentID = "" // a bit superfluous    


instxtreq.Location = &txtloc   


instxtreq.Text = "your new text"    


breq.InsertText =&instxtreq   


var breqarray [1](*docs.Request)    


breqarray[0].InsertText = instxtreq   


breqslice = breqarray[:]


 batchreqs.Request = &breqslice    


// now you can do the BatchUpdate


 _, err = srv.Documents.BatchUpdate("your_document_id", &batchreqs).Do()


// the batch reqs must be a pointer to an existing batchupdaterequest structure


查看完整回答
反對 回復 2022-08-30
  • 2 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號