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

📄 bs_spreadsheet.class.js

📁 在线电子表格SpreadSheet 在线电子表格SpreadSheet
💻 JS
📖 第 1 页 / 共 3 页
字号:
this.getNumRows = function() {try {return this._data.length;} catch (e) {return 0;}}this.getNumCols = function() {return bs_array_maxSizeOfLevel(this._data, 2);}this.calculateCellWidth = function() {var numCols = this.getNumCols();if (typeof(this._cellWidth) == 'undefined') {this._cellWidth = new Array();}for (var i=0; i<numCols; i++) {if (typeof(this._cellWidth[i]) != 'undefined') continue;var t = document.getElementById('col_autonumber_' + (i+1));if (t != null) {this._cellWidth[i] = t.width;} else {this._cellWidth[i] = this.defaultCellWidth;}}}this.calculateCellHeight = function() {var numRows = this.getNumRows();if (typeof(this._cellHeight) == 'undefined') {this._cellHeight = new Array();}for (var i=0; i<numRows; i++) {if (typeof(this._cellHeight[i]) != 'undefined') continue;var t = document.getElementById('row_autonumber_' + (i+1));if (t != null) {this._cellHeight[i] = t.height;} else {this._cellHeight[i] = this.defaultCellHeight;}}}this.calculateCellSizes = function() {var numCols = this.getNumCols();var numRows = this.getNumRows();this._cellWidth  = new Array();this._cellHeight = new Array();var width  = this.defaultCellWidth;var height = this.defaultCellHeight;for (var i=0; i<numCols; i++) {for (var j=0; j<numRows; j++) {var cell = document.getElementById('data[' + i + '][' + j + ']');if (cell) {width  = cell.clientWidth;height = cell.clientHeight;}if ((!this._cellWidth[i]) || (width > this._cellWidth[i])) {this._cellWidth[i] = width;}if ((!this._cellHeight[j]) || (height > this._cellHeight[j])) {this._cellHeight[j] = height;}}}}this.emptyValue = function(row, col) {this.setValue('', row, col);}this.setValue = function(val, row, col, noRedraw) {if (this._data.length <= row) {for (var i=this._data.length; i<=row; i++) {this.addRow(null, noRedraw);}}if (this._data[0].length <= col) {for (var i=this._data[0].length; i<=col; i++) {this.addCol(null, noRedraw);}}this._data[row][col]['value'] = val;var cell = document.getElementById('data[' + row + '][' + col + ']');if (cell) {cell.innerHTML = val;this.editCellEnd(cell);this.cellSelect(cell);}this.updateDataFromFields();if (!noRedraw) this.draw();}this.formatBold = function(val) {try {if (!this._currentCell) throw 'noCellSelected';var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);if (this._setStyle(row, col, 'bold', val)) {var cell = document.getElementById('data[' + row + '][' + col + ']');val = (val) ? 'bold' : 'normal';if (cell) cell.style.fontWeight = val;}} catch (e) {alert(e);}}this.formatItalic = function(val) {try {if (!this._currentCell) throw 'noCellSelected';var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);if (this._setStyle(row, col, 'italic', val)) {var cell = document.getElementById('data[' + row + '][' + col + ']');val = (val) ? 'italic' : 'normal';if (cell) cell.style.fontStyle = val;}} catch (e) {alert(e);}}this.formatUnderline = function(val) {try {if (!this._currentCell) throw 'noCellSelected';var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);if (this._setStyle(row, col, 'underline', val)) {var cell = document.getElementById('data[' + row + '][' + col + ']');val = (val) ? 'underline' : 'none';if (cell) cell.style.textDecoration = val;}} catch (e) {alert(e);}}this.formatAlign = function(left, center, right) {var val = '';if (left) {val = 'left';} else if (center) {val = 'center';} else if (right) {val = 'right';}try {if (!this._currentCell) throw 'noCellSelected';var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);if (this._setStyle(row, col, 'align', val)) {if (val != '') {var cell = document.getElementById('data[' + row + '][' + col + ']');if (cell) cell.style.textAlign = val;}}} catch (e) {alert(e);}}this._setStyle = function(row, col, style, val) {this._data[row][col][style] = val;return true;}this._updateStyleButtons = function() {var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);var valBold      = false;var valItalic    = false;var valUnderline = false;var valAlign     = '';try {if (this._data[row][col]) {valBold      = (this._data[row][col]['bold']);valItalic    = (this._data[row][col]['italic']);valUnderline = (this._data[row][col]['underline']);valAlign     = (this._data[row][col]['align']);}} catch (e) {}try {btnBold.setStatus(valBold ? 2 : 1);btnItalic.setStatus(valItalic ? 2 : 1);btnUnderline.setStatus(valUnderline ? 2 : 1);} catch (e) {}try {btnAlignLeft.setStatus((valAlign   == 'left')   ? 2 : 1);btnAlignCenter.setStatus((valAlign == 'center') ? 2 : 1);btnAlignLeft.setStatus((valAlign   == 'right')  ? 2 : 1);} catch (e) {}}this.sortAsc = function() {if (this._currentCell) {var colNumber = this.getCol(this._currentCell.id);this._sortData(colNumber, true);this.draw();}}this.sortDesc = function() {if (this._currentCell) {var colNumber = this.getCol(this._currentCell.id);this._sortData(colNumber, false);this.draw();}}this._sortData = function(colNumber, asc) {this.updateDataFromFields();var tmpArray = new Array();var dataLength = this.getNumRows();var subLength  = this.getNumCols();for (var i=0; i<dataLength; i++) {tmpArray[i] = this._data[i][colNumber]['value'] + '[?!*]' + i;}tmpArray.sort();var tmpArrayRank = new Array();for (var i=0; i<dataLength; i++) {pos = tmpArray[i].lastIndexOf('[?!*]') + 5;tmpArrayRank[i] = tmpArray[i].substr(pos);}if (!asc) tmpArrayRank.reverse();var tmpData = this._data;this._data = new Array();for (var i=0; i<dataLength; i++) {this._data[i] = Array();for (var j=0; j<subLength; j++) {this._data[i][j] = tmpData[tmpArrayRank[i]][j];}}}this.toHtml = function(withStyle) {if (this.debug) alert("exporting table to html");this.updateDataFromFields();var numCols = this.getNumCols();var out = "<table>\n";for (var i=0; i<this._data.length; i++) {out += "  <tr>\n";for (var j=0; j<numCols; j++) {var cellValue = this._data[i][j]['data'];var formatStyle = this._getStyleStringForCell(i, j);out += '    <td style="' + formatStyle + '">' + cellValue + '</td>\n';}out += "  </tr>\n";}return out;}this._readFromClipboard = function(key) {if (window.clipboardData) {return window.clipboardData.getData(key);} else {netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);if (!clip) return;var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);if (!trans) return;trans.addDataFlavor('text/unicode');clip.getData(trans,clip.kGlobalClipboard);var str = new Object();var len = new Object();try { trans.getTransferData('text/unicode',str,len); }catch(error) { return; }if (str) {if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString);else str = null;}if (str) return(str.data.substring(0,len.value / 2));}}}function editorStart(i, j) {divEditor.style.display = 'block';formField = document.getElementById('data[' + i + '][' + j + ']');txtEditor = document.getElementById('txtEditor');txtEditor.value = formField.value;editorI = i;editorJ = j;}function editorSave() {formField = document.getElementById('data[' + editorI + '][' + editorJ + ']');txtEditor = document.getElementById('txtEditor');formField.value = txtEditor.value;txtEditor.value = '';divEditor.style.display = 'none';}function editorCancel() {txtEditor.value = '';divEditor.style.display = 'none';}

⌨️ 快捷键说明

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