let ImageCellType = function ImageCellType (img) {
this.img = img
}
ImageCellType.prototype = new spreadNS.CellTypes.Text();
var img = undefined;
ImageCellType.prototype.paint = function (ctx, value, x, y, width, height, style, context) {
spreadNS.CellTypes.RowHeader.prototype.paint.apply(this, arguments);
if (img) {
ctx.save();
ctx.beginPath();
ctx.moveTo(x, y);
ctx.drawImage(img, x+width/5.5, y, 20, 20);
ctx.restore();
return
}
//创建新的图片对象
img = new Image();
//指定图片的URL
img.src = this.img
//浏览器加载图片完毕后再绘制图片
img.onload = function () {
context.sheet.repaint();
}
};
window.ImageCellType = ImageCellType; |