找回密码
 立即注册

QQ登录

只需一步,快速开始

尛森

注册会员

13

主题

25

帖子

124

积分

注册会员

积分
124
尛森
注册会员   /  发表于:2022-3-3 15:26  /   查看:1795  /  回复:1
1金币
TipCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {

    ctx.font = style.font;
    value = fittingString(ctx, value, w - 2);
    spreadNS.CellTypes.Text.prototype.paint.apply(this, arguments);
};

function fittingString(c, str, maxWidth) {

    var width = c.measureText(str).width;
    var ellipsis = '…';
    var ellipsisWidth = c.measureText(ellipsis).width;
    if (width <= maxWidth || width <= ellipsisWidth) {
        return str;
    } else {
        var len = str.length;
        while (width >= maxWidth - ellipsisWidth && len-- > 0) {
            str = str.substring(0, len);
            width = c.measureText(str).width;
        }
        return str + ellipsis;
    }
}

最佳答案

查看完整内容

sheet.options.allowCellOverflow = false; 这句代码没有设置,设置了就好了

1 个回复

倒序浏览
最佳答案
最佳答案
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-3-3 15:26:36
来自 2#
sheet.options.allowCellOverflow = false; 这句代码没有设置,设置了就好了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部