summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
diff options
context:
space:
mode:
authorStefan Daschek <[email protected]>2013-07-05 04:22:35 +0200
committerStefan Daschek <[email protected]>2013-07-08 14:15:59 +0200
commit92b73ffb1e5cdfb001da684c463856f79aff6e11 (patch)
tree69c6de36e9ee3eb7a4bb241d65f4ccdf1d604d3a /lib/axlsx/workbook/worksheet/worksheet_drawing.rb
parentb7e14c242c0d9fc3af7b7ad969ec25df21475547 (diff)
downloadcaxlsx-92b73ffb1e5cdfb001da684c463856f79aff6e11.tar.gz
caxlsx-92b73ffb1e5cdfb001da684c463856f79aff6e11.zip
Make relationship ids more reliable.
Relationship instances now keep track of their own id – this should be much more reliable than the old way of more or less “guessing” the relationship id based on the position of some object in some array. Fixes https://github.com/randym/axlsx/issues/212, especially. Each relationship now has its own, unique id – except for the cases when it doesn’t: Some relationships need to share the same id, see `Relation#should_use_same_id_as?` for the gory details. All tests pass, and the full example.xlsx is generated without errors and looks fine in Excel for Mac 2011. The pivot table example still has the problems mentioned in https://github.com/randym/axlsx/issues/168 – but as far as I can tell I didn’t make it worse (Excel is still be able to “repair” the file, and the repaired file then contains the pivot table).
Diffstat (limited to 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_drawing.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
index 9deeeec3..08cad1f7 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
@@ -41,24 +41,18 @@ module Axlsx
@drawing.is_a? Drawing
end
- # The relationship required by this object
+ # The relationship instance for this drawing.
# @return [Relationship]
def relationship
return unless has_drawing?
- Relationship.new(DRAWING_R, "../#{drawing.pn}")
- end
-
- # returns the index of the worksheet releationship that defines this drawing.
- # @return [Integer]
- def index
- worksheet.relationships.index{ |r| r.Type == DRAWING_R } +1
+ Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
end
# Serialize the drawing for the worksheet
# @param [String] str
def to_xml_string(str = '')
return unless has_drawing?
- str << "<drawing r:id='rId#{index}'/>"
+ str << "<drawing r:id='#{relationship.Id}'/>"
end
end
end