如何在Google Docs API上添加页脚

syqv5f0l  于 2023-04-18  发布在  Go
关注(0)|答案(1)|浏览(152)

我想在Go中给我的文档添加一个页脚。下面是我的代码。

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: "",
            },
        },
    }

但是在编辑器中(我使用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
nkoocmlb

nkoocmlb1#

您为页脚类型提供了不正确的值,根据库文档,(此处)允许的值为:

//   "HEADER_FOOTER_TYPE_UNSPECIFIED" - The header/footer type is
// unspecified.
//   "DEFAULT" - A default header/footer.

所以,进行以下更改,它应该可以工作:

createFooterReq := &docs.Request{
    CreateFooter: &docs.CreateFooterRequest{
        SectionBreakLocation: &docs.Location{},
        Type:                 "DEFAULT",
    },
}

相关问题