设置名称

  1. func (f *File) SetDefinedName(definedName *DefinedName) error

根据给定的名称和引用区域设置名称,默认范围是工作簿。例如:

  1. err := f.SetDefinedName(&excelize.DefinedName{
  2. Name: "Amount",
  3. RefersTo: "Sheet1!$A$2:$D$5",
  4. Comment: "defined name comment",
  5. Scope: "Sheet2",
  6. })

工作表的打印区域和打印标题设置:

工作表的打印区域和打印标题设置

  1. if err := f.SetDefinedName(&excelize.DefinedName{
  2. Name: "_xlnm.Print_Area",
  3. RefersTo: "Sheet1!$A$1:$Z$100",
  4. Scope: "Sheet1",
  5. }); err != nil {
  6. fmt.Println(err)
  7. }
  8. if err := f.SetDefinedName(&excelize.DefinedName{
  9. Name: "_xlnm.Print_Titles",
  10. RefersTo: "Sheet1!$A:$A,Sheet1!$1:$1",
  11. Scope: "Sheet1",
  12. }); err != nil {
  13. fmt.Println(err)
  14. }