Can't insert more than one image in sheet #795

Closed
opened 2017-08-28 10:29:18 +00:00 by jitendra-rsi · 6 comments
jitendra-rsi commented 2017-08-28 10:29:18 +00:00 (Migrated from github.com)

ws["!images"] = [];
$.each(images, function(index, image){
ws["!images"].push({
name: 'image' + index + '.png',
data: image.imageData,
opts: {base64: true},
type: "png",
position: {
type: 'twoCellAnchor',
attrs: {editAs: 'oneCell'},
from: {col: image.c, row: image.r},
to: {col: image.c + 1, row: image.r + 1}
}
});
});

ws["!images"] = []; $.each(images, function(index, image){ ws["!images"].push({ name: 'image' + index + '.png', data: image.imageData, opts: {base64: true}, type: "png", position: { type: 'twoCellAnchor', attrs: {editAs: 'oneCell'}, from: {col: image.c, row: image.r}, to: {col: image.c + 1, row: image.r + 1} } }); });
jitendra-rsi commented 2017-08-29 10:32:09 +00:00 (Migrated from github.com)

Hi ,
when inserting multiple image it's repeating first image

Hi , when inserting multiple image it's repeating first image
krishnakommuri commented 2017-12-06 04:57:20 +00:00 (Migrated from github.com)

replace rId with for loop i value
function write_drawing(images, rId) {
var o = [];
o[o.length] = (XML_HEADER);
o[o.length] = (DRAW_ROOT);

    for (var i = 0; i < images.length; i++) {
        var image = images[i];
        var pos = image.position || {};
        if (pos.type === 'twoCellAnchor') {
            var from = pos.from || {}, to = pos.to || {},
                fromCol = from.col || 0, toCol = to.col || 0,
                fromRow = from.row || 0, toRow = to.row || 0;

            var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>';
            twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>';
            twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">';
            twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>';
            twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>';
            twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>';
            o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs));
        }
    }

    if (o.length > 2) {
        o[o.length] = ('</xdr:wsDr>');
        o[1] = o[1].replace("/>", ">");
    }
    return o.join("");
}
replace rId with for loop i value function write_drawing(images, rId) { var o = []; o[o.length] = (XML_HEADER); o[o.length] = (DRAW_ROOT); for (var i = 0; i < images.length; i++) { var image = images[i]; var pos = image.position || {}; if (pos.type === 'twoCellAnchor') { var from = pos.from || {}, to = pos.to || {}, fromCol = from.col || 0, toCol = to.col || 0, fromRow = from.row || 0, toRow = to.row || 0; var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>'; twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>'; twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">'; twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>'; twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>'; twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>'; o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs)); } } if (o.length > 2) { o[o.length] = ('</xdr:wsDr>'); o[1] = o[1].replace("/>", ">"); } return o.join(""); }
demotascha commented 2017-12-07 10:59:51 +00:00 (Migrated from github.com)

@krishnakommuri Thank you very much.

@krishnakommuri Thank you very much.
SheetJSDev commented 2018-05-20 18:34:55 +00:00 (Migrated from github.com)

We offer this in the Pro compendium. Since companies have paid for the features already, it would be unfair to them if we turned around and made it available as open source. We have a longer comment in a gist.

We offer this in the [Pro compendium](https://sheetjs.com/pro). Since companies have paid for the features already, it would be unfair to them if we turned around and made it available as open source. [We have a longer comment in a gist.](https://gist.github.com/SheetJSDev/24b8acd317d01999d721b38de7c53021)
lucasverra commented 2019-04-03 19:51:38 +00:00 (Migrated from github.com)

replace rId with for loop i value
function write_drawing(images, rId) {
var o = [];
o[o.length] = (XML_HEADER);
o[o.length] = (DRAW_ROOT);

    for (var i = 0; i < images.length; i++) {
        var image = images[i];
        var pos = image.position || {};
        if (pos.type === 'twoCellAnchor') {
            var from = pos.from || {}, to = pos.to || {},
                fromCol = from.col || 0, toCol = to.col || 0,
                fromRow = from.row || 0, toRow = to.row || 0;

            var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>';
            twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>';
            twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">';
            twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>';
            twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>';
            twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>';
            o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs));
        }
    }

    if (o.length > 2) {
        o[o.length] = ('</xdr:wsDr>');
        o[1] = o[1].replace("/>", ">");
    }
    return o.join("");
}

@krishnakommuri can i contact you for advice on implementation ?

> replace rId with for loop i value > function write_drawing(images, rId) { > var o = []; > o[o.length] = (XML_HEADER); > o[o.length] = (DRAW_ROOT); > > ``` > for (var i = 0; i < images.length; i++) { > var image = images[i]; > var pos = image.position || {}; > if (pos.type === 'twoCellAnchor') { > var from = pos.from || {}, to = pos.to || {}, > fromCol = from.col || 0, toCol = to.col || 0, > fromRow = from.row || 0, toRow = to.row || 0; > > var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>'; > twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>'; > twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">'; > twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>'; > twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>'; > twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>'; > o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs)); > } > } > > if (o.length > 2) { > o[o.length] = ('</xdr:wsDr>'); > o[1] = o[1].replace("/>", ">"); > } > return o.join(""); > } > ``` @krishnakommuri can i contact you for advice on implementation ?
krishnakommuri commented 2019-04-04 04:54:28 +00:00 (Migrated from github.com)

Hi Verra,

 I don't have much knowledge on this one. One of the client we had requirement so used this sheetjs and just edited that line of code.

Thanks,
Krishna

Get Outlook for Androidhttps://aka.ms/ghei36


From: Lucas Verra notifications@github.com
Sent: Thursday, April 4, 2019 1:21:57 AM
To: SheetJS/js-xlsx
Cc: Krishna Kommuri; Mention
Subject: Re: [SheetJS/js-xlsx] Can't insert more than one image in sheet (#795)

replace rId with for loop i value
function write_drawing(images, rId) {
var o = [];
o[o.length] = (XML_HEADER);
o[o.length] = (DRAW_ROOT);

for (var i = 0; i < images.length; i++) {
    var image = images[i];
    var pos = image.position || {};
    if (pos.type === 'twoCellAnchor') {
        var from = pos.from || {}, to = pos.to || {},
            fromCol = from.col || 0, toCol = to.col || 0,
            fromRow = from.row || 0, toRow = to.row || 0;

        var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>';
        twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>';
        twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">';
        twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>';
        twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>';
        twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>';
        o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs));
    }
}

if (o.length > 2) {
    o[o.length] = ('</xdr:wsDr>');
    o[1] = o[1].replace("/>", ">");
}
return o.join("");

}

@krishnakommurihttps://github.com/krishnakommuri can i contact you for advice on implementation ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/SheetJS/js-xlsx/issues/795#issuecomment-479634218, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AMN2LL1cuvh9AwKQHWgkpLqzccCWtXvzks5vdQZdgaJpZM4PEWPY.

Hi Verra, I don't have much knowledge on this one. One of the client we had requirement so used this sheetjs and just edited that line of code. Thanks, Krishna Get Outlook for Android<https://aka.ms/ghei36> ________________________________ From: Lucas Verra <notifications@github.com> Sent: Thursday, April 4, 2019 1:21:57 AM To: SheetJS/js-xlsx Cc: Krishna Kommuri; Mention Subject: Re: [SheetJS/js-xlsx] Can't insert more than one image in sheet (#795) replace rId with for loop i value function write_drawing(images, rId) { var o = []; o[o.length] = (XML_HEADER); o[o.length] = (DRAW_ROOT); for (var i = 0; i < images.length; i++) { var image = images[i]; var pos = image.position || {}; if (pos.type === 'twoCellAnchor') { var from = pos.from || {}, to = pos.to || {}, fromCol = from.col || 0, toCol = to.col || 0, fromRow = from.row || 0, toRow = to.row || 0; var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>'; twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to>'; twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i+1) + '" name="' + image.name + '">'; twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>'; twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + (i+1) + '"/>'; twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>'; o[o.length] = (writextag('xdr:twoCellAnchor', twoCell, images[i].attrs)); } } if (o.length > 2) { o[o.length] = ('</xdr:wsDr>'); o[1] = o[1].replace("/>", ">"); } return o.join(""); } @krishnakommuri<https://github.com/krishnakommuri> can i contact you for advice on implementation ? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<https://github.com/SheetJS/js-xlsx/issues/795#issuecomment-479634218>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AMN2LL1cuvh9AwKQHWgkpLqzccCWtXvzks5vdQZdgaJpZM4PEWPY>.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#795
No description provided.