sheetDataHelper.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Created by Mai on 2017/3/13.
  3. */
  4. // settingʾÀý
  5. var __settingTemp = {
  6. cols: [
  7. {
  8. head: {
  9. titleNames: ['񅧏'],
  10. spanCols:[1],
  11. spanRows:[1],
  12. vAlign: [1],
  13. hAlign: [1],
  14. font: '4px Arial'
  15. },
  16. data:{
  17. field: 'code',
  18. vAlign: 1,
  19. hAlign: 0,
  20. font: '4px Arial'
  21. },
  22. width: 60
  23. }
  24. ],
  25. headRows: 1,
  26. headRowHeight: [25],
  27. emptyRows: 3
  28. };
  29. var SheetDataHelper = {
  30. loadSheetHeader: function (setting, sheet) {
  31. sheet.setColumnCount (setting.cols.length, GC.Spread.Sheets.SheetArea.viewport);
  32. sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
  33. setting.headRowHeight.forEach(function (rowHeight, index) {
  34. sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
  35. })
  36. setting.cols.forEach(function (col, index) {
  37. var i, iRow = 0, cell;
  38. for (i = 0; i < col.head.spanCols.length; i++) {
  39. if (col.head.spanCols[i] !== 0) {
  40. cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
  41. cell.value(col.head.titleNames[i])
  42. .font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  43. }
  44. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  45. sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
  46. }
  47. iRow += col.head.spanRows[i];
  48. };
  49. sheet.setColumnWidth(index, col.width);
  50. });
  51. },
  52. loadSheetData: function (setting, sheet, datas) {
  53. sheet.setRowCount(datas.length + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
  54. datas.forEach(function (data, iData) {
  55. setting.cols.forEach(function (colSetting, iCol) {
  56. var cell = sheet.getCell(iData, iCol, GC.Spread.Sheets.SheetArea.viewport);
  57. cell.value(data[colSetting.data.field])
  58. .font(colSetting.data.font).hAlign(colSetting.data.hAlign).vAlign(colSetting.data.vAlign);
  59. })
  60. });
  61. }
  62. };