Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix position of pageMargins XML element.

Must appear after mergeCells but before drawing element.
  • Loading branch information...
commit 4338184111e19487665070f928208c15e539bd96 1 parent 2861af8
@noniq noniq authored
View
2  lib/axlsx/workbook/worksheet/worksheet.rb
@@ -402,9 +402,9 @@ def to_xml_string
str.concat '<sheetData>'
@rows.each_with_index { |row, index| row.to_xml_string(index, str) }
str.concat '</sheetData>'
- page_margins.to_xml_string(str) if @page_margins
str.concat "<autoFilter ref='%s'></autoFilter>" % @auto_filter if @auto_filter
str.concat "<mergeCells count='%s'>%s</mergeCells>" % [@merged_cells.size, @merged_cells.reduce('') { |memo, obj| "<mergeCell ref='%s'></mergeCell>" % obj } ] unless @merged_cells.empty?
+ page_margins.to_xml_string(str) if @page_margins
str.concat "<drawing r:id='rId1'></drawing>" if @drawing
unless @tables.empty?
str.concat "<tableParts count='%s'>%s</tableParts>" % [@tables.size, @tables.reduce('') { |memo, obj| memo += "<tablePart r:id='%s'/>" % obj.rId }]
View
8 test/workbook/worksheet/tc_worksheet.rb
@@ -252,8 +252,14 @@ def test_to_xml_string
assert(errors.empty?, "error free validation")
end
- def test_valid_with_page_margins
+ # Make sure the XML for all optional elements (like pageMargins, autoFilter, ...)
+ # is generated in correct order.
+ def test_valid_with_optional_elements
@ws.page_margins.set :left => 9
+ @ws.auto_filter = "A1:C3"
+ @ws.merge_cells "A4:A5"
+ @ws.add_chart Axlsx::Pie3DChart
+ @ws.add_table "E1:F3"
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
errors = []
Please sign in to comment.
Something went wrong with that request. Please try again.