qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.41k stars 1.72k forks source link

Support absolute paths for `GetPictureCells` and `GetPictures` functions #1988

Closed slashdotdash closed 2 months ago

slashdotdash commented 2 months ago

PR Details

Support absolute paths for the GetPictureCells and GetPictures functions.

Description

Detects when a relationship target is an absolute path (starts with /) and trims the prefix. The behaviour for relative paths is unchanged.

Related Issue

Fixes #1987.

Motivation and Context

This PR solves an issue when attempting to get pictures from an Excel file which uses absolute paths in the XML for the relationship target, such as in the example XML snippet below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1"
        Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
        Target="/xl/media/image1.jpg" />
</Relationships>

How Has This Been Tested

The changes have been tested locally using the problematic Excel file attached to the issue and the PR extends the existing TestGetPicture test (in picture_test.go) to get picture cells and pictures with an absolute target path in the drawing relationship.

Types of changes

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.31%. Comparing base (0447cb2) to head (df20658). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1988 +/- ## ======================================= Coverage 99.31% 99.31% ======================================= Files 32 32 Lines 25267 25277 +10 ======================================= + Hits 25095 25105 +10 Misses 92 92 Partials 80 80 ``` | [Flag](https://app.codecov.io/gh/qax-os/excelize/pull/1988/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qax-os) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/qax-os/excelize/pull/1988/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qax-os) | `99.31% <100.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qax-os#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.