Giter Club home page Giter Club logo

Comments (4)

DR-Univer avatar DR-Univer commented on August 28, 2024

能不能看看 calcChain里存储的数据? 因为这里和自动计算相关

from luckyexcel.

OPerri avatar OPerri commented on August 28, 2024

image
刚导入一个excel文件 calcChain参数是空数组

from luckyexcel.

OPerri avatar OPerri commented on August 28, 2024

我写了一个组装calcChain的初版代码,基本能满足导入后calcChain为空数组的问题。
1.组件问题:但是公式多了页面渲染确实会存在性能问题,
2.如果导入excel中存在隐藏列,下方代码 列对应关系也会有问题。

我的代码如下

`
function getCalcChain(sheetIndex,sheetJson){
/*
已知条件
1.celldata的结构如下:
{
"r": 9,
"c": 72,
"v": {
"ct": {
"fa": "#,##0.00"
},
"bg": "#99CCFF",
"fs": 10,
"ff": "宋体",
"ht": 2,
"vt": 0,
"tb": 1,
"v": 0,
"f": "=I10-Y10+AO10+BE10",
"m": "0.00"
}

		计算链条calcChain 的结构如下
			 {
				"r": 8, //行数
				"c": 5, //列数
				"index": luckysheet.getluckysheetfile()[0]["index"], //工作表id
				"func": [true, 23.75, "=C9+D9+E9"], //公式信息,包含公式计算结果和公式字符串
				"color": "w", //"w":采用深度优先算法 "b":普通计算
				"parent": null,
				"chidren": {},
				"times": 0
			}
			
	*/
 
	
	//var selfCellArray = luckysheet.getluckysheetfile()[sheetIndex]["celldata"];
	debugger;
	var selfCellArray = sheetJson["celldata"];
	var filterCells = [];
	for(var i = 0 ;i < selfCellArray.length ; i++){
		var itemCell = selfCellArray[i];
		if(i == 450){
			debugger;
			console.log(itemCell);
		}
		
		if(isNullObject(itemCell)
			|| isNullObject(itemCell["v"]) 
			|| isNullObject(itemCell["v"]["v"] ) 
			|| !isNumberObject(itemCell["v"]["v"])
			|| isNullObject(itemCell["v"]["f"])){  //将非数值并且不存在公式的单元格过滤掉
			continue;
		}
		
		itemCell["self_coordinate"] = getColId(itemCell["c"])+""+itemCell["r"];
		itemCell["self_func"] = itemCell["v"]["f"];
		filterCells.push(itemCell); 
	} 
	
	var sortCells = bubbleSort(filterCells);  //排序后的单元格
	
	var calcChain = [];
	for(var i = 0 ;i < sortCells.length ; i++){
		var itemCell = sortCells[i];
		
		calcChain.push({
				"r": itemCell["r"], //行数
				"c": itemCell["c"], //列数
				"index": sheetIndex, //工作表id
				"func": [true, itemCell["v"]["v"], itemCell["self_func"]], //公式信息,包含公式计算结果和公式字符串
				"color": "w", //"w":采用深度优先算法 "b":普通计算
				"parent": null,
				"chidren": {},
				"times": 0
		}); 
	}
	
	return calcChain;

}

//冒泡排序
function bubbleSort(arr) {
	var len = arr.length;
	for(var i = 0; i < len - 1; i++) {
		for(var j = 0; j < len - 1 - i; j++) {
			if(arr[j]["self_func"].indexOf(arr[j+1]["self_coordinate"]) != -1 ) {  //相邻元素两两对比,如果 元素2的公式中存在元素1的坐标则交换位置 
				var temp = arr[j+1];        // 元素交换
				arr[j+1] = arr[j];
				arr[j] = temp;
			}
		}
	}
	return arr;
}


function  getColId( colIndex){  //大小写问题//例如列下标是45,返回AS 
	if(colIndex == undefined || colIndex == 'undefined' || colIndex == null || colIndex =='null'){
		return "";
	}
	
	if(colIndex < 26 ){
		return String.fromCharCode( "A".charCodeAt() + colIndex );
	}
	
	if(colIndex < 26 * 26){
		return String.fromCharCode( "A".charCodeAt() + (parseInt(colIndex / 26)-1) ) +""+String.fromCharCode( "A".charCodeAt() + parseInt(colIndex % 26) );  //获取字符的ASCII码  ,大写字母A的ASCII码值是65 
	}
	  
	return "";
	  
}


function  getColNumber(col){ //例如列是AS,返回下标45
	if(col == undefined || col == 'undefined' || col == null || col =='null'){
		return -1;
	}
	
	col = col.toUpperCase().trim(); //转换成大写
	
	var colArray = col.split("");
	 
	if(indexArray == 1){
		return   colArray[i].charCodeAt() - "A".charCodeAt() ;
	}
	
	if(indexArray == 2){
		return   (colArray[0].charCodeAt() - "A".charCodeAt()) * 26 +(colArray[1].charCodeAt() - "A".charCodeAt());
	}
	
	return -1;
	  
}
 

function isNumberObject(value) {
  return  !isNullObject(value) && !isNaN(value);
}

function isNullObject(obj) {
   return ( typeof(obj) == "undefined" || obj == null ) ;
}

`

from luckyexcel.

DR-Univer avatar DR-Univer commented on August 28, 2024

可以把你的excel发出来看看? 现在公式的性能正在逐步优化中。

from luckyexcel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.