Method: Writexlsx::Worksheet#set_header
- Defined in:
- lib/write_xlsx/worksheet.rb
#set_header(string = '', margin = 0.3, options = {}) ⇒ Object
Set the page header caption and optional margin.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/write_xlsx/worksheet.rb', line 638 def set_header(string = '', margin = 0.3, = {}) raise 'Header string must be less than 255 characters' if string.length > 255 # Replace the Excel placeholder &[Picture] with the internal &G. = string.gsub("&[Picture]", '&G') # placeholeder /&G/ の数 placeholder_count = .scan("&G").count @page_setup.header = @page_setup. = [:align_with_margins] if [:align_with_margins] @page_setup. = [:scale_with_doc] if [:scale_with_doc] # 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| @header_images << ImageProperty.new([p.first], position: p.last) if [p.first] end # # placeholeder /&G/ の数 # placeholder_count = @page_setup.header.scan("&G").count raise "Number of header image (#{@header_images.size}) doesn't match placeholder count (#{placeholder_count}) in string: #{@page_setup.header}" if @header_images.size != placeholder_count @page_setup.margin_header = margin || 0.3 @page_setup. = true end |