SpreadJS GC를 사용하지 않고 border색 변경

워니·2024년 7월 4일


-> 대략 이런 스프레드시트

회사에서 스프레드시트 그리드 수정시 '직전변경(sheet.getDirtyCells())' 기준이 아니라 '원본'을 기준으로 색을 변화시키라는 오더가 있었다. 즉, 원본을 수정했다가, 다시 원본으로 변경했을때 색이 다시 원래대로 되어야 한다는 것이다.
우리회사 코드의 spreadJS버전에서는 GC를 사용하지 않기 때문에, 대안으로 border를 설정하는 방법 코드를 짜 보았다
(수많은 삽질이 있었다... 정보가 안나와...)

$scope.editCellChgColor = function(e, args) {
   var sheet = spread.getActiveSheet('grid1');
   var dirtyCells = sheet.getDirtyCells();
   var orgSheetCells = angular.element('#drawCanvas').scope().orgSheetCells;

   dirtyCells.forEach(cell => {
      var row = cell.row;
      var col = cell.col;

      if(!orgSheetCells[row]) {
         orgSheetCells[row] = {};
      }
      if((cell.newValue == null || cell.newValue == '') &&
         (cell.oldValue == null || cell.oldValue == '')) return;

      if(orgSheetCells[row][col] == undefined || orgSheetCells[row][col] == null) {
         sheet.getCell(row, col).backColor('#FFDAB9');
         orgSheetCells[row][col] = cell.oldValue;
      } else if(cell.newValue == orgSheetCells[row][col] || (!cell.newValue && orgSheetCells[row][col] == '')){
         sheet.getCell(row, col).backColor(null);
         sheet.getCell(row, col).borderTop(new $.wijmo.wijspread.LineBorder('#e1e4e9', 1));
         sheet.getCell(row, col).borderBottom(new $.wijmo.wijspread.LineBorder('#e1e4e9', 1));
         sheet.getCell(row, col-1).borderRight(new $.wijmo.wijspread.LineBorder('#e1e4e9', 1));
         sheet.getCell(row, col).borderRight(new $.wijmo.wijspread.LineBorder('#e1e4e9', 1));

      } else if(cell.newValue != orgSheetCells[row][col]) {
         sheet.getCell(row, col).backColor('#FFDAB9');
      }
   })
   angular.element('#drawCanvas').scope().orgSheetCells = orgSheetCells;
}

 

 

 
// 이 두 이벤트를 통해 
// 복사, 붙여넣기, 드래그앤드롭, 드래그필, delete를 감지하고 동작한다
sheet.bind($.wijmo.wijspread.Events.ValueChanged, function(e, args) {
   console.log('ValueChanged');
   $scope.editCellChgColor(e, args);
});

sheet.bind($.wijmo.wijspread.Events.RangeChanged, function(e, args) {
   console.log('RangeChanged');
   $scope.editCellChgColor(e, args);
});
profile
매일, 조금씩 나아가는중

0개의 댓글