Permalink
Browse files

Fix position of pageMargins XML element.

Must appear after mergeCells but before drawing element.
  • Loading branch information...
1 parent 2861af8 commit 4338184111e19487665070f928208c15e539bd96 @noniq noniq committed Apr 5, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/axlsx/workbook/worksheet/worksheet.rb
  2. +7 −1 test/workbook/worksheet/tc_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 }]
@@ -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 = []

0 comments on commit 4338184

Please sign in to comment.