Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to freeze the header pane using axlsx with Rails

I am Using the Axlsx gem with rails to create the Excel sheet. I need the header to be fixed and frozen. The header to should be always visible even we scroll down. rails version 3.2.1 gem 'axlsx'

Any help is appreciated?

like image 753
user1517686 Avatar asked Jan 30 '26 12:01

user1517686


1 Answers

You can freeze the pane like this example:

  require 'axlsx'
  XLSX_temp = 'simple.xlsx'

  Axlsx::Package.new do |p|
      p.workbook.add_worksheet(:name => 'DATA') do |sheet|
        sheet.add_row(%w{key col1 col2 col3 col4 col5})
        #Fix first line and column
        sheet.sheet_view.pane do |pane|
          pane.top_left_cell = "B2"
          pane.state = :frozen_split
          pane.y_split = 1
          pane.x_split = 1
          pane.active_pane = :bottom_right
        end

        10.times{
          sheet.add_row(%w{1 2 3 4 5 6})
        }
      end    

      puts "Write %s" % XLSX_temp
      p.serialize(XLSX_temp)
  end

The result has a fixed first column and row:

enter image description here

With pane.x_split = 0 only the first row is fixed.

like image 70
knut Avatar answered Feb 01 '26 04:02

knut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!