/** * Created by Mai on 2017/3/13. */ // setting示例 var __settingTemp = { cols: [ { id: 'code', head: { titleNames: ['编号'], spanCols:[1], spanRows:[1], vAlign: [1], hAlign: [1], font: '4px Arial' }, data:{ field: 'code', vAlign: 1, hAlign: 0, font: '4px Arial' }, width: 60, readOnly: false } ], headRows: 1, headRowHeight: [25], emptyRows: 3 }; var SheetDataHelper = { loadSheetHeader: function (setting, sheet) { sheet.setColumnCount(setting.cols.length); sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader); setting.headRowHeight.forEach(function (rowHeight, index) { sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader); }) setting.cols.forEach(function (col, index) { var i, iRow = 0, cell; for (i = 0; i < col.head.spanCols.length; i++) { if (col.head.spanCols[i] !== 0) { cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader); cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]); } if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) { sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader); } iRow += col.head.spanRows[i]; }; sheet.setColumnWidth(index, col.width); }); }, protectdSheet: function (sheet) { var option = { allowSelectLockedCells: true, allowSelectUnlockedCells: true, allowResizeRows: true, allowResizeColumns: true }; sheet.options.protectionOptions = option; sheet.options.isProtected = true; }, getSheetCellStyle: function (setting) { var style = new GC.Spread.Sheets.Style(); style.locked = setting.readOnly; style.name = setting.id; style.font = setting.data.font; style.hAlign = setting.data.hAlign; style.vAlign = setting.data.vAlign; //style.wordWrap = setting.data.wordWrap; return style; }, loadSheetData: function (setting, sheet, datas) { SheetDataHelper.protectdSheet(sheet); sheet.suspendPaint(); sheet.suspendEvent(); sheet.setRowCount(datas.length + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport); setting.cols.forEach(function (colSetting, iCol) { sheet.setStyle(-1, iCol, SheetDataHelper.getSheetCellStyle(colSetting)); datas.forEach(function (data, iRow) { var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport); cell.value(data[colSetting.data.field]); }); }); sheet.resumeEvent(); sheet.resumePaint(); }, bindSheetData: function (setting, sheet, datas) { var getBindColInfo = function (setting) { var colInfo = {}; colInfo.name = setting.data.field; colInfo.size = setting.width; return colInfo; } SheetDataHelper.protectdSheet(sheet); sheet.autoGenerateColumns = false; sheet.setDataSource(datas); setting.cols.forEach(function (colSetting, iCol) { sheet.setStyle(-1, iCol, SheetDataHelper.getSheetCellStyle(colSetting)); sheet.bindColumn(iCol, getBindColInfo(colSetting)); }); } };