Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert image as 'Place in cell' #186

Closed
jdugh opened this issue Feb 7, 2024 · 2 comments
Closed

Insert image as 'Place in cell' #186

jdugh opened this issue Feb 7, 2024 · 2 comments

Comments

@jdugh
Copy link
Contributor

jdugh commented Feb 7, 2024

Hi @optilude, nice to retalk with you.

Place in cell features proposal

I have a new PR proposal to propose: Insert image as 'Place in cell', instead of 'Place over cell' as currently proposed with ${image:...}.

The Place in cell allow to place a picture directly 'in the cell' and the image respects the dimensions (and centering) of the cell (without dimension calculation as in the 'over cell'):
https://support.microsoft.com/en-gb/office/insert-picture-in-cell-in-excel-e9317aee-4294-49a3-875c-9dd95845bab0

this feature 'Place in cell' need the feature 'RichData' of MS Excel, I can't find from which version of Excel this feature is available.

So, I propose to add the substitution keyword 'imageincell' (${imageincell:my_json_key}) to use this new functionality : What do you think about the key 'imageincell' ?

What do you think about this PR ? In any case, I will implement this functionality on my side (I need it). I would just like to have your opinion so that I can then give you the PR.

Some pseudo code

If folder xl/richData does not exist, init it with default value;
rdrichvaluestructure.xml and rdRichValueTypes.xml seams to be 'static' files and never change If there are 1 or 5 images.

  • Adding the image in the media folder (already available in code).
  • richValueRel.xml.rels : Adding the new Relationship with incremental rId and link to image source
<?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="../media/image1.jpeg"/>
</Relationships>
  • rdrichvalue.xml : increment the count arg of rvData object; adding a 'rv' object with the first 'v' key which has the value {count-1} (I don't know what the 2nd object v corresponds to)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>   
<rvData xmlns="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata" count="1">   
    <rv s="0">
        <v>0</v>
        <v>5</v>
    </rv>
</rvData>
  • richValueRel.xml : Just add the rId of the rels referring to our picture
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<richValueRels xmlns="http://schemas.microsoft.com/office/spreadsheetml/2022/richvaluerel"
    xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <rel r:id="rId1"/>
</richValueRels>
  • xl/metadata.xml
    Can be a little complex to control everything 😁
    Increment the count arg of futureMetadata object; adding a 'kb' object
    Increment the count arg of valueMetadata object and adding a 'bk' objet
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
    xmlns:xlrd="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata">
    <metadataTypes count="1">
        <metadataType name="XLRICHVALUE" minSupportedVersion="120000" copy="1" pasteAll="1" pasteValues="1" merge="1" splitFirst="1" rowColShift="1" clearFormats="1" clearComments="1" assign="1" coerce="1"/>
    </metadataTypes>
    <futureMetadata name="XLRICHVALUE" count="1">
        <bk>
            <extLst>
                <ext uri="{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}">
                    <xlrd:rvb i="0"/>
                </ext>
            </extLst>
        </bk>
    </futureMetadata>
    <valueMetadata count="1">
        <bk>
            <rc t="1" v="0"/>
        </bk>
    </valueMetadata>
</metadata>
  • And make unit test !
@kant2002
Copy link
Collaborator

kant2002 commented Feb 8, 2024

Sounds cool. Given that I'm mostly maintain this library, I'm happy take this change if sufficient tests would be present.

@jdugh
Copy link
Contributor Author

jdugh commented Apr 18, 2024

Close with this PR :
#189
#190
#191

@jdugh jdugh closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants