📄 bs_spreadsheet.class.js
字号:
bar.newGroup();btnPaste = new Bs_Button();btnPaste.objectName = 'btnPaste';btnPaste.title = 'Paste';btnPaste.imgName = 'bs_paste';btnPaste.imgPath = this.buttonsPath;btnPaste.attachEvent(function(){mySpreadSheet.onGlobalPaste()});bar.addButton(btnPaste, 'Paste the clipboard at the current position.');}if (this.mayUseFormat) {bar.newGroup();btnBold = new Bs_Button();btnBold.objectName = 'btnBold';btnBold.title = 'Bold';btnBold.imgName = 'bs_formatBold_en';btnBold.imgPath = this.buttonsPath;btnBold.group = 'bold';btnBold.attachEvent(function(){mySpreadSheet.formatBold(true)});bar.addButton(btnBold, 'Format the selected cell as bold.');btnItalic = new Bs_Button();btnItalic.objectName = 'btnItalic';btnItalic.title = 'Italic';btnItalic.imgName = 'bs_formatItalic_en';btnItalic.imgPath = this.buttonsPath;btnItalic.group = 'italic';btnItalic.attachEvent(function(){mySpreadSheet.formatItalic(true)});bar.addButton(btnItalic, 'Format the selected cell as italic.');btnUnderline = new Bs_Button();btnUnderline.objectName = 'btnUnderline';btnUnderline.title = 'Underline';btnUnderline.imgName = 'bs_formatUnderline';btnUnderline.imgPath = this.buttonsPath;btnUnderline.group = 'underline';btnUnderline.attachEvent(function(){mySpreadSheet.formatUnderline(true)});bar.addButton(btnUnderline, 'Format the selected cell as underlined.');}if (this.mayUseAlign) {bar.newGroup();btnAlignLeft = new Bs_Button();btnAlignLeft.objectName = 'btnAlignLeft';btnAlignLeft.title = 'Align left';btnAlignLeft.imgName = 'bs_alignLeft';btnAlignLeft.imgPath = this.buttonsPath;btnAlignLeft.group = 'align';btnAlignLeft.attachEvent(formatAlign);bar.addButton(btnAlignLeft, 'Align the selected cell to the left.');btnAlignCenter = new Bs_Button();btnAlignCenter.objectName = 'btnAlignCenter';btnAlignCenter.title = 'Align center';btnAlignCenter.imgName = 'bs_alignCenter';btnAlignCenter.imgPath = this.buttonsPath;btnAlignCenter.group = 'align';btnAlignCenter.attachEvent(formatAlign);bar.addButton(btnAlignCenter, 'Align the selected cell to the middle.');btnAlignRight = new Bs_Button();btnAlignRight.objectName = 'btnAlignRight';btnAlignRight.title = 'Align right';btnAlignRight.imgName = 'bs_alignRight';btnAlignRight.imgPath = this.buttonsPath;btnAlignRight.group = 'align';btnAlignRight.attachEvent(formatAlign);bar.addButton(btnAlignRight, 'Align the selected cell to the right.');}if (this.mayUseWysiwyg) {bar.newGroup();btnWysiwyg = new Bs_Button();btnWysiwyg.objectName = 'btnWysiwyg';btnWysiwyg.title = 'Wysiwyg Editor';btnWysiwyg.imgName = 'bs_webEdit';btnWysiwyg.imgPath = this.buttonsPath;btnWysiwyg.attachEvent(function(){startWysiwyg()});bar.addButton(btnWysiwyg, 'Open the editor to visually edit this cells content.');}bar.drawInto(this.objectName + '_toolbarDiv');}this._getStyleStringForCell = function(row, col) {var formatStyle = '';if (this._data[row][col]['bold']) {formatStyle += ' font-weight:bold;'}if (this._data[row][col]['italic']) {formatStyle += ' font-style:italic;'}if (this._data[row][col]['underline']) {formatStyle += ' text-decoration:underline;'}if ((this._data[row][col]['align']) && (this._data[row][col]['align'] != '')) {formatStyle += ' text-align:' + this._data[row][col]['align'] + ';';}return formatStyle;}this.updateDataFromFields = function() {}this.setDrawStyle = function(drawStyle) {this._drawStyle = drawStyle;this.updateDataFromFields();this.draw();}this.save = function() {if (this.returnType == 'csv') {var ret = bs_array_toCsv(this._data, ';');} else {var ret = this._data;}try {var evalStr = 'parent.' + this._callbackFunction + '(ret);';eval(evalStr);} catch (e) {try {var evalStr = this._callbackFunction + '(ret);';eval(evalStr);} catch (e) {alert("Could not call callback function.");}}}this.cellSelect = function(cell) {if (cell != this._currentCell) {this._cellDeactivate(this._currentCell);}this._currentCell = cell;this._currentState = 'active';this._cellActivate(cell);}this._cellActivate = function(cell) {var td = document.getElementById('td_' + cell.id);if (td) td.style.border = "2px solid Black";this._updateStyleButtons();var y = this.getCol(cell.id) +1;var x = this.getRow(cell.id) +1;var colTitle = document.getElementById('col_autonumber_' + y);if (colTitle) colTitle.bgColor = '#B5BED6';var rowTitle = document.getElementById('row_autonumber_' + x);if (rowTitle) rowTitle.bgColor = '#B5BED6';document.getElementById(this.objectName + '_fieldSpan').innerText = String.fromCharCode(64 +y) + '' + x;document.getElementById(this.objectName + '_valueSpan').innerText = cell.innerText;}this._cellDeactivate = function(cell) {if (cell) {if (this._currentState == 'edit') {this.editCellEnd(cell);}var td = document.getElementById('td_' + cell.id);if (td) td.style.border = "1px solid #DEDBD6";var colTitle = document.getElementById('col_autonumber_' + (this.getCol(cell.id) +1));if (colTitle) colTitle.bgColor = '#DEDBD6';var rowTitle = document.getElementById('row_autonumber_' + (this.getRow(cell.id) +1));if (rowTitle) rowTitle.bgColor = '#DEDBD6';}}this.editCellStart = function(cell) {if (cell != this._currentCell) {this.cellDeactivate(this._currentCell);}this._currentCell = cell;this._currentState = 'edit';this._currentCellLastValue = cell.innerHTML;if (ie) {cell.style.left = cell.offsetLeft;cell.style.top = cell.offsetTop;cell.style.position = "absolute";cell.style.overflow = "visible";cell.style.width = 500;cell.style.zIndex = 700;cell.contentEditable = true;cell.focus();} else {var newVal = window.prompt('Type in the new value', this._currentCellLastValue);if ((newVal == false) || (newVal == null)) return;cell.innerHTML = newVal;this.editCellEnd(cell);}}this.editCellEnd = function(cell) {var row = this.getRow(cell.id);var col = this.getCol(cell.id);this._data[row][col]['value'] = cell.innerHTML;cell.style.position = "relative";cell.style.overflow = "hidden";cell.style.left = 0;cell.style.top = 0;cell.style.width = this._cellWidth[this.getCol(cell.id)];cell.style.zIndex = 50;cell.contentEditable = false;this._currentState = 'active';document.getElementById(this.objectName + '_valueSpan').innerText = cell.innerText;}this.typing = function() {if (this._currentState == 'edit') {var goOn = false;switch (window.event.keyCode) {case 13:if (event.shiftKey) {return true;}this.editCellEnd(this._currentCell);return false;case 27:this._currentCell.innerHTML = this._currentCellLastValue;this.editCellEnd(this._currentCell);this.cellSelect(this._currentCell);return false;case 40:case 9:case 39:case 38:case 37:this.editCellEnd(this._currentCell);goOn = true;}if (!goOn) {return true;}}if (event.ctrlKey) {if (window.event.keyCode == 66) {this.formatBold(true);this._updateStyleButtons();return false;} else if (window.event.keyCode == 73) {this.formatItalic(true);this._updateStyleButtons();return false;} else if (window.event.keyCode == 85) {this.formatUnderline(true);this._updateStyleButtons();return false;} else if (window.event.keyCode == 86) {this.onGlobalPaste(this._currentCell);return false;}return true;}switch (window.event.keyCode) {case 13:case 40:var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);var t = document.getElementById('data[' + (row +1) + '][' + col + ']');if (t) {this.cellSelect(t);} else {t = document.getElementById('data[0][' + col + ']');this.cellSelect(t);}return false;case 9:case 39:var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);var t = document.getElementById('data[' + row + '][' + (col +1) + ']');if (t) {this.cellSelect(t);} else {if (window.event.keyCode == 9) {t = document.getElementById('data[' + (row +1) + '][0]');} else {t = document.getElementById('data[' + (row) + '][0]');}if (t) {this.cellSelect(t);} else {t = document.getElementById('data[0][0]');this.cellSelect(t);}}return false;case 38:case 13:var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);var t = document.getElementById('data[' + (row -1) + '][' + col + ']');if (t) {this.cellSelect(t);} else {t = document.getElementById('data[' + (this.getNumRows() -1) + '][' + col + ']');this.cellSelect(t);}return false;case 37:var row = this.getRow(this._currentCell.id);var col = this.getCol(this._currentCell.id);var t = document.getElementById('data[' + row + '][' + (col -1) + ']');if (t) {this.cellSelect(t);} else {t = document.getElementById('data[' + (row) + '][' + (this.getNumCols() -1) + ']');if (t) {this.cellSelect(t);} else {t = document.getElementById('data[' + (this.getNumRows() -1) + '][' + (this.getNumCols() -1) + ']');this.cellSelect(t);}}return false;case 113:this.editCellStart(this._currentCell);return true;default:if ((window.event.keyCode >= 32) && (window.event.keyCode <= 126)) {this.editCellStart(this._currentCell);this.removeContent(this._currentCell);return true;}}return false;}this.onPaste = function(cell) {event.returnValue = true;}this.onGlobalPaste = function(cell) {if (typeof(cell) == 'undefined') cell = this._currentCell;if (bs_isNull(cell)) {alert('Select a cell first!');return;}if (ie) {var clipValOrig = this._readFromClipboard("Text");this.pasteValue(clipValOrig, cell);} else {var layerDiv = document.getElementById('bs_ss_pasteLayerDiv');layerDiv.style.display = 'block';var pos = getAbsolutePos(document.getElementById(btnPaste._getId()), true);layerDiv.style.left = pos.x + 'px';layerDiv.style.top = pos.y + 20 + 'px';document.getElementById('bs_ss_pasteLayerTxt').focus();}}this.pasteValue = function(value, cell) {if (typeof(cell) == 'undefined') cell = this._currentCell;if ((value.indexOf("\t") >= 0) || (value.indexOf("\n") >= 0)) {var cvsUtil = new Bs_CsvUtil();var clipArr = cvsUtil.csvStringToArray(value, 'auto', false, false, false, true);var startRow = this.getRow(cell.id);var startCol = this.getCol(cell.id);for (var i=0; i<clipArr.length; i++) {for (var j=0; j<clipArr[i].length; j++) {this.setValue(clipArr[i][j], startRow +i, startCol +j, true);}}this.draw();} else {this.setValue(value, this.getRow(cell.id), this.getCol(cell.id));}}this.removeContent = function(cell) {cell.innerHTML = '';}this.getRow = function(cellName) {var posTwo = cellName.indexOf(']');return parseInt(cellName.substring(5, posTwo));}this.getCol = function(cellName) {var posTwo = cellName.lastIndexOf('[');return parseInt(cellName.substr(posTwo +1, cellName.length));}this.getCellCaption = function(cellId) {return String.fromCharCode(65 + this.getCol(cellId)) + (this.getRow(cellId) +1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -