How to write each wijmo flex sheet cell efficiently

Posted by: syed.mahmud on 22 March 2023, 5:26 pm EST

    • Post Options:
    • Link

    Posted 22 March 2023, 5:26 pm EST

    I want to write each cell of a flex sheet by myself. currently i am using this function to write the cell . But it is not optimized and takes so much time to write . How can i improve this .

    FYI - i am getting the excel data from SpreadsheetGear Engine for .NET .

    writeToWorksheet(rowIndex: number, maxRowToWritePerCall: number, worksheetPageModel, sheet, callback, self, threadId) {

    for (let i = 0; i < maxRowToWritePerCall; i++) {

    if (rowIndex >= worksheetPageModel.rows.length) {

    callback();

    return;

    }

      const row = worksheetPageModel.rows[rowIndex];
    
      if (sheet.rows[rowIndex]) {
        sheet.rows[rowIndex].visible = !row.isHidden;
      } else {
        for (let r = sheet.rows.length; r <= rowIndex; r++) {
          const newRow = new wjcGrid.Row();
          newRow.visible = !row.isHidden;
          sheet.rows.push(new wjcGrid.Row());
        }
      }
    
      for (let j = 0; j < row.cells.length; j++) {
        const cell = row.cells[j];
        if (cell.e) {
          continue;
        }
        const colIdx = cell.c;
        const cellRange = self.getCellRange(sheet, row, cell);
        const sheetColumn = sheet.columns[colIdx];
    
        if (sheetColumn) {
          sheet.setCellData(rowIndex, colIdx, cell.v);
          self.mergeCell(sheet, cellRange, row, cell);
          self.flexSheetStyleManagementService.setCellStyle(sheet, cellRange, cell, this.worksheetPageModel);
          cellRange.worksheetPageModel = cell;
        } else {
          console.warn('Invalid column index', cell);
        }
      }
    
      try {
        sheet.autoSizeRow(rowIndex);
      } catch (err) {
        console.log('[Excel] ', err);
      }
    
      rowIndex++;
      if (rowIndex >= worksheetPageModel.rows.length) {
        // this.setProgressBar(0, false);shaon
        callback();
        return;
      }
      const progress = Math.round((rowIndex / worksheetPageModel.rows.length * 100));
      this.fuseSplashScreenService.updateProgressBar(rowIndex, worksheetPageModel.rows.length, 'Rendering Spreadsheet', true);
    }
    if (rowIndex < worksheetPageModel.rows.length) {
      console.log(rowIndex, '[Excel] cell row writen threadId' + threadId);
    
      requestAnimationFrame(()=> {
        self.writeToWorksheet(rowIndex, maxRowToWritePerCall, worksheetPageModel, sheet, callback, self, threadId);
      })
    }
    

    }

  • Posted 23 March 2023, 7:57 pm EST

    Hello,

    Your approach seems correct by looking into the shared code snippet, as to update data manually in the Unbound sheet you would be required to iterate over each cell and set your desired value. When dealing with big data sets, there may be some slight delay, but if you encounter a significant performance problem then we would require a small sample replicating your issue so that we can investigate it further at our end to find the root cause and assist you accordingly.

    Regards

    Sonu Kumar Pandey

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels