|
@@ -6,7 +6,32 @@ let ColSettingObj = {
|
|
|
colSetting: null,
|
|
|
DEFAULT_TITLE_STYLE: null,
|
|
|
DEFAULT_DATA_STYLE: null,
|
|
|
- Rows: {data: 0, filedName: 0, width: 1, readOnly: 2},
|
|
|
+ cellType: {
|
|
|
+ getText: null,
|
|
|
+ readOnly: null
|
|
|
+ },
|
|
|
+ Rows: {data: 0, filedName: 0, getText: 1, width: 2, readOnly: 3},
|
|
|
+ columnValueChanged: function (e, info) {
|
|
|
+ let that = ColSettingObj;
|
|
|
+ info.colList.forEach(function (iCol) {
|
|
|
+ info.sheet.setValue(that.colSetting.headRows + that.Rows.width, iCol, info.sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ valueChanged: function (e, info) {
|
|
|
+ let that = ColSettingObj;
|
|
|
+ if (info.row === that.colSetting.headRows + that.Rows.width) {
|
|
|
+ info.sheet.setColumnWidth(info.col, info.newValue, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ selectionChanged: function (e, info) {
|
|
|
+ let that = ColSettingObj, sel = info.newSelections[0];
|
|
|
+ if (sel.row <= that.colSetting.headRows) {
|
|
|
+ $('.btn-toolbar').removeClass('disabled');
|
|
|
+ $('#font').val(info.sheet.getCell(sel.row, sel.col, GC.Spread.Sheets.SheetArea.viewport).font());
|
|
|
+ } else {
|
|
|
+ $('.btn-toolbar').addClass('disabled');
|
|
|
+ }
|
|
|
+ },
|
|
|
getCellStyle: function (font, hAlign, vAlign) {
|
|
|
var style = new GC.Spread.Sheets.Style();
|
|
|
style.font = font;
|
|
@@ -15,6 +40,17 @@ let ColSettingObj = {
|
|
|
style.wordWrap = true;
|
|
|
return style;
|
|
|
},
|
|
|
+ initCellType: function () {
|
|
|
+ this.cellType.readOnly = new GC.Spread.Sheets.CellTypes.ComboBox();
|
|
|
+ this.cellType.readOnly.items([true, false,
|
|
|
+ 'readOnly.bills', 'readOnly.ration', 'readOnly.volumePrice',
|
|
|
+ 'readOnly.non_bills', 'readOnly.non_ration', 'readOnly.non_volumePrice',
|
|
|
+ 'readOnly.billsParent', 'readOnly.forCalcBase'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ this.cellType.getText = new GC.Spread.Sheets.CellTypes.ComboBox();
|
|
|
+ this.cellType.getText.items(['getText.type']);
|
|
|
+ },
|
|
|
initSheet: function (sheet, setting) {
|
|
|
sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
sheet.setColumnWidth(0, 80, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
@@ -23,8 +59,10 @@ let ColSettingObj = {
|
|
|
|
|
|
sheet.setText(setting.headRows + this.Rows.data, 0, 'Data', GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
sheet.setStyle(setting.headRows + this.Rows.data, -1, this.DEFAULT_DATA_STYLE);
|
|
|
+ sheet.addSpan(setting.headRows + this.Rows.data, 0, 2, 1, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
|
|
|
sheet.setText(setting.headRows + this.Rows.filedName, 1, 'FieldName', GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
+ sheet.setText(setting.headRows + this.Rows.getText, 1, 'getText', GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
|
|
|
sheet.setText(setting.headRows + this.Rows.width, 0, 'width', GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
sheet.addSpan(setting.headRows + this.Rows.width, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
@@ -35,6 +73,7 @@ let ColSettingObj = {
|
|
|
initColSetting: function (setting) {
|
|
|
this.DEFAULT_TITLE_STYLE = this.getCellStyle('Arial', GC.Spread.Sheets.HorizontalAlign.center, GC.Spread.Sheets.VerticalAlign.center);
|
|
|
this.DEFAULT_DATA_STYLE = this.getCellStyle('Arial', GC.Spread.Sheets.HorizontalAlign.left, GC.Spread.Sheets.VerticalAlign.center);
|
|
|
+ this.initCellType();
|
|
|
|
|
|
$('#empty-rows').val(setting.emptyRows);
|
|
|
$('#col-count').val(setting.cols ? setting.cols.length : 0);
|
|
@@ -42,15 +81,55 @@ let ColSettingObj = {
|
|
|
|
|
|
colEditSpread = new GC.Spread.Sheets.Workbook($('#colEditSpread')[0], {sheetCount: 1});
|
|
|
colEditSpread.options.tabStripVisible = false;
|
|
|
+ colEditSpread.bind(GC.Spread.Sheets.Events.ColumnWidthChanged, this.columnValueChanged);
|
|
|
+ colEditSpread.bind(GC.Spread.Sheets.Events.ValueChanged, this.valueChanged);
|
|
|
+ colEditSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, this.selectionChanged);
|
|
|
+
|
|
|
this.initSheet(colEditSpread.getActiveSheet(), setting);
|
|
|
this.setColCount(this.colSetting.cols.length);
|
|
|
this.setHeaderRowCount(this.colSetting.headRows);
|
|
|
+
|
|
|
+ if (setting.cols) {
|
|
|
+ let sheet = colEditSpread.getActiveSheet(), iRow;
|
|
|
+ for (let iCol = 0; iCol < setting.cols.length; iCol++) {
|
|
|
+ let col = setting.cols[iCol], iRow = 0;
|
|
|
+ // header
|
|
|
+ for (let i in col.head.spanCols) {
|
|
|
+ if (col.head.spanCols[i] !== 0) {
|
|
|
+ let cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ cell.value(col.head.titleNames[i]).font(col.head.font[i]).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
|
|
|
+ }
|
|
|
+ if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
|
|
|
+ sheet.addSpan(iRow, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ }
|
|
|
+ iRow += col.head.spanRows[i];
|
|
|
+ };
|
|
|
+ // data
|
|
|
+ // field
|
|
|
+ let cell = sheet.getCell(this.colSetting.headRows + this.Rows.data, iCol, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ cell.value(col.data.field).font(col.data.font).hAlign(col.head.hAlign).vAlign(col.data.vAlign);
|
|
|
+ // getText
|
|
|
+ cell = sheet.getCell(this.colSetting.headRows + this.Rows.getText, iCol, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ cell.cellType(this.cellType.getText).value(col.data.getText).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
|
|
|
+ // 列宽
|
|
|
+ sheet.setColumnWidth(iCol, col.width);
|
|
|
+ sheet.setValue(this.colSetting.headRows + this.Rows.width, iCol, sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ // readonly
|
|
|
+ cell = sheet.getCell(this.colSetting.headRows + this.Rows.readOnly, iCol, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ cell.cellType(this.cellType.readOnly).value(col.readOnly).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let cell = info.sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ if (cell) {
|
|
|
+ $('#font').val(cell.font());
|
|
|
+ }
|
|
|
},
|
|
|
setColCount: function (count) {
|
|
|
let sheet = colEditSpread.getActiveSheet();
|
|
|
sheet.setColumnCount(count);
|
|
|
for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
|
|
|
sheet.setValue(this.colSetting.headRows + this.Rows.width, iCol, sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ sheet.getCell(this.colSetting.headRows + this.Rows.readOnly, iCol, GC.Spread.Sheets.SheetArea.viewport).cellType(this.cellType.readOnly);
|
|
|
sheet.setValue(this.colSetting.headRows + this.Rows.readOnly, iCol, false, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
}
|
|
|
},
|
|
@@ -142,6 +221,11 @@ let ColSettingObj = {
|
|
|
col.data.vAlign = cell.vAlign();
|
|
|
col.data.hAlign = cell.hAlign();
|
|
|
col.data.font = cell.font();
|
|
|
+ // getText
|
|
|
+ cell = sheet.getCell(setting.headRows + this.Rows.getText, iCol);
|
|
|
+ if (cell.text() !== '') {
|
|
|
+ col.data.getText = cell.text();
|
|
|
+ }
|
|
|
setting.cols.push(col);
|
|
|
}
|
|
|
return setting;
|
|
@@ -199,41 +283,41 @@ $('#save-col-setting').click(function () {
|
|
|
});
|
|
|
|
|
|
$('#h-left').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
|
|
|
});
|
|
|
});
|
|
|
$('#h-center').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$('#h-right').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$('#v-top').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
|
|
|
});
|
|
|
});
|
|
|
$('#v-center').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
|
|
|
});
|
|
|
});
|
|
|
$('#v-bottom').click(function () {
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$('#set-font').click(function () {
|
|
|
var sFont = $('#font').val();
|
|
|
- ColSettingObj.controlSelectCells(spread, function (cell) {
|
|
|
+ ColSettingObj.controlSelectCells(colEditSpread, function (cell) {
|
|
|
cell.font(sFont);
|
|
|
});
|
|
|
});
|