123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- /**
- * Created by Tony on 2018/9/10.
- */
- let visualJumbo = {
- tplWorkBook: null,
- iniSpreadJs: function () {
- let me = this;
- /*/
- if (me.tplWorkBook === null) {
- me.tplWorkBook = new GC.Spread.Sheets.Workbook($('#ele_visual_div_main3')[0], {sheetCount: 1});
- me.tplWorkBook.options.tabStripVisible = false;
- me.tplWorkBook.options.allowCopyPasteExcelStyle = false;
- me.tplWorkBook.options.allowUserDragDrop = false;
- me.tplWorkBook.options.allowContextMenu = false;
- let sheet = me.tplWorkBook.getActiveSheet();
- sheet.options.allowCellOverflow = false;
- sheet.setRowCount(10, GC.Spread.Sheets.SheetArea.viewport);
- // sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onCellEnter);
- }
- /*/
- if (me.tplWorkBook !== null) {
- me.tplWorkBook.destroy();
- me.tplWorkBook = null;
- }
- me.tplWorkBook = new GC.Spread.Sheets.Workbook($('#ele_visual_div_main3')[0], {sheetCount: 1});
- me.tplWorkBook.options.tabStripVisible = false;
- me.tplWorkBook.options.allowCopyPasteExcelStyle = false;
- me.tplWorkBook.options.allowUserDragDrop = false;
- me.tplWorkBook.options.allowContextMenu = false;
- let sheet = me.tplWorkBook.getActiveSheet();
- sheet.options.allowCellOverflow = false;
- sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
- // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellEnter);
- //*/
- },
- setupTpl: function () {
- let me = this;
- let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- if (rptTpl && me.tplWorkBook) {
- let sheet = me.tplWorkBook.getActiveSheet();
- let border = new GC.Spread.Sheets.LineBorder;
- border.color = "Black";
- border.style = GC.Spread.Sheets.LineStyle.thin;
- sheet.suspendPaint();
- sheet.setRowCount(0);
- sheet.setColumnCount(0);
- //1. put the pos into array
- let xPos = [0], yPos = [0];
- let pageH, pageW;
- let bandMappingObj = {};
- let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
- pageW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
- pageH = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM])) /2.54*96 );
- if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
- pageW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
- pageH = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM])) /2.54*96 );
- }
- xPos.push(pageW);
- // pageH = Math.round(pageH / 2);
- yPos.push(pageH);
- visualCommonOprObj.addBandPos(rptTpl, pageW, pageH, xPos, yPos, bandMappingObj);
- visualCommonOprObj.addTplTxtFldPos(rptTpl, dataInfoMapTreeOprObj.treeObj, xPos, yPos, bandMappingObj);
- //2. 设置spreadjs
- xPos.sort(function(x1, x2){ return (x1 - x2); });
- yPos.sort(function(y1, y2){ return (y1 - y2); });
- sheet.setRowCount(yPos.length - 1);
- sheet.setColumnCount(xPos.length - 1);
- for (let idx = 1; idx < xPos.length; idx++) {
- sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
- }
- for (let idx = 1; idx < yPos.length; idx++) {
- sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
- sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
- }
- visualCommonOprObj.brushSheet(bandMappingObj, sheet, xPos, yPos);
- visualCommonOprObj.setupTplTxtFld(rptTpl, dataInfoMapTreeOprObj.treeObj, sheet, xPos, yPos, bandMappingObj)
- for (let idx = 1; idx < yPos.length; idx++) {
- let bkc = sheet.getCell(idx - 1, 0).backColor();
- if (bkc === 'White') {
- sheet.setRowHeight(idx - 1, 30);
- }
- }
- for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
- for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
- let cell = sheet.getCell(iRow, iCol);
- if (cell.backColor() === 'LightGray' || cell.backColor() === 'LightCyan') {
- visualCommonOprObj.setupBorder(sheet.getCell(iRow, iCol), border);
- }
- }
- }
- sheet.clearSelection();
- sheet.resumePaint();
- }
- },
- restoreTpl: function () {
- let me = visualJumbo;
- if (me.tplWorkBook) {
- me.setupTpl();
- }
- },
- private_AddCols: function (sheet, col) {
- sheet.suspendPaint();
- sheet.addColumns(col, 1);
- sheet.resumePaint();
- },
- insertColumn: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- if (selectedRanges.length > 0) {
- me.private_AddCols(sheet, selectedRanges[0].col);
- }
- },
- addColumn: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- me.private_AddCols(sheet, sheet.getColumnCount());
- },
- deleteColumn: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- let cc = sheet.getColumnCount();
- if (cc > 1) {
- if (selectedRanges.length > 0) {
- sheet.deleteColumns(selectedRanges[0].col, 1);
- }
- } else {
- alert('不能删除列!');
- }
- },
- addRow: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- if (selectedRanges.length > 0) {
- let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
- let color = cell.backColor();
- if (color !== 'White') {
- let nextIdx = sheet.getRowCount();
- for (let idx = selectedRanges[0].row + 1; idx < sheet.getRowCount(); idx++) {
- if (sheet.getCell(idx, selectedRanges[0].col).backColor() !== color) {
- nextIdx = idx;
- break;
- }
- }
- sheet.suspendPaint();
- sheet.addRows(nextIdx, 1);
- sheet.getRange(nextIdx, -1, 1, -1).backColor(color);
- sheet.resumePaint();
- }
- }
- },
- deleteRow: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- if (selectedRanges.length > 0) {
- let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
- let color = cell.backColor();
- if (color !== 'White') {
- let amt = 0;
- for (let idx = 0; idx < sheet.getRowCount(); idx++) {
- if (sheet.getCell(idx, selectedRanges[0].col).backColor() === color) {
- amt++
- }
- }
- if (amt > 1) {
- sheet.suspendPaint();
- sheet.deleteRows(selectedRanges[0].row, 1);
- sheet.resumePaint();
- }
- }
- }
- },
- fitTheWidth: function (factor) {
- let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
- let bandW = 700;
- if (pIdx >= 0) {
- bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
- if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
- bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
- }
- }
- bandW *= factor;
- let currentWidth = 0;
- let sheet = me.tplWorkBook.getActiveSheet();
- for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
- currentWidth += sheet.getColumnWidth(idx);
- }
- let actFactor = bandW / currentWidth;
- for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
- sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
- }
- },
- mergeCells: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- if (selectedRanges.length > 0) {
- let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
- let color = cell.backColor();
- let isDifferent = false;
- for (let idx = 1; idx < selectedRanges[0].rowCount; idx++) {
- if (sheet.getCell(selectedRanges[0].row + idx, 0).backColor() !== color) {
- isDifferent = true;
- break;
- }
- }
- if (!isDifferent) {
- sheet.suspendPaint();
- sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
- sheet.resumePaint();
- } else {
- alert(`不能合并跨界单元格!`)
- }
- }
- },
- disMergeCells: function () {
- let me = visualJumbo,
- sheet = me.tplWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- let spans = sheet.getSpans();
- if (selectedRanges.length > 0 && spans.length > 0) {
- let selectedSpans = [];
- for(let i = 0; i < spans.length; i++)
- {
- for (let j = 0; j < selectedRanges.length; j++) {
- if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
- spans[i].row < selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col < selectedRanges[j].col + selectedRanges[j].colCount) {
- selectedSpans.push(spans[i]);
- }
- }
- }
- for (let span of selectedSpans) {
- sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
- }
- }
- }
- };
|