本帖最后由 ArnoldH 于 2019-6-17 20:00 编辑
您好,我在单元格中通过自定义迷你图函数的方式插入了图片,并且可以正确地显示出来了。但是在打印时却显示“[object Object]"。
使用的SpreadJS的版本是12.
具体如下:
1、增加了迷你图函数:
const CellImgHAlign = { left:1, center:2, right:0 };
const CellImgVAlign = { top:1, middel:0, bottom:3 };
function CellImg() {
GC.Spread.Sheets.Sparklines.SparklineEx.call(this);
}
CellImg.prototype = new GC.Spread.Sheets.Sparklines.SparklineEx();
CellImg.prototype.createFunction = function () {
var func = new GC.Spread.CalcEngine.Functions.Function("CELLIMG", 1, 5);
func.evaluate = function (args) {
var returnVal = new Object();
returnVal.iconImg = args[0];
//hAlign
if (args.length >= 2) {
returnVal.hAlign = args[1];
} else {
returnVal.hAlign = CellImgHAlign.center;
}
//vAlign
if (args.length >= 3) {
returnVal.vAlign = args[2];
} else {
returnVal.vAlign = CellImgHAlign.middel;
}
//imgWidth
if (args.length >= 4) {
returnVal.imgWidth = parseInt(args[3]);
} else {
returnVal.imgWidth = 0;
}
//imgHeight
if (args.length >= 5) {
returnVal.imgHeight = parseInt(args[4]);
} else {
returnVal.imgHeight = 0;
}
return returnVal;
};
return func;
};
CellImg.prototype.paint = function (context, value, x, y, width, height) {
if (value == null) {
console.log("paint(): value is null.");
return;
}
if (!value.iconImg) {
console.log("paint(): value.iconImg is null.");
return;
}
context.save();
// draw inside the cell's boundary
context.rect(x, y, width, height);
context.clip();
context.beginPath();
var img = document.createElement("img");
if (value.iconImg.indexOf("/") < 0) {
var defaultImgDir = WEB_CONTEXT_PATH + "/eip/tools/seditor/img_ud/";
img.src = defaultImgDir + value.iconImg;
} else {
img.src = value.iconImg;
}
//console.log("img.src:" + img.src);
var imgWidth = value.imgWidth; if (imgWidth == 0) { imgWidth = width;}
var imgHeight = value.imgHeight; if (imgHeight == 0) { imgHeight = height;}
//console.log("value:" + value.hAlign + ":" + value.vAlign);
var imgX = x + width - imgWidth;
if (value.hAlign == CellImgHAlign.left) {
imgX = x + 1;
} else if (value.hAlign == CellImgHAlign.center) {
imgX = x + (width - imgWidth) / 2;
}
var imgY = y;
//console.log(img.src + ":" + imgX + ":" + imgY);
try {
context.drawImage(img, imgX, imgY, imgWidth, imgHeight);
} catch (e) {
console.log(e.getMessage() + ":" + img.src);
}
context.closePath();
context.fill();
context.restore();
};
2、在单元格公式中输入:
=CELLIMG("DNA.jpg",1)
界面上可以正确地显示插入的图片,如下图所示:
但是在打印时,图片所在位置只显示了“[object Object]",如下图所示:
请问这个问题该如何解决?
|
|