下面是之前成功导出设置图片的代码,您可以参考一下写法,再根据您实际情况调整代码:
for(var i=4;i<tableRow+4;i++)
{
picRows=sheet.getValue(i,0).split(".")
sheet.setValue(i,0,picRows[0])
startRow = i;
var url = "./Resources/Pictures/" + picRows[0] + ".png";
var pic = sheet.addPicture(picRows[0], undefined, startRow, 0, i + 1, 1, 0, 0);
var loadImage = function (url, picture) {
var imgElement = $(document.createElement("img"));
imgElement.bind("load", function () {
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
var dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL("image/png");
picture.src(dataURL);
});
imgElement[0].src = url;
}
loadImage(url, pic);
if(parseInt(picRows[1])>1)
{
sheet.addSpan(i, 0, parseInt(picRows[1]), 1);
i=i+parseInt(picRows[1])-1;
pic.pictureStretch(GcSpread.Sheets.ImageLayout.Zoom);
varPoint=new GcSpread.Sheets.Point(0,y);
pic.position(varPoint);
pic.height(parseInt(picRows[1])*40-18);
y=y+parseInt(picRows[1])*40;
}else{
sheet.getRow(i).height(68);
pic.pictureStretch(GcSpread.Sheets.ImageLayout.Zoom);
pic.height(50);
varPoint=new GcSpread.Sheets.Point(0,y);
pic.position(varPoint);
y=y+68;
}
}
|