123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /**
- * 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, GC.Spread.Sheets.SheetArea.viewport);
- 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);
- });
- },
- loadSheetData: function (setting, sheet, datas) {
- var option = {
- allowSelectLockedCells: true,
- allowSelectUnlockedCells: true,
- allowResizeRows: true,
- allowResizeColumns: false
- };
- var getStyle = 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;
- return style;
- };
- sheet.options.protectionOptions = option;
- sheet.options.isProtected = true;
- sheet.setRowCount(datas.length + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
- setting.cols.forEach(function (colSetting, iCol) {
- var i, style = getStyle(colSetting);
- datas.forEach(function (data, iRow) {
- var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
- cell.value(data[colSetting.data.field]);//.font(colSetting.data.font).hAlign(colSetting.data.hAling).vAlign(colSetting.data.vAlign);
- sheet.setStyle(iRow, iCol, style);
- });
- for (i = 0; i < setting.emptyRows; i++) {
- sheet.setStyle(datas.length + i, iCol, style);
- }
- });
- }
- };
|