123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /**
- * 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 = {
- createNewSpread: function (obj) {
- var spread = new GC.Spread.Sheets.Workbook(obj, {sheetCount: 1});
- spread.options.tabStripVisible = false;
- spread.options.scrollbarMaxAlign = true;
- spread.options.cutCopyIndicatorVisible = false;
- spread.options.allowCopyPasteExcelStyle = false;
- spread.getActiveSheet().setRowCount(3);
- return spread;
- },
- 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.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- 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));
- });
- }
- };
|