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.43k stars 1.73k forks source link

Add a way to set graphics in a header/footer #2018

Closed imirkin closed 3 weeks ago

imirkin commented 3 weeks ago

The full functionality of the VML drawing is not addressed here. However this seems to work for embedding regular images.

PR Details

Adds the ability to set header/footer graphics.

Description

This is a somewhat restricted implementation out of all the options possible. But it's enough to get the basics going, and I doubt anyone out there wants too much more than this offers -- image + width/height for scaling.

If this function is called twice, it won't "update" the existing bits, but rather just leave them around and make a new drawing / media image. I don't think there's any process to "GC" the left-overs, but it's also not completely clear what to do about this. The media object may be shared by multiple drawings / sheets that have the same image.

How Has This Been Tested

This is based on what MS Excel produces. I tried other variations but was mostly unsuccessful. I had some variations which produced a border (without using the formulas bit), and many which crashed Excel -- seems like the logic to processing these is a bit fragile. Not 100% sure what all is needed since there are a lot of permutations, but with everything I have, it seems to work OK.

Types of changes

Checklist

I wasn't too sure how to test the change, so I added an example.

codecov[bot] commented 3 weeks ago

Codecov Report

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

Project coverage is 99.20%. Comparing base (0d5d1c5) to head (e735fdd). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2018 +/- ## ======================================= Coverage 99.20% 99.20% ======================================= Files 32 32 Lines 29803 29880 +77 ======================================= + Hits 29565 29642 +77 Misses 158 158 Partials 80 80 ``` | [Flag](https://app.codecov.io/gh/qax-os/excelize/pull/2018/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/2018/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qax-os) | `99.20% <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.

imirkin commented 3 weeks ago

Great. I wasn't 100% sure about the API, and I couldn't come up with a good Get variant. But I think it's still useful without that. I thought about putting it into the SetHeaderFooter call, but since there's no good way to Get it, I decided against it. Happy to iterate on the API if you think it still needs work though.

xuri commented 3 weeks ago

Thanks for your contribution. I merged this PR. If you'd like to add GetLegacyDrawingHF function, that would be great.