请选择 进入手机版 | 继续访问电脑版

jin.ye

金牌服务用户

119

主题

240

帖子

971

积分

金牌服务用户

积分
971
jin.ye
金牌服务用户   /  发表于:2022-11-15 11:12  /   查看:1998  /  回复:4

自定义单元格保存时,如何才能将单元格设置为数字,现为 以文本形式存储的数字


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

4 个回复

Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-11-15 14:19:34
沙发
您好,
您可以新建一个sheet,在其中一个单元格中输入数字,会发现此时value是number类型的。
所以,从截图来看,该string类型的数字的产生可能与自定义单元格有关,您自定义单元格是如何设置的呢?
请提供下相关代码与ssjson文件 ,并详细描述下产生此string类型数字的步骤,这边测试调研下原因。
回复 使用道具 举报
jin.ye
金牌服务用户   /  发表于:2022-11-16 10:18:06
板凳
Lynn.Dou 发表于 2022-11-15 14:19
您好,
您可以新建一个sheet,在其中一个单元格中输入数字,会发现此时value是number类型的。
所以,从截 ...

// 底稿取值类型
var ShowDgFetch = (function () {
    function ShowDgFetch() {
        this.typeName = 'ShowDgFetch';
        this._cellTagStartCache = undefined;
        this._textWidth = undefined;
    }

    ShowDgFetch.prototype = new GC.Spread.Sheets.CellTypes.Text();
    ShowDgFetch.prototype.paintContent = function (ctx, value, x, y, w, h, style, context) {
        var tag = context.sheet.getTag(context.row, context.col);
        if (tag == '' || tag == null || tag === undefined) {
            this._cellTagStartCache = undefined;
            this._textWidth = undefined;
            GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, value, x, y, w, h, style, context);
            return;
        }
        this._cellTagStartCache = [], this._textWidth = 0;
        var startTextWidth = 0, endTextWidth = 0;
        var sheet = context.sheet, zoomFactor = sheet.zoom();
        var foreColor = style.foreColor, textDecoration = style.textDecoration;

        //为了实现简单,单元格垂直居中,如果有其他需求,绘制文字位置重新计算
        style.vAlign = GC.Spread.Sheets.VerticalAlign.center;

        for (var i = 0; i < tag.cellTagStart.length; i++) {
            var node = tag.cellTagStart[i;

            if (node.type === 'link') {
                style.foreColor = 'blue';
                style.textDecoration = GC.Spread.Sheets.TextDecorationType.underline;
                var linkText = node.linkText;
                GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, linkText, x + startTextWidth + 2, y, w - startTextWidth, h, style, context);
                var textWidth = GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, linkText, linkText, style, zoomFactor, context);
                this._cellTagStartCache[i] = {
                    startX: x + startTextWidth,
                    textWidth: textWidth + 3,
                    dgFileId: node.dgFileId,
                    dgFileInputVal: node.dgFileInputVal,
                    dgFileInputText: node.dgFileInputText,
                    dgFileSelectVal: node.dgFileSelectVal,
                    dgSheetSelectVal: node.dgSheetSelectVal,
                    dgSheetName: node.dgSheetName,
                    dgRange: node.dgRange,
                    linkText: node.linkText,
                    type: node.type
                };
                startTextWidth += (textWidth + 3);
            }
        }
        this._textWidth += startTextWidth;

        // Set Font to default
        style.foreColor = foreColor;
        style.textDecoration = textDecoration;

        //Paint Value
        // style.font = 'bold ' + style.font;
        style.hAlign = GC.Spread.Sheets.HorizontalAlign.right;
        style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
        GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, value, x, y, w - endTextWidth - 3, h, style, context)

    };

    ShowDgFetch.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
        var info = {
            x: x,
            y: y,
            row: context.row,
            col: context.col,
            cellRect: cellRect,
            sheetArea: context.sheetArea,
            isReservedLocation: false,
            reservedLocation: -1
        };
        for (var i = 0; i < this._cellTagStartCache.length; i++) {
            var item = this._cellTagStartCache[i;
            if (item) {
                var startX = item.startX;
                if (x - startX > 0 && x < startX + item.textWidth) {
                    info.isReservedLocation = true;
                    info.reservedLocation = i;
                    break;
                }
            }
        }
        return info;
    };
    ShowDgFetch.prototype.processMouseUp = function (hitInfo) {
        return false;
    };

    ShowDgFetch.prototype.processMouseMove = function (hitInfo) {
        return false;
    };

    ShowDgFetch.prototype.processMouseLeave = function (hitInfo) {
    };

    ShowDgFetch.prototype.getAutoFitWidth = function (value, text, cellStyle, zoomFactor, context) {
        if (this._textWidth) {
            // cellStyle.font = 'bold ' + cellStyle.font;
            return 5 + this._textWidth + GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, value, text, cellStyle, zoomFactor, context);
        } else {
            return GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, value, text, cellStyle, zoomFactor, context)
        }
    };
    return ShowDgFetch;
})();
designer.ShowDgFetch = ShowDgFetch;
回复 使用道具 举报
jin.ye
金牌服务用户   /  发表于:2022-11-16 10:18:48
地板
Lynn.Dou 发表于 2022-11-15 14:19
您好,
您可以新建一个sheet,在其中一个单元格中输入数字,会发现此时value是number类型的。
所以,从截 ...

var cellTagStart = [];
cellTagStart.push({
    type: 'link',
    linkText: 'N',
    dgFileInputVal: dgFileInput.val(),
    dgFileInputText: dgFileInput.text(),
    dgFileSelectVal: dgFileSelect.val() != null ? dgFileSelect.val() : dgFileInput.text(),
    dgSheetSelectVal: dgSheetSelect.val(),
    dgFileId: dgFileInput.text().substring(0, dgFileInput.text().indexOf(':')),
    dgSheetName: dgSheetSelect[0.selectedOptions[0.text,
    dgRange: dgRange.val()
});var activeCell = sheet.getCell(rowIndex, columnIndex);spread.suspendPaint();
activeCell.value(dgValue);
activeCell.cellType(new designer.ShowDgFetch());
activeCell.tag({
    cellTagStart: cellTagStart
});
// 居左
activeCell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
spread.resumePaint();
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-11-16 14:43:08
5#
根据提供的代码尝试复现此问题,发现代码存在错误提示,如下图:


请在附件demo基础上将代码补充完整,需要可复现此问题。
另,代码中注意到您给单元格赋值“dgValue”,您检查下“dgValue”是否是string类型数值,如果是修改为number类型再测试下。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部