def set_header(string = '', margin = 0.3, options = {})
      raise 'Header string must be less than 255 characters' if string.length >= 255
      # Replace the Excel placeholder &[Picture] with the internal &G.
      @page_setup.header = string.gsub(/&\[Picture\]/, '&G')

      if string.size >= 255
        raise 'Header string must be less than 255 characters'
      end

      if options[:align_with_margins]
        @page_setup.header_footer_aligns = options[:align_with_margins]
      end

      if options[:scale_with_doc]
        @page_setup.header_footer_scales = options[:scale_with_doc]
      end

      # Reset the array in case the function is called more than once.
      @header_images = []

      [
       [:image_left, 'LH'], [:image_center, 'CH'], [:image_right, 'RH']
      ].each do |p|
        if options[p.first]
          @header_images << [options[p.first], p.last]
        end
      end

      # placeholeder /&G/ の数
      placeholder_count = @page_setup.header.scan(/&G/).count

      image_count = @header_images.count

      if image_count != placeholder_count
        raise "Number of header image (#{image_count}) doesn't match placeholder count (#{placeholder_count}) in string: #{@page_setup.header}"
      end

      @has_header_vml = true if image_count > 0

      @page_setup.margin_header         = margin || 0.3
      @page_setup.header_footer_changed = true
    end
def set_header(string = '', margin = 0.3, options = {})
      raise 'Header string must be less than 255 characters' if string.length >= 255
      # Replace the Excel placeholder &[Picture] with the internal &G.
      @page_setup.header = string.gsub(/&\[Picture\]/, '&G')

      if string.size >= 255
        raise 'Header string must be less than 255 characters'
      end

      if options[:align_with_margins]
        @page_setup.header_footer_aligns = options[:align_with_margins]
      end

      if options[:scale_with_doc]
        @page_setup.header_footer_scales = options[:scale_with_doc]
      end

      # Reset the array in case the function is called more than once.
      @header_images = []

      [
       [:image_left, 'LH'], [:image_center, 'CH'], [:image_right, 'RH']
      ].each do |p|
        if options[p.first]
          @header_images << [options[p.first], p.last]
        end
      end

      # placeholeder /&G/ の数
      placeholder_count = @page_setup.header.scan(/&G/).count

      image_count = @header_images.count

      if image_count != placeholder_count
        raise "Number of header image (#{image_count}) doesn't match placeholder count (#{placeholder_count}) in string: #{@page_setup.header}"
      end

      @has_header_vml = true if image_count > 0

      @page_setup.margin_header         = margin || 0.3
      @page_setup.header_footer_changed = true
    end
Set the page header caption and optional margin.

 Headers and footers are generated using a string which is a combination
 of plain text and control characters. The margin parameter is optional.

 The available control character are:

     Control             Category            Description
     =======             ========            ===========
     &L                  Justification       Left
     &C                                      Center
     &R                                      Right

     &P                  Information         Page number
     &N                                      Total number of pages
     &D                                      Date
     &T                                      Time
     &F                                      File name
     &A                                      Worksheet name
     &Z                                      Workbook path

     &fontsize           Font                Font size
     &"font,style"                           Font name and style
     &U                                      Single underline
     &E                                      Double underline
     &S                                      Strikethrough
     &X                                      Superscript
     &Y                                      Subscript

     &&                  Miscellaneous       Literal ampersand &

 Text in headers and footers can be justified (aligned) to the left,
 center and right by prefixing the text with the control characters
 &L, &C and &R.

 For example (with ASCII art representation of the results):

     worksheet.set_header('&LHello')

      ---------------------------------------------------------------
     |                                                               |
     | Hello                                                         |
     |                                                               |


     worksheet.set_header('&CHello')

      ---------------------------------------------------------------
     |                                                               |
     |                          Hello                                |
     |                                                               |


     worksheet.set_header('&RHello')

      ---------------------------------------------------------------
     |                                                               |
     |                                                         Hello |
     |                                                               |

 For simple text, if you do not specify any justification the text will
 be centred. However, you must prefix the text with &C if you specify
 a font name or any other formatting:

     worksheet.set_header('Hello')

      ---------------------------------------------------------------
     |                                                               |
     |                          Hello                                |
     |                                                               |

 You can have text in each of the justification regions:

     worksheet.set_header('&LCiao&CBello&RCielo')

      ---------------------------------------------------------------
     |                                                               |
     | Ciao                     Bello                          Cielo |
     |                                                               |

 The information control characters act as variables that Excel will update
 as the workbook or worksheet changes. Times and dates are in the users
 default format:

     worksheet.set_header('&CPage &P of &N')

      ---------------------------------------------------------------
     |                                                               |
     |                        Page 1 of 6                            |
     |                                                               |


     worksheet.set_header('&CUpdated at &T')

      ---------------------------------------------------------------
     |                                                               |
     |                    Updated at 12:30 PM                        |
     |                                                               |

 You can specify the font size of a section of the text by prefixing it
 with the control character &n where n is the font size:

     worksheet1.set_header('&C&30Hello Big' )
     worksheet2.set_header('&C&10Hello Small' )

 You can specify the font of a section of the text by prefixing it with
 the control sequence &"font,style" where fontname is a font name such
 as "Courier New" or "Times New Roman" and style is one of the standard
 Windows font descriptions: "Regular", "Italic", "Bold" or "Bold Italic":

     worksheet1.set_header('&C&"Courier New,Italic"Hello')
     worksheet2.set_header('&C&"Courier New,Bold Italic"Hello')
     worksheet3.set_header('&C&"Times New Roman,Regular"Hello')

 It is possible to combine all of these features together to create
 sophisticated headers and footers. As an aid to setting up complicated
 headers and footers you can record a page set-up as a macro in Excel
 and look at the format strings that VBA produces. Remember however
 that VBA uses two double quotes "" to indicate a single double quote.
 For the last example above the equivalent VBA code looks like this:

     .LeftHeader   = ""
     .CenterHeader = "&""Times New Roman,Regular""Hello"
     .RightHeader  = ""

 To include a single literal ampersand & in a header or footer you
 should use a double ampersand &&:

     worksheet1.set_header('&CCuriouser && Curiouser - Attorneys at Law')

 As stated above the margin parameter is optional. As with the other
 margins the value should be in inches. The default header and footer
 margin is 0.3 inch. Note, the default margin is different from the
 default used in the binary file format by Spreadsheet::WriteExcel.
 The header and footer margin size can be set as follows:

     worksheet.set_header('&CHello', 0.75)

 The header and footer margins are independent of the top and bottom
 margins.

 Note, the header or footer string must be less than 255 characters.
 Strings longer than this will not be written and a warning will be
 generated.

 See, also the headers.rb program in the examples directory of the
 distribution.