设置工作表页面布局

  1. func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error

根据给定的工作表名称和页面布局参数设置工作表的页面布局属性。目前支持设置的页面布局属性:

  • 通过 PageLayoutOrientation 方法设置页面布局方向,默认页面布局方向为“纵向”。下面的表格是 Excelize 中页面布局方向 PageLayoutOrientation 参数的列表:

    参数方向
    OrientationPortrait纵向
    OrientationLandscape横向
  • 通过 PageLayoutPaperSize 方法设置页面纸张大小,默认页面布局大小为“信纸 8½ × 11 英寸”。下面的表格是 Excelize 中页面布局大小和索引 PageLayoutPaperSize 参数的关系对照:

    索引纸张大小
    1信纸 8½ × 11 英寸
    2简式信纸 8½ × 11 英寸
    3卡片 11 × 17 英寸
    4账单 17 × 11 英寸
    5律师公文纸 8½ × 14 英寸
    6报告单 5½ × 8½ 英寸
    7行政公文纸 7½ × 10 英寸
    8A3 297 × 420 毫米
    9A4 210 × 297 毫米
    10A4(小) 210 × 297 毫米
    11A5 148 × 210 毫米
    12B4 250 × 353 毫米
    13B5 176 × 250 毫米
    14对开本 8½ × 13 英寸
    15四开 215 × 275 毫米
    16美式标准纸张 10 × 14 英寸
    17美式标准纸张 11 × 17 英寸
    18Note paper 8.5 × 11 英寸
    19信封 #9 3.875 × 8.875 英寸
    20信封 #10 4-1/8 × 9½ 英寸
    21信封 #11 4.5 × 10.375 英寸
    22信封 #12 4.75 × 11 英寸
    23信封 #14 5 × 11.5 英寸
    24C paper 17 × 22 英寸
    25D paper 22 × 34 英寸
    26E paper 34 × 44 英寸
    27信封 DL 110 × 220 毫米
    28信封 C5 162 × 229 毫米
    29信封 C3 324 × 458 毫米
    30信封 C4 229 × 324 毫米
    31信封 C6 114 × 162 毫米
    32信封 C65 114 × 229 毫米
    33信封 B4 250 × 353 毫米
    34信封 B5 176 × 250 毫米
    35信封 B6 176 × 125 毫米
    36信封 Italy 110 × 230 毫米
    37君主式信封 3.88 × 7.5 英寸
    38信封 6 3/4 3.625 × 6.5 英寸
    39US standard fanfold 14.875 × 11 英寸
    40German standard fanfold 8.5 × 12 英寸
    41German legal fanfold 8.5 × 13 英寸
    42ISO B4 250 × 353 毫米
    43日式明信片 100 × 148 毫米
    44Standard paper 9 × 11 英寸
    45Standard paper 10 × 11 英寸
    46Standard paper 15 × 11 英寸
    47邀请信 220 × 220 毫米
    50Letter extra paper 9.275 × 12 英寸
    51Legal extra paper 9.275 × 15 英寸
    52Tabloid extra paper 11.69 × 18 英寸
    53A4 extra paper 236 × 322 毫米
    54Letter transverse paper 8.275 × 11 英寸
    55A4 transverse paper 210 × 297 毫米
    56Letter extra transverse paper 9.275 × 12 英寸
    57SuperA/SuperA/A4 paper 227 × 356 毫米
    58SuperB/SuperB/A3 paper 305 × 487 毫米
    59Letter plus paper 8.5 × 12.69 英寸
    60A4 plus paper 210 × 330 毫米
    61A5 transverse paper 148 × 210 毫米
    62JIS B5 transverse paper 182 × 257 毫米
    63A3 extra paper 322 × 445 毫米
    64A5 extra paper 174 × 235 毫米
    65ISO B5 extra paper 201 × 276 毫米
    66A2 420 × 594 毫米
    67A3 transverse paper 297 × 420 毫米
    68A3 extra transverse paper 322 × 445 毫米
    69双层日式明信片 200 × 148 毫米
    70A6 105 × 148 毫米
    71日式信封 Kaku #2
    72日式信封 Kaku #3
    73日式信封 Chou #3
    74日式信封 Chou #4
    75Letter Rotated (11in x 8 1/2 11 in)
    76A3 横向旋转 420 × 297 毫米
    77A4 横向旋转 297 × 210 毫米
    78A5 横向旋转 210 × 148 毫米
    79B4 (JIS) 横向旋转 364 × 257 毫米
    80B5 (JIS) 横向旋转 257 × 182 毫米
    81日式明信片 横向旋转 148 × 100 毫米
    82双层日式明信片 横向旋转 148 × 200 毫米
    83A6 横向旋转 148 × 105 毫米
    84日式信封 Kaku #2 横向旋转
    85日式信封 Kaku #3 横向旋转
    86日式信封 Chou #3 横向旋转
    87日式信封 Chou #4 横向旋转
    88B6 (JIS) 128 × 182 毫米
    89B6 (JIS) 横向旋转 182 × 128 毫米
    9012 × 11 英寸
    91日式信封 You #4
    92日式信封 You #4 横向旋转
    93中式 16 开 146 × 215 毫米
    94中式 32 开 97 × 151 毫米
    95中式大 32 开 97 × 151 毫米
    96中式信封 #1 102 × 165 毫米
    97中式信封 #2 102 × 176 毫米
    98中式信封 #3 125 × 176 毫米
    99中式信封 #4 110 × 208 毫米
    100中式信封 #5 110 × 220 毫米
    101中式信封 #6 120 × 230 毫米
    102中式信封 #7 160 × 230 毫米
    103中式信封 #8 120 × 309 毫米
    104中式信封 #9 229 × 324 毫米
    105中式信封 #10 324 × 458 毫米
    106中式 16 开 横向旋转
    107中式 32 开 横向旋转
    108中式大 32 开 横向旋转
    109中式信封 #1 横向旋转 165 × 102 毫米
    110中式信封 #2 横向旋转 176 × 102 毫米
    111中式信封 #3 横向旋转 176 × 125 毫米
    112中式信封 #4 横向旋转 208 × 110 毫米
    113中式信封 #5 横向旋转 220 × 110 毫米
    114中式信封 #6 横向旋转 230 × 120 毫米
    115中式信封 #7 横向旋转 230 × 160 毫米
    116中式信封 #8 横向旋转 309 × 120 毫米
    117中式信封 #9 横向旋转 324 × 229 毫米
    118中式信封 #10 横向旋转 458 × 324 毫米
  • 例如,将名为 Sheet1 的工作表页面布局设置为横向并使用 A4(小) 210 × 297 毫米纸张:

  1. xl := excelize.NewFile()
  2. const sheet = "Sheet1"
  3. if err := xl.SetPageLayout(
  4. "Sheet1",
  5. excelize.PageLayoutOrientation(excelize.OrientationLandscape),
  6. ); err != nil {
  7. panic(err)
  8. }
  9. if err := xl.SetPageLayout(
  10. "Sheet1",
  11. excelize.PageLayoutPaperSize(10),
  12. ); err != nil {
  13. panic(err)
  14. }