weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.27k stars 253 forks source link

Copy an image from one sheet to another sheet? #426

Open MyklClason opened 2 years ago

MyklClason commented 2 years ago

So here is what I'm trying to do:

1) Given an excel file with a single sheet it in (the template sheet) 2) Duplicate that sheet one or more times and changes each sheet (IE: Add rows) 3) The template sheet has an image in it.

This is working generally fine thanks to: https://stackoverflow.com/questions/29507841/create-multiple-sheets-that-uses-same-template-using-rubyxl

However, I'm having trouble figuring out how to copy the image. I tried the following based roughly on how cells was handled but didn't work out, and after a fair bit of digging around rows and cells I'm a bit stuck as to what to try next. It looks like the row data might have something in but it's a bit to buried for me to debug (ran into an infinite loop of too much nesting trying to inspect it).

worksheet.generic_storage = template.generic_storage.map(&:dup)