⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excelpage.htm.bak

📁 本程序使用C#开发
💻 BAK
📖 第 1 页 / 共 2 页
字号:

		//循环找出要覆盖的区域
		var searchflag = true;
		while(searchflag)
		{
			searchflag = getcellobj();
		}
		var scellobj = tbs.get(srow+'-'+scol);
		var ecellobj = tbs.get(erow+'-'+ecol);
		var left = fnGetPosition(tbobj.rows[scellobj.row].cells[scellobj.col],'Left');
		var top = fnGetPosition(tbobj.rows[scellobj.row].cells[scellobj.col],'Top');
		var right = fnGetPosition(tbobj.rows[ecellobj.row].cells[ecellobj.col],'Right');
		var bottom = fnGetPosition(tbobj.rows[ecellobj.row].cells[ecellobj.col],'Bottom');
		hehe.style.left = left;
		hehe.style.top = top;
		hehe.style.width = right - left;
		hehe.style.height = bottom - top;
		hehe.style.display = '';
	}
	function getrowcol(kind,cellobj)
	{	
		while(cellobj!=null)
		{
			if(cellobj.tagName == "TD")
			{				
				var parentobj = cellobj.parentElement;
				var colspan = getmergecolnum(parentobj.rowIndex,cellobj.cellIndex);
				if(kind)
				{
					ohoh2.innerText ="row:"+cellobj.parentElement.rowIndex+",col:"+ cellobj.cellIndex+",colspan:"+colspan;
					srow = parentobj.rowIndex;
					scol = cellobj.cellIndex+colspan;
				}
				else
				{
					erow = parentobj.rowIndex+cellobj.rowSpan-1;
					ecol = cellobj.cellIndex+cellobj.colSpan-1+colspan;//要加上自身的列数				
				}
				return;
			}
			cellobj = cellobj.parentElement;
		}
	}
	//确定选择范围
	function getcellobj()
	{		
		if(scol>ecol){var temp=0; temp = scol; scol = ecol; ecol = temp; }
		for(var i = srow; i<=erow; i++)
		{			
			for(var j = scol; j<=ecol; j++)	
			{
				var checkobj = tbs.get(i + '-' + j); 
				if(i==srow||i==erow)//说明检查的是第一行或者最后一行
				{
					if(geteffectrowcol(checkobj,i,j))
						return true;
				}
				else//检查中间的行
				{
					if(j==scol||j==ecol)
					{
						if(geteffectrowcol(checkobj,i,j))
							return true;
					}
					else
					{
						continue;
					}
				}
			}
		}
		return false;
	}
	//得到当前合并格子所影响的行和列
	function geteffectrowcol(checkobj,row,col)
	{
		var currow = checkobj.row;//当前实际操作的行
		var curcol = checkobj.col;//当前实际操作的列
		var reloadflag= false;

		ohoh3.innerText = currow+','+curcol;
		if(checkobj.merge == false)//说明没有合并
		{
			return reloadflag;
		}
		else
		{
			var colnum = getmergecolnum(currow,curcol);
			if(currow>erow)
			{
				erow = currow;
				reloadflag = true;
			}
			if(currow<srow)
			{
				srow = currow;
				reloadflag = true;
			}
			if(curcol+colnum>ecol)
			{
				ecol = curcol+colnum;
				reloadflag = true;
			}
			if(curcol+colnum<scol)
			{
				scol = curcol+colnum;
				reloadflag = true;
			}
			return reloadflag;
		}
	}
	//获得某一行的某一列之前合并了多少列
	function getmergecolnum(row,col)
	{
		var n=col;
		for(;n<tablecol;n++)
		{
			var obj = tbs.get(row+'-'+n);
			if(obj.row == row&&obj.col == col)
				break;
		}
		return n-col;
	}
}
var selected_area = new selectedArea(null,null,'blue');

function getParentNodeByTagName(node,tagName)
{
	while(node.tagName != tagName) node = node.parentElement;
	return node;
}
function down()
{
	selected_area.sy = event.y;
	selected_area.ey = event.y;	
	n=1;
	var scellobj = event.srcElement;
	//ohoh2.innerText ="row:"+scellobj.parentElement.parentElement.rowIndex+",col:"+ scellobj.parentElement.cellIndex;
	if(scellobj.parentElement.tagName == "TD")
	{
		selected_area.sobj = scellobj;//设置sobj和eobj
		selected_area.eobj = scellobj;	
		selected_area.show();
		clickobj = scellobj;	
		getinputwidth();
	}
	//fdsf
	//if(clickobj!=null)
	//	clickobj.style.width = "";//清除之前单元格的样式
	
}
function up()
{
	n=0;
}
function move()
{
	selected_area.ey = event.y;	
	var ecellobj = event.srcElement;
	if(n!=1) return;
	if(ecellobj.parentElement.tagName == "TD")
	{
		selected_area.eobj = ecellobj;//设置eobj
		selected_area.show();
	}
}
function getFocusObj(kind,cellobj)
{
	if(kind)
	{
		selected_area.sobj = cellobj;
	}
	selected_area.eobj = cellobj;
}

//获得单元格对象的坐标
function fnGetPosition(obj,direction)
{
    var objPosition=0;
	if(direction == "Left")
	{
		 while (obj !=null){
			objPosition+=obj["offsetLeft"];
			obj=obj.offsetParent;
		 }
	}
	else if(direction == "Top")
	{
		while (obj !=null){
			objPosition+=obj["offsetTop"];
			obj=obj.offsetParent;
		 }
	}
	else if(direction == "Right")
	{
		var tdwidth = obj.offsetWidth;
		while (obj !=null){
			objPosition+=obj["offsetLeft"];
			obj=obj.offsetParent;
		 }
		 objPosition += tdwidth;
	}
	else
	{
		var tdheight = obj.offsetHeight;
		while (obj !=null){
			objPosition+=obj["offsetTop"];
			obj=obj.offsetParent;
		 }
		 objPosition += tdheight;
	}
    return objPosition;
}

//获得输入列的宽度
function getinputwidth()
{
	if(clickobj!=null)
	{
		owidth = clickobj.parentElement.offsetWidth-2;
		oheight = clickobj.offsetHeight;
		clickobj.style.width = clickobj.parentElement.offsetWidth-2;//设置当前单元格样式
	}
}
//接收键盘事件
document.onkeyup = function()
{   
	if(window.event.keyCode==13)
	{   
		tst();
		window.event.keycode = 0;   
		window.event.returnValue = false;   
	}
	else
	{
		if(clickobj==null)return;
		var nh=clickobj.offsetHeight;

		ohoh.innerText = oheight;
		ohoh1.innerText = nh;

		if(oheight==nh){return;}
		else
		{
			if(clickobj.parentElement.offsetHeight >= Number(nh)+2){oheight = nh;return;}
			//改变两个表的高度
			changeheight(nh-oheight);
			oheight = nh;
			ohoh.innerText = oheight;
			ohoh1.innerText = nh
		}
	}
 
}   
function tst()
{   
	if(clickobj==null)return;
	var bak = clipboardData.getData('Text');
	clipboardData.setData('Text','\n');
	clickobj.focus();   
	document.execCommand('Paste');   
	clipboardData.setData('Text',bak);   
}
function changeheight(h)
{
	//h为增加的高度
	var L = document.getElementById("lefttable");//MyHeadTab
	var B = document.getElementById("t1");//MyBodyTab
	var rows = clickobj.parentElement.rowSpan;
	var addheight = parseFloat(h)/parseFloat(rows);
	var rowindex = clickobj.parentElement.parentElement.rowIndex;
	for(var i=0 ;i<rows;i++)
	{
		var obj = tbs.get(Number(rowindex+i)+'-'+0);
		var h1 = B.rows[obj.row].cells[0].style.height.split('px')[0];
		B.rows[obj.row].cells[0].style.height = parseFloat(h1) + parseFloat(addheight);
		var h2 = L.rows[rowindex+i].cells[0].style.height.split('px')[0];
		L.rows[rowindex+i].cells[0].style.height = parseFloat(h2) + parseFloat(addheight);
	}
}

//************************拖动表头列宽******************************************
function HeadScroll()
	{
	document.getElementById("topdiv").scrollLeft = document.getElementById("rightdiv").scrollLeft;//THead,TBody
	}
function ChangWidth()
	{
	var e = event.srcElement;
	if (e == undefined)
		return;
	if (e.tagName != "TD")
		return;
	var H = document.getElementById("toptable");//MyHeadTab
	var B = document.getElementById("t1");//MyBodyTab
	var CellIndex;
	for (var  i = 0; i < H.rows(0).cells.length; i++)
		if (H.rows(0).cells[i] == e)
			{
			CellIndex = i;
			break;
			}
	CellIndex = i-1;
	var l = e.offsetLeft;
	if (e.style.cursor == "e-resize") //是改变列宽
		{
		e.setCapture();
		document.onmousemove = function ()
			{
			if (e == undefined)
				return;
			e.style.cursor = "e-resize";
			var w = event.x + document.body.scrollLeft - l;//getElementById("topdiv")
			ohoh.innerText = "hehe:"+w;
			if (w >= 5)
				{
				e.style.width = w;
				if (B.rows.length < 1)
					return;
				B.rows(0).cells[CellIndex].style.width = w;
				if(typeof(Y) != "undefined")
					clearTimeout(Y);
				if (B.rows.length < 50) //防止排序有Bug
					Y = setTimeout("ChangWidthx("+ CellIndex +","+w+")" , 100);
				else
					Y = setTimeout("ChangWidthx("+ CellIndex +","+w+")" , 800);
			}
			HeadScroll();
			}
		document.onmouseup = function ()
			{
			if (e == undefined)
				return;
			e.releaseCapture();
			e = undefined;
			}
		}
	else
		{
		return;
		}
	}
function ChangWidthx(CellIndex,w)
	{
	var B = document.getElementById("t1");//MyBodyTab
	B.rows(0).cells[CellIndex].style.width = w;
	HeadScroll();
	}
function ChangCursor()
	{
	var e = event.srcElement;
	if (e.tagName != "TD")
		return;

	var x = event.x + document.body.scrollLeft; //此值在固定表头时要更改getElementById("topdiv")
	var l = e.offsetLeft;
	var l=l + e.offsetWidth + addleft;
	if (x >= l)
	{
		e.style.cursor = "e-resize";
	}
	else
		e.style.cursor = "default";
	}
	
//*********************************************************************************

//************************拖动表左行宽******************************************
function LeftScroll()
	{
	document.getElementById("leftdiv").scrollTop = document.getElementById("rightdiv").scrollTop;//THead,TBody
	}
function ChangHeight()
	{
	var e = event.srcElement;
	if (e == undefined)
		return;
	if (e.tagName != "TD")
		return;
	var L = document.getElementById("lefttable");//MyHeadTab
	var B = document.getElementById("t1");//MyBodyTab
	var CellIndex;
	for (var  i = 0; i < L.rows.length; i++)
		if (L.rows(i).cells[0] == e)//获得事件行
			{
			CellIndex = i;
			break;
			}
	CellIndex = i;
	var l = e.offsetTop+addtop;//上一行到顶部的距离
	if (e.style.cursor == "n-resize") //是改变行宽
		{
		e.setCapture();
		document.onmousemove = function ()
			{
			if (e == undefined)
				return;
			e.style.cursor = "n-resize";
			var w = event.y + document.body.scrollTop - l;//getElementById("topdiv")
			if (w >= 5)
				{
				e.style.height = w;//设置左边的高度
				if (B.rows.length < 1)
					return;
				B.rows(CellIndex).cells[0].style.height = w;
			}
			HeadScroll();
			}
		document.onmouseup = function ()
			{
			if (e == undefined)
				return;
			e.releaseCapture();
			e = undefined;
			}
		}
	else
		{
		return;
		}
	}
function ChangHeighty(CellIndex,w)
	{
	var B = document.getElementById("t1");//MyBodyTab
	B.rows(CellIndex).cells[0].style.height = w;
	LeftScroll();
	}
function ChangHCursor()
	{
	var e = event.srcElement;
	if (e.tagName != "TD")
	{		
		return;	
	}
	var y = event.y + document.body.scrollTop; //此值在固定左表行时要更改getElementById("leftdiv")
	var l = e.offsetTop;
	var l=l + e.offsetHeight + addtop;
	if (y >= l)
	{
		e.style.cursor = "n-resize";
	}
	else
		e.style.cursor = "default";
	}
//屏蔽右键菜单
if (document.all && window.print) 
	{ 
		document.oncontextmenu = function() {return false;};
	}	
//*********************************************************************************
//-->
</script>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -