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

📄 bs_spreadsheet.class.js

📁 在线电子表格SpreadSheet 在线电子表格SpreadSheet
💻 JS
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************************* BlueShoes Framework; This file is part of the php application framework.* NOTE: This code is stripped (obfuscated). To get the clean documented code goto *       www.blueshoes.org and register for the free open source *DEVELOPER* version or *       buy the commercial version.*       *       In case you've already got the developer version, then this is one of the few *       packages/classes that is only available to *PAYING* customers.*       To get it go to www.blueshoes.org and buy a commercial version.* * @copyright www.blueshoes.org* @author    Samuel Blume <sam at blueshoes dot org>* @author    Andrej Arn <andrej at blueshoes dot org>*/function bs_ss_pageLoaded() {mySpreadSheet = new Bs_SpreadSheet;try {if (opener) parent = opener;parent.bs_ss_init();} catch (e) {}}function Bs_SpreadSheet() {this.objectName;this.debug = false;this.showLineNumbers = true;this.firstRowTitle = false;this.firstColTitle = false;this.useToolbar = true;this.mayUseClipboard = true;this.mayUseFormat = true;this.mayUseAlign = true;this.mayUseWysiwyg = true;this._drawStyle = 'hidden';this.numCols = 6;this.numRows = 10;this._data;this._callbackFunction;this.returnType = 'array';this._currentCell;this._currentState;this._currentCellLastValue;this.defaultCellWidth = 80;this._cellWidth;this.defaultCellHeight = 20;this._cellHeight;this.sheetWidth  = 450;this.sheedHeight = 230;this.editorI;this.editorJ;this._drawTagId;this.buttonsPath = '/_bsImages/buttons/';this.setMousePointer = function(work) {var body = document.getElementById('body');if (body) {if (work) {body.style.cursor = 'hand';} else {body.style.cursor = 'hand';}}}this._getNewCell = function() {var ret = new Array();ret['value']     = '';ret['bold']      = false;ret['italic']    = false;ret['underline'] = false;ret['align']     = '';return ret;}this.addCol = function(pos, noRedraw) {try {if (typeof(pos) == 'boolean') {if (pos == false) {pos = this.getCol(this._currentCell.id) +1;} else {pos = this.getCol(this._currentCell.id);}} else if ((pos == null) || (typeof(pos) == 'undefined')) {pos = this._data[0].length +1;}if (this.debug) alert("insert col at position " + pos);this.updateDataFromFields();var t = new Array();for (var i=0; i<this._cellWidth.length; i++) {if (pos == i) {t.push(this.defaultCellWidth);}t.push(this._cellWidth[i]);}this._cellWidth = t;for (var i=0; i<this._data.length; i++) {var numCols = this._data[i].length;var t = null;t = new Array();var doneAdd = false;for (var j=0; j<numCols; j++) {if (pos == j) {t.push(this._getNewCell());doneAdd = true;}t.push(this._data[i][j]);}if (!doneAdd) {t.push(this._getNewCell());}this._data[i] = t;}if (!noRedraw) this.draw();} catch (e) {}}this.addRow = function(pos, noRedraw) {try {if (typeof(pos) == 'boolean') {if (pos == false) {pos = this.getRow(this._currentCell.id) +1;} else {pos = this.getRow(this._currentCell.id);}} else if ((pos == null) || (typeof(pos) == 'undefined')) {pos = this._data.length +1;}if (this.debug) alert("insert row at position " + pos);this.updateDataFromFields();var t = new Array();for (var i=0; i<this._cellHeight.length; i++) {if (pos == i) {t.push(this.defaultCellHeight);}t.push(this._cellHeight[i]);}this._cellHeight = t;var doneAdd = false;var t = new Array();for (var i=0; i<this._data.length; i++) {if (pos == i) {var tt = new Array;for (var j=0; j<this._data[i].length; j++) {tt[j] = this._getNewCell();}t.push(tt);doneAdd = true;}t.push(this._data[i]);}if (!doneAdd) {var maxCols = bs_array_maxSizeOfLevel(this._data, 2);var tt = new Array;for (var j=0; j<maxCols; j++) {tt[j] = this._getNewCell();}t.push(tt);}this._data = t;if (!noRedraw) this.draw();} catch (e) {}}this.removeCol = function(pos) {if (isNaN(pos)) {pos = this.getCol(this._currentCell.id);}if (this.debug) alert("remove col at position " + pos);this.updateDataFromFields();var t = new Array();for (var i=0; i<this._cellWidth.length; i++) {if (pos == i) continue;t.push(this._cellWidth[i]);}this._cellWidth = t;for (var i=0; i<this._data.length; i++) {var t = new Array();for (var j=0; j<this._data[i].length; j++) {if (pos == j) continue;t.push(this._data[i][j]);}this._data[i] = t;}this.draw();}this.removeRow = function(pos) {if (isNaN(pos)) {pos = this.getRow(this._currentCell.id);}if (this.debug) alert("remove row at position " + pos);this.updateDataFromFields();var t = new Array();for (var i=0; i<this._cellHeight.length; i++) {if (pos == i) continue;t.push(this._cellHeight[i]);}this._cellHeight = t;var t = new Array();for (var i=0; i<this._data.length; i++) {if (pos == i) continue;t.push(this._data[i]);}this._data = t;this.draw();}this.init = function(data, drawTagId, callbackFunction) {this._importData(data);this._drawTagId = drawTagId;if (callbackFunction != null) this._callbackFunction = callbackFunction;this.draw();}this._importData = function(data) {var maxCols = bs_array_maxSizeOfLevel(data, 2);if (this.numCols > maxCols) maxCols = this.numCols;var numRows = data.length;if (this.numRows > numRows) numRows = this.numRows;for (var i=0; i<numRows; i++) {for (var j=0; j<maxCols; j++) {if (typeof(data[i]) == 'undefined') data[i] = new Array;try {if (typeof(data[i][j]) != 'object') {var tmpVal = data[i][j];} else {var tmpVal = '';}} catch (e) {var tmpVal = '';}data[i][j] = new Object;data[i][j]['value']     = tmpVal;data[i][j]["bold"]      = false;data[i][j]['italic']    = false;data[i][j]['underline'] = false;data[i][j]['align']     = '';}}this._data = data;}this.exportDataToCsv = function() {var clean = new Array;for (var i=0; i<this._data.length; i++) {clean[i] = new Array;for (var j=0; j<this._data[i].length; j++) {clean[i][j] = this._data[i][j]['value'];}}return bs_array_toCsv(this._data, ';');}this._exportData = function() {}this.draw = function() {var containerElm    = document.getElementById(this._drawTagId);var containerWidth  = parseInt(containerElm.currentStyle.width);var containerHeight = parseInt(containerElm.currentStyle.height);var containerPos    = getAbsolutePos(containerElm, true);var layout = '';if (moz) {layout += '<div id="bs_ss_pasteLayerDiv" style="z-index:15; display:none; position:absolute; background-color:#D6D3CE; padding:5px; border:1px solid black;">';layout += '<textarea name="bs_ss_pasteLayerTxt" id="bs_ss_pasteLayerTxt" cols="30" rows="4"></textarea><br>';layout += '<input type="button" name="bs_ss_pasteLayerOk" value="OK" onclick="' + this.objectName + '.pasteValue(document.getElementById(\'bs_ss_pasteLayerTxt\').value); document.getElementById(\'bs_ss_pasteLayerTxt\').value = \'\'; document.getElementById(\'bs_ss_pasteLayerDiv\').style.display = \'none\';"> ';layout += '<input type="button" name="bs_ss_pasteLayerCancel" value="Cancel" onclick="document.getElementById(\'bs_ss_pasteLayerTxt\').value = \'\'; document.getElementById(\'bs_ss_pasteLayerDiv\').style.display = \'none\';">';layout += '</div>';}layout    += '<div id="' + this.objectName + '_toolbarDiv" style="width:100%;"></div>';layout    += '<div id="' + this.objectName + '_formulaDiv" style="width:100%; background-color:#D6D3CE; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#404040;">';layout    += '<div style="position:absolute; left:' + (containerPos.x + 8) + 'px;">Field: <span id="' + this.objectName + '_fieldSpan" style="color:#000000;"></span></div>';layout    += '<div style="position:relative; left:80px;">Value: ';layout    += '<div id="' + this.objectName + '_valueSpan" style="position:absolute; width:' + (containerWidth -120) + 'px; color:#000000; background-color:#D6D3CE;"></div>';layout    += '</div>';layout    += '</div>';if ((containerElm.currentStyle.overflow == 'auto') || (containerElm.currentStyle.overflow == 'scroll')) {var sheetDivOverflow = 'visible';var sheetDivHeight   = '100%';} else {var sheetDivOverflow = 'auto';var sheetDivHeight   = (containerHeight -38) + 'px';}layout    += '<div id="' + this.objectName + '_spreadSheetDiv" style="width:100%; height:' + sheetDivHeight + '; overflow:' + sheetDivOverflow + ';"></div>';document.getElementById(this._drawTagId).innerHTML = layout;if (this.useToolbar) this._loadToolbar();if ((this._currentCell) && (this._currentState == 'active')) {var reactivateCurrentCell = this._currentCell.id;}var fullTableWidth = 30;this.calculateCellWidth();this.calculateCellHeight();var numCols = this.getNumCols();if (this.debug) alert("building table with " + numCols + " cols and " + this._data.length + " rows.");var titleRow = new Array;titleRow[titleRow.length] = '<tr>';titleRow[titleRow.length] = '<td width="25" bgcolor="#DEDBD6" style="border-bottom-color: Black; border-bottom-style: solid; border-bottom-width: 1px; border-right-color: Black; border-right-style: solid; border-right-width: 1px;">&nbsp;</td>';for (var i=0; i<numCols; i++) {var tdId = 'col_autonumber_' + (i+1);titleRow[titleRow.length] = '<td id="' + tdId + '" width="' + this._cellWidth[i] + '" bgcolor="#DEDBD6" align="middle" style="border-bottom-color: Black; border-bottom-style: solid; border-bottom-width: 1px; border-right-color: Black; border-right-style: solid; border-right-width: 1px;">';titleRow[titleRow.length] = '<table width="100%" height="100%" cellpadding="0" cellspacing="0"><tr><td align="middle" id="' + tdId + '_hack">';titleRow[titleRow.length] = String.fromCharCode(65 +i);titleRow[titleRow.length] = '</td><td align="right" width="3">';titleRow[titleRow.length] = '<span style="cursor:col-resize;" ondragstart="resizeColStart(\'' + tdId + '\')" ondrag="resizeCol(\'' + tdId + '\')" ondragend="resizeColEnd(\'' + tdId + '\')"><img src="/_bsImages/spacer.gif" width="3" height="10"></span>';titleRow[titleRow.length] = '</td></tr></table>';titleRow[titleRow.length] = '</td>';}titleRow[titleRow.length] = '</tr>';var out = new Array;var addRowLine = '';for (var i=0; i<this._data.length; i++) {var lineNumber = i+1;var outLine = new Array;outLine[outLine.length] = '<tr>\n';var outWhile = new Array;var tdId = 'row_autonumber_' + lineNumber;outWhile[outWhile.length] = '<td id="' + tdId + '" width="25" height="' + this._cellHeight[i] + '"valign="bottom" align="right" bgcolor="#DEDBD6" style="border-bottom-color: Black; border-bottom-style: solid; border-bottom-width: 1px;">';outWhile[outWhile.length] = '<table width="100%" height="100%" cellpadding="0" cellspacing="0"><tr><td valign="bottom" align="right" id="' + tdId + '_hack">';outWhile[outWhile.length] = lineNumber + '&nbsp;';outWhile[outWhile.length] = '</td></tr><tr height="3"><td align="middle" valign="bottom" height="3">';outWhile[outWhile.length] = '<span style="cursor:row-resize;" ondragstart="resizeRowStart(\'' + tdId + '\')" ondrag="resizeRow(\'' + tdId + '\')" ondragend="resizeRowEnd(\'' + tdId + '\')"><img src="/_bsImages/spacer.gif" width="10" height="3"></span>';outWhile[outWhile.length] = '</td></tr></table>';outWhile[outWhile.length] = '</td>';for (var j=0; j<numCols; j++) {var colNumber = j+1;try {var cellValue   = (this._data[i][j]['value']) ? this._data[i][j]['value'] : '';var formatStyle = this._getStyleStringForCell(i, j);} catch (e) {continue;}if (i==0) fullTableWidth += this._cellWidth[j] +1;outWhile[outWhile.length] = '<td id="td_data[' + i + '][' + j + ']" width=' + this._cellWidth[j] + ' height=' + this._cellHeight[i] + ' style="width:' + this._cellWidth[j] + '; height:' + this._cellHeight[i] + ';">';outWhile[outWhile.length] = '<div name="data[' + i + '][' + j + ']" id="data[' + i + '][' + j + ']" ';outWhile[outWhile.length] = 'onkeydown="return ' + this.objectName + '.typing();" ';outWhile[outWhile.length] = 'onclick="'    + this.objectName + '.cellSelect(this);" ';outWhile[outWhile.length] = 'ondblclick="' + this.objectName + '.editCellStart(this);" ';outWhile[outWhile.length] = 'onpaste="'    + this.objectName + '.onPaste(this);" ';outWhile[outWhile.length] = 'style="' + formatStyle + ' position:relative; left:0; top:0; width:100%; height:100%; background-color:white; overflow:hidden; z-index:60;">';outWhile[outWhile.length] = cellValue;outWhile[outWhile.length] = '</div>';outWhile[outWhile.length] = '</td>';}outLine[outLine.length] = outWhile.join('');outLine[outLine.length] = "</tr>\n";out[out.length] = outLine.join('');addRowLine = '';kSave = i;}var tableString = '<div style="z-index:50; width:' + this.sheetWidth + 'px; height:' + this.sheedHeight + 'px; overflow: visible;"><table width="' + fullTableWidth + '" id="dataTable" border="1" cellspacing="0" cellpadding="0" bordercolor="#DEDBD6" bgcolor="#FFFFFF">\n';tableString += titleRow.join('');tableString += out.join('');tableString += '</table></div>\n';document.getElementById(this.objectName + '_spreadSheetDiv').innerHTML = tableString;if (reactivateCurrentCell) {var cell = document.getElementById(reactivateCurrentCell);if (cell) {this.cellSelect(cell);}}}this._loadToolbar = function() {bar = new Bs_ButtonBar();bar.useHelpBar = false;btnAddRowAbove = new Bs_Button();btnAddRowAbove.objectName = 'btnAddRowAbove';btnAddRowAbove.title = 'Insert row above';btnAddRowAbove.imgName = 'bs_tblInsertRowAbove';btnAddRowAbove.imgPath = this.buttonsPath;btnAddRowAbove.attachEvent(function(){mySpreadSheet.addRow(true)});bar.addButton(btnAddRowAbove, 'Insert row above');btnAddRowBelow = new Bs_Button();btnAddRowBelow.objectName = 'btnAddRowBelow';btnAddRowBelow.title = 'Insert row below';btnAddRowBelow.imgName = 'bs_tblInsertRowBelow';btnAddRowBelow.imgPath = this.buttonsPath;btnAddRowBelow.attachEvent(function(){mySpreadSheet.addRow(false)});bar.addButton(btnAddRowBelow, 'Insert row below');btnRemoveRow = new Bs_Button();btnRemoveRow.objectName = 'btnRemoveRow';btnRemoveRow.title = 'Remove row';btnRemoveRow.imgName = 'bs_tblRemoveRow';btnRemoveRow.imgPath = this.buttonsPath;btnRemoveRow.attachEvent(function(){mySpreadSheet.removeRow()});bar.addButton(btnRemoveRow, 'Remove row');bar.newGroup();btnAddColLeft = new Bs_Button();btnAddColLeft.objectName = 'btnAddColLeft';btnAddColLeft.title = 'Insert col left';btnAddColLeft.imgName = 'bs_tblInsertColLeft';btnAddColLeft.imgPath = this.buttonsPath;btnAddColLeft.attachEvent(function(){mySpreadSheet.addCol(true)});bar.addButton(btnAddColLeft, 'Insert col left');btnAddColRight = new Bs_Button();btnAddColRight.objectName = 'btnAddColRight';btnAddColRight.title = 'Insert col right';btnAddColRight.imgName = 'bs_tblInsertColRight';btnAddColRight.imgPath = this.buttonsPath;btnAddColRight.attachEvent(function(){mySpreadSheet.addCol(false)});bar.addButton(btnAddColRight, 'Insert col right');btnRemoveCol = new Bs_Button();btnRemoveCol.objectName = 'btnRemoveCol';btnRemoveCol.title = 'Remove col';btnRemoveCol.imgName = 'bs_tblRemoveCol';btnRemoveCol.imgPath = this.buttonsPath;btnRemoveCol.attachEvent(function(){mySpreadSheet.removeCol()});bar.addButton(btnRemoveCol, 'Remove col');bar.newGroup();btnSortAsc = new Bs_Button();btnSortAsc.objectName = 'btnSortAsc';btnSortAsc.title = 'Sort Ascending';btnSortAsc.imgName = 'bs_sortAsc';btnSortAsc.imgPath = this.buttonsPath;btnSortAsc.attachEvent(function(){mySpreadSheet.sortAsc()});bar.addButton(btnSortAsc, 'Sort Ascending');btnSortDesc = new Bs_Button();btnSortDesc.objectName = 'btnSortDesc';btnSortDesc.title = 'Sort Descending';btnSortDesc.imgName = 'bs_sortDesc';btnSortDesc.imgPath = this.buttonsPath;btnSortDesc.attachEvent(function(){mySpreadSheet.sortDesc()});bar.addButton(btnSortDesc, 'Sort Descending');if (this.mayUseClipboard) {

⌨️ 快捷键说明

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