获取工作表页边距

  1. func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error

根据给定的工作表名称和页边距参数获取工作表的页边距。页边距可选参数:

参数数据类型
PageMarginBotomfloat64
PageMarginFooterfloat64
PageMarginHeaderfloat64
PageMarginLeftfloat64
PageMarginRightfloat64
PageMarginTopfloat64
  • 例如,获取名为 Sheet1 的工作表页边距:
  1. f := excelize.NewFile()
  2. const sheet = "Sheet1"
  3. var (
  4. marginBottom excelize.PageMarginBottom
  5. marginFooter excelize.PageMarginFooter
  6. marginHeader excelize.PageMarginHeader
  7. marginLeft excelize.PageMarginLeft
  8. marginRight excelize.PageMarginRight
  9. marginTop excelize.PageMarginTop
  10. )
  11. if err := f.GetPageMargins(sheet,
  12. &marginBottom,
  13. &marginFooter,
  14. &marginHeader,
  15. &marginLeft,
  16. &marginRight,
  17. &marginTop,
  18. ); err != nil {
  19. fmt.Println(err)
  20. }
  21. fmt.Println("Defaults:")
  22. fmt.Println("- marginBottom:", marginBottom)
  23. fmt.Println("- marginFooter:", marginFooter)
  24. fmt.Println("- marginHeader:", marginHeader)
  25. fmt.Println("- marginLeft:", marginLeft)
  26. fmt.Println("- marginRight:", marginRight)
  27. fmt.Println("- marginTop:", marginTop)

得到输出:

  1. Defaults:
  2. - marginBottom: 0.75
  3. - marginFooter: 0.3
  4. - marginHeader: 0.3
  5. - marginLeft: 0.7
  6. - marginRight: 0.7
  7. - marginTop: 0.75