找回密码
 立即注册

QQ登录

只需一步,快速开始

aritime

注册会员

24

主题

43

帖子

157

积分

注册会员

积分
157
aritime
注册会员   /  发表于:2016-9-19 21:57  /   查看:5283  /  回复:7
以下是我的代码,整体意思是:当点击按钮时,加载json数据到SpreadJS在线表格编辑器中,然后将数组中的数据通过setValue函数设置到
指定的单元格中,数组大概有2000多个元素,相当于要设置2000多个单元格的值,在给单元格赋值之前和之后分别计时,即代码中的time1和time2,
发现这个过程要26秒钟,并且使不使用theSpread.isPaintSuspended(true)的耗时都一样,相当于停止重绘没起到作用,请问这是为什么呢?
还有没有好的方法或解决方案来快速为多个单元格赋值(这些单元格不是连在一起的)?
打开一张报表要用户等待30秒是在是要崩溃啊!!!

                                theSpread.isPaintSuspended(true); //停止重绘
                                theSpread.fromJSON(JSON.parse(json["theData"])); //加载模板数据
                                var sheetCount = theSpread.getSheetCount();
                                var theSheetAry = new Array(); //预先获取所有的工作页
                                for (var i = 0; i < sheetCount; i++)
                                {
                                    theSheetAry.push(theSpread.getSheet(i));
                                }

                                var time1 = Ext.Date.format(new Date(), "Y-m-d H:i:s"); //开始计时

                                //将补充数据设置到各单元格
                                var cellsJson = eval('(' + json["theDataPlus"] + ')');
                                for (var i = 0; i < cellsJson.length; i++)
                                {
                                    var cellJson = cellsJson[i];
                                    theSheetAry[cellJson["i"]].setValue(cellJson["j"], cellJson["k"], cellJson["value"]);
                                }

                                var time2 = Ext.Date.format(new Date(), "Y-m-d H:i:s"); //结束计时
                                theSpread.isPaintSuspended(false); //恢复重绘


7 个回复

倒序浏览
CCKan
银牌会员   /  发表于:2016-9-20 09:49:02
沙发
你把
theSpread.isPaintSuspended(true); //停止重绘
放在
theSpread.fromJSON(JSON.parse(json["theData"])); //加载模板数据
这行后面试试看

评分

参与人数 1金币 +999 收起 理由
Alice + 999

查看全部评分

回复 使用道具 举报
aritime
注册会员   /  发表于:2016-9-20 10:07:01
板凳
CCKan 发表于 2016-9-20 09:49
你把
theSpread.isPaintSuspended(true); //停止重绘
放在

刚刚试了一下,结果还是一样的。
回复 使用道具 举报
CCKan
银牌会员   /  发表于:2016-9-20 11:44:06
地板
如果你的 JSON 里面有公式的话,你试试
theSpread.fromJSON(JSON.parse(json["theData"])); //加载模板数据
theSpread.isPaintSuspended(true); //停止重绘
theSpread.suspendCalcService(true);
...
theSpread.resumeCalcService(true)
theSpread.isPaintSuspended(false); //恢复重绘

不行的话你按 F12 用浏览器的性能分析工具看看到底是哪个地方性能比较差。

评分

参与人数 1金币 +1000 收起 理由
Alice + 1000 神马都是浮云

查看全部评分

回复 使用道具 举报
aritime
注册会员   /  发表于:2016-9-20 12:06:49
5#
CCKan 发表于 2016-9-20 11:44
如果你的 JSON 里面有公式的话,你试试
theSpread.fromJSON(JSON.parse(json["theData"])); //加载模板数 ...

试了一下,的确是公式太多引起的,使用theSpread.suspendCalcService(true)是会快了不少,
但渲染完成后使用theSpread.resumeCalService(true)并没有使公式立刻生效,
有没有函数可以立刻进行公式计算并刷新数据的?
回复 使用道具 举报
CCKan
银牌会员   /  发表于:2016-9-20 12:25:53
6#
调用 theSpread.resumeCalService(true) 后就应该会让所有的公式重算的呀!
但是必须保证 theSpread.resumeCalService() 调用的次数跟 theSpread.suspendCalcService(true) 一样多。
回复 使用道具 举报
aritime
注册会员   /  发表于:2016-9-20 13:17:22
7#
CCKan 发表于 2016-9-20 12:25
调用 theSpread.resumeCalService(true) 后就应该会让所有的公式重算的呀!
但是必须保证 theSpread.resum ...

试了一下,再加上theSpread.repaint(),数据就刷新了,现在读取速度快了很多,多谢!
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2016-9-20 14:03:21
8#
aritime 发表于 2016-9-20 13:17
试了一下,再加上theSpread.repaint(),数据就刷新了,现在读取速度快了很多,多谢!

谢谢您的反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部