diff options
| author | Randy Morgan <[email protected]> | 2012-03-12 23:11:34 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-03-12 23:11:34 +0900 |
| commit | 111292baa50b06445e181c0cb2284bf68117ab4a (patch) | |
| tree | b976da0b06efbc1c075805b0e37a9b912e2584c6 | |
| parent | b8fcb4a6b78cf0419487353d098d12671909c7e2 (diff) | |
| download | caxlsx-111292baa50b06445e181c0cb2284bf68117ab4a.tar.gz caxlsx-111292baa50b06445e181c0cb2284bf68117ab4a.zip | |
adding in option to show/hide gridlines in a sheet.
| -rw-r--r-- | examples/example.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 25 |
2 files changed, 27 insertions, 5 deletions
diff --git a/examples/example.rb b/examples/example.rb index 8058b50b..df5a401f 100644 --- a/examples/example.rb +++ b/examples/example.rb @@ -201,6 +201,13 @@ wb.add_worksheet(:name => "custom column widths") do |sheet| sheet.column_widths nil, 3 end + +##Hide Gridlines in worksheet +wb.add_worksheet(:name => "No Gridlines") do |sheet| + sheet.add_row ["This", "Sheet", "Hides", "Gridlines"] + sheet.show_gridlines = false +end + ##Specify Page Margins for printing margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7} wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet| diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 679817ce..a514c31c 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -35,6 +35,10 @@ module Axlsx # @return Array attr_reader :auto_filter + # Indicates if the worksheet should show gridlines or not + # @return Boolean + attr_reader :show_gridlines + # Page margins for printing the worksheet. # @example # wb = Axlsx::Package.new.workbook @@ -55,6 +59,7 @@ module Axlsx @page_margins ||= PageMargins.new yield @page_margins if block_given? @page_margins + end # Creates a new worksheet. @@ -62,8 +67,10 @@ module Axlsx # @see Workbook#add_worksheet # @option options [String] name The name of this worksheet. # @option options [Hash] page_margins A hash containing page margins for this worksheet. @see PageMargins + # @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet. def initialize(wb, options={}) @drawing = @page_margins = @auto_filter = nil + @show_gridlines = true @rows = SimpleTypedList.new Row self.workbook = wb @workbook.worksheets << self @@ -109,6 +116,14 @@ module Axlsx "#{rows.first.cells.first.r}:#{rows.last.cells.last.r}" end + # Indicates if gridlines should be shown in the sheet. + # This is true by default. + # @return [Boolean] + def show_gridlines=(v) + Axlsx::validate_boolean v + @show_gridlines = v + end + # Returns the cell or cells defined using excel style A1:B3 references. # @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber @@ -337,11 +352,11 @@ module Axlsx # this is required by rubyXL, spec says who cares - but it seems they didnt notice # however, it also seems to be causing some odd [Grouped] stuff in excel 2011 - so # removing until I understand it better. - # xml.sheetViews { - # xml.sheetView(:tabSelected => 1, :workbookViewId => 0) { - # xml.selection :activeCell=>"A1", :sqref => "A1" - # } - # } + xml.sheetViews { + xml.sheetView(:tabSelected => 1, :workbookViewId => 0, :showGridLines => show_gridlines) { + xml.selection :activeCell=>"A1", :sqref => "A1" + } + } if @auto_fit_data.size > 0 xml.cols { |
