- function copydata() {
- var spread1 = document.getElementById("<%=FpSpread1.ClientID %>");
- var rg = spread1.GetSelectedRange();
- if (rg.rowCount == 0 || rg.colCount == 0)
- return;
- // alert("selected " + rg.type + ", " + rg.row + ", " + rg.col + ", " + rg.rowCount + ", " + rg.colCount);
- var cht = spread1.all("<%=FpSpread1.ClientID %>" + "_cht");
- var rh = spread1.all("<%=FpSpread1.ClientID %>" + "_rh");
- var sc = spread1.all("<%=FpSpread1.ClientID %>" + "_viewport");
- var corn = spread1.all("<%=FpSpread1.ClientID %>" + "_ctl01");
- var rs = rg.row; //start row
- var re = rg.row + rg.rowCount - 1; //end row
- var cs = rg.col; //start col
- var ce = rg.col + rg.colCount - 1; //end col
- var rowArray = new Array(); // 列数组
- var rhc = rh.rows[0].cells.length; //行头数
- var chc = cht.rows.length; //列头数
- //按照行来填充数组
- //step1 填充行头
- for (r = 0; r < chc; r++) {
- rowArray[r] = new Array();
- for (c = 0; c < rhc + ce - cs + 1; c++) {
- if (c < rhc) {
- rowArray[r][c] = corn.rows[r].cells[c].innerText; //填充corn
- }
- else {
- rowArray[r][c] = cht.rows[r].cells[cs + c - 1].innerText; //填充行头
- }
- }
- }
- //step2填充数据
- for (r = chc; r < chc + re - rs + 1; r++) {
- rowArray[r] = new Array();
- for (c = 0; c < rhc + ce - cs + 1; c++) {
- if (c < rhc) {
- rowArray[r][c] = rh.rows[rs + r - chc].cells[c].innerText; //填充列头
- }
- else {
- rowArray[r][c] = sc.rows[rs + r - chc].cells[c + cs - rhc].innerText; //填充数据
- }
- }
- }
- //输出
- var result = "";
- for (r = 0; r < rowArray.length; r++) {
- for (c = 0; c < rowArray[r].length; c++) {
- result = result.concat(rowArray[r][c]);
- result = result.concat("\t");
- }
- result = result.concat("\r\n");
- }
- window.clipboardData.setData("Text", result);
- // return result;
- }
复制代码 |