diff options
| author | Stefan Daschek <[email protected]> | 2013-07-05 04:22:35 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2013-07-08 14:15:59 +0200 |
| commit | 92b73ffb1e5cdfb001da684c463856f79aff6e11 (patch) | |
| tree | 69c6de36e9ee3eb7a4bb241d65f4ccdf1d604d3a /lib/axlsx/drawing/pic.rb | |
| parent | b7e14c242c0d9fc3af7b7ad969ec25df21475547 (diff) | |
| download | caxlsx-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/drawing/pic.rb')
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 8ed8d042..89f4c1ea 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -102,15 +102,10 @@ module Axlsx "#{IMAGE_PN % [(index+1), extname]}" end - # The relational id withing the drawing's relationships - def id - @anchor.drawing.charts.size + @anchor.drawing.images.index(self) + 1 - end - - # Returns a relationship object for this object - # @return Axlsx::Relationship + # The relationship object for this pic. + # @return [Relationship] def relationship - Relationship.new(IMAGE_R, "../#{pn}") + Relationship.new(self, IMAGE_R, "../#{pn}") end # providing access to the anchor's width attribute @@ -177,7 +172,7 @@ module Axlsx picture_locking.to_xml_string(str) str << '</xdr:cNvPicPr></xdr:nvPicPr>' str << '<xdr:blipFill>' - str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="rId' << id.to_s << '"/>' + str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '"/>' str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>' str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>' str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>' |
