|
@@ -1,12 +1,13 @@
|
|
|
/**
|
|
|
* Created by Mai on 2017/3/13.
|
|
|
*/
|
|
|
-// settingʾÀý
|
|
|
+// setting示例
|
|
|
var __settingTemp = {
|
|
|
cols: [
|
|
|
{
|
|
|
+ id: 'code',
|
|
|
head: {
|
|
|
- titleNames: ['񅧏'],
|
|
|
+ titleNames: ['编�'],
|
|
|
spanCols:[1],
|
|
|
spanRows:[1],
|
|
|
vAlign: [1],
|
|
@@ -19,7 +20,8 @@ var __settingTemp = {
|
|
|
hAlign: 0,
|
|
|
font: '4px Arial'
|
|
|
},
|
|
|
- width: 60
|
|
|
+ width: 60,
|
|
|
+ readOnly: false
|
|
|
}
|
|
|
],
|
|
|
headRows: 1,
|
|
@@ -29,7 +31,7 @@ var __settingTemp = {
|
|
|
|
|
|
var SheetDataHelper = {
|
|
|
loadSheetHeader: function (setting, sheet) {
|
|
|
- sheet.setColumnCount (setting.cols.length, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ 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);
|
|
@@ -39,8 +41,7 @@ var SheetDataHelper = {
|
|
|
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]);
|
|
|
+ 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);
|
|
@@ -51,13 +52,36 @@ var SheetDataHelper = {
|
|
|
});
|
|
|
},
|
|
|
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);
|
|
|
- datas.forEach(function (data, iData) {
|
|
|
- setting.cols.forEach(function (colSetting, iCol) {
|
|
|
- var cell = sheet.getCell(iData, iCol, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
- cell.value(data[colSetting.data.field])
|
|
|
- .font(colSetting.data.font).hAlign(colSetting.data.hAlign).vAlign(colSetting.data.vAlign);
|
|
|
- })
|
|
|
+ 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);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
};
|