سؤال

I have a worksheet that I want to apply gridlines to only specific cells (disable for only specific cells works too). I've read the documentation and can only find out how to do it on a per worksheet basis. I've tried :gridlines=>true in my style just in case, but that didn't work.

So, the gist of it is, how can you add/remove gridlines for specific cells in AXLSX if it is even possible?

Update:

Here is a screenshot. On the left there are no apparent gridlines. When I check format cells I do not see any borders to create the effect. On the right you can see gridlines, and scrolling continously right will reveal more gridlines.

Excel Spreadsheet

هل كانت مفيدة؟

المحلول 2

this is really an excel question more than it is an axlsx question. in excel, you can only turn off gridlines on a sheet by sheet basis. i believe, what you are looking to do is to disable gridlines for the sheet and then create borders around a specific set of cells to simulate a 'gridline' look.

نصائح أخرى

With axlsx, you would need to so something like the following to achieve that combination of having no grid, but borders on certain cells:

require 'axlsx'
package = Axlsx::Package.new
package.workbook do |workbook|
  workbook.styles do |s|
    gridstyle_border =  s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" }
    workbook.add_worksheet :name => "Custom Borders"  do |sheet|
      sheet.sheet_view.show_grid_lines = false
      sheet.add_row ["with", "grid", "style"], :style => gridstyle_border
      sheet.add_row ["no", "border"]
    end
  end
end
package.serialize 'no_grid_with_borders.xlsx'

As you can see in the example above, the trick is to turn gridlines off on the sheet view, and then apply whatever border style you want to the cells that should have a border.

best

randym

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top