Pārlūkot izejas kodu

根据setting输出data到Spread.Sheets

MaiXinRong 8 gadi atpakaļ
vecāks
revīzija
df02953f38
1 mainītis faili ar 63 papildinājumiem un 0 dzēšanām
  1. 63 0
      web/scripts/sheetDataHelper.js

+ 63 - 0
web/scripts/sheetDataHelper.js

@@ -0,0 +1,63 @@
+/**
+ * Created by Mai on 2017/3/13.
+ */
+// settingʾÀý
+var __settingTemp = {
+    cols: [
+        {
+            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
+        }
+    ],
+    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) {
+        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);
+            })
+        });
+    }
+};