On 5 Jul 2023, at 22:08, Josh Grou wrote:
Thanks for the pointer Charlie,
I didn't end up using the openpyxl handling for relationships but that got
me going in the right direction. Instead, I directly accessed the xml files
and looked for relationships with targets in the embedding folder which
seems to do the job. The only drawback I am having is that I am not
entirely sure where the actual sheet name is stored in the excel zip
archive, so for now I just have to go by the order of the sheets which does
seem to match up with the workbook.worksheets method. My implementation if
anyone has a similar problem:
You're making a rod for your own back because openpyxl provides all the primitives for handling the XML source reliably.
find
method might be useful) out the files you're looking forOn 7 Jul 2023, at 16:31, Josh Grou wrote:
Thanks for the feedback and advice Charlie,
I was being a bit lazy and not understanding the use of the openpyxl
RelationshipList class, I spent some time to refactor using the openpyxl
handling which turned out to be simpler than I thought it would be.
There may be a better method, but this seems to solve the task that I had
for this project in a fairly robust way. In the future I may add a file
extension filter to the find_workbook_attachments function as I am not sure
what all can be included in the openxml package content type.
The code looks fine though I don't know why you're loading the whole workbook first. You're also depending upon the private ws._rels attribute, which I wouldn't as I plan to do away with it.
A couple of notes:
I've done some refactoring of RelationshipList this week, more related to its use when writing files but also looking forward to making reading dependencies more deterministic. Procedural is where we came from but it does make the code a tad repetitive.