Hemant Rajpoot
Hemant Rajpoot

Reputation: 690

extract image from excel in nodejs

I am trying to extract all image in excel with node js.can anyone suggests any npm module for this. Here is an image of the excel file that I m using for the test.

screen shot of excel image

Upvotes: 2

Views: 4014

Answers (1)

cford 50
cford 50

Reputation: 106

I would use JSZip https://stuk.github.io/jszip/

You should be able to find the images inside the \xl\media\ directory of the excel file.

You can use ExcelJS to find out the the column and row that the image appears on. Unfortunately I have not found a way in ExcelJS to know the filename of the image that appears on that cell in the excel document.

Edit: You can open up sheet1.xml.rels to find what other files are used for creating sheet1. Among the list of files there should be a reference to a drawing1.xml file. Inside the drawing1.xml.rels file you can find a link to the images inside the media folder. This file also gives each of these files an Id. drawing1.xml has information about what images it should place inside the sheet.

Here is the general structure:

<xdr:twoCellAnchor editAs="oneCell">
    <xdr:from>
        <xdr:col>4</xdr:col>
        <xdr:row>14</xdr:row>
    </xdr:from>
    <xdr:pic>
        <xdr:blipFill>
            <a:blip xmlns:r="" r:embed="rId2" cstate="print">
            </a:blip>
        </xdr:blipFill>
    </xdr:pic>
    <xdr:clientData />
</xdr:twoCellAnchor>

If you add 1 to both the col and row values you will get the cell that the image is stored inside of. rId2 is an Id that references the media definitions inside of drawing1.xml.rels

Upvotes: 2

Related Questions