英文:
How to add a Footer on Google Docs API
问题
我正在尝试在Go中为我的文档添加页脚。以下是我的代码。
createFooterReq := &docs.Request{
CreateFooter: &docs.CreateFooterRequest{
SectionBreakLocation: &docs.Location{},
Type: "DEFAULT_FOOTER",
},
}
// 将文本插入页脚
footerText := "This is a footer added with Go"
insertTextReq := &docs.Request{
InsertText: &docs.InsertTextRequest{
Text: footerText,
EndOfSegmentLocation: &docs.EndOfSegmentLocation{
SegmentId: "",
},
},
}
但是在编辑器中(我使用的是vscode),没有错误,但是当我尝试运行时,出现了以下错误。
Error 400: Invalid value at 'requests[0].create_footer.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), "DEFAULT_FOOTER"Details:[{"@type": "type.googleapis.com/google.rpc.BadRequest","fieldViolations": [{"description": "Invalid value at 'requests[0].create_footer.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), "DEFAULT_FOOTER"","field": "requests[0].create_footer.type"}]}], invalidexit status 1
英文:
I'm trying to add a footer to my docs in Go. Here is my code.
createFooterReq := &docs.Request{
CreateFooter: &docs.CreateFooterRequest{
SectionBreakLocation: &docs.Location{},
Type: "DEFAULT_FOOTER",
},
}
// Insert text into the footer
footerText := "This is a footer added with Go"
insertTextReq := &docs.Request{
InsertText: &docs.InsertTextRequest{
Text: footerText,
EndOfSegmentLocation: &docs.EndOfSegmentLocation{
SegmentId: "",
},
},
}
But in the editor (I use vscode) there is no error but when I try to run, this error comes.
Error 400: Invalid value at 'requests[0].create_footer.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), "DEFAULT_FOOTER"Details:[{"@type": "type.googleapis.com/google.rpc.BadRequest","fieldViolations": [{"description": "Invalid value at 'requests[0].create_footer.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), "DEFAULT_FOOTER"","field": "requests[0].create_footer.type"}]}], invalidexit status 1
答案1
得分: 1
您为页脚类型提供了错误的值,根据库文档(这里),允许的值为:
// "HEADER_FOOTER_TYPE_UNSPECIFIED" - 未指定页眉/页脚类型。
// "DEFAULT" - 默认页眉/页脚。
因此,请进行以下更改,应该可以正常工作:
createFooterReq := &docs.Request{
CreateFooter: &docs.CreateFooterRequest{
SectionBreakLocation: &docs.Location{},
Type: "DEFAULT",
},
}
英文:
You are giving incorrect value for the footer type, as per the library docs, (here) the allowed values are:
// "HEADER_FOOTER_TYPE_UNSPECIFIED" - The header/footer type is
// unspecified.
// "DEFAULT" - A default header/footer.
So, make the following changes, and it should work:
createFooterReq := &docs.Request{
CreateFooter: &docs.CreateFooterRequest{
SectionBreakLocation: &docs.Location{},
Type: "DEFAULT",
},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论