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}
}
});
});
Hi ,
when inserting multiple image it's repeating first image
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 Thank you very much.
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.
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 ?
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.
Most helpful comment
replace rId with for loop i value
function write_drawing(images, rId) {
var o = [];
o[o.length] = (XML_HEADER);
o[o.length] = (DRAW_ROOT);