Cannot get cell value

Hi team. 

I'm facing a problem: I cannot get the cell value when the open file is completed. Although, I can still see the value while using console.log


Image_1959_1721879801060


Here is my code: https://stackblitz.com/edit/react-yu8m9t-huftdm?file=index.js

You can reproduce this problem by importing the file that I attached below. 


Attachment: Sample2507_84447f66.zip

3 Replies

BP Babu Periyasamy Syncfusion Team July 25, 2024 06:00 PM UTC

Hi Ngoc Hoang,

We have reviewed your reported query based on the shared sample and file. We would like to inform you that the `openComplete` event gets triggered once the Workbook model is received from the server. If a cell in the opened file contains a formula, only the formula will be available in the model initially. The value of the formula will only be available after the sheet is rendered into the DOM. Since the `openComplete` event is triggered before the sheets are rendered, the formula of the cell is not calculated and so the cell value is undefined at that moment, leading to the issue you reported.

And if you want to get the cell value in the `openComplete` event, you can utilize the setTimeout function
like in the below code snippet to get the value of the cells and also attached the sample for your reference,

const openComplete = () => {

    const spreadsheet = spreadsheetRef.current;

    isOpenComplete = true;

    if (spreadsheet) {

      setTimeout(() => {

        spreadsheet

        .getData('SheetA!A1:W25')

        .then((cells) => {

          const cell = cells.get('A1');

          console.log('cell', cell);

          console.log('Value', cell.value);// => this value is undefined

        })

        .catch((e) => console.log(e));

      })

    }

  };


Sample link: https://stackblitz.com/edit/react-yu8m9t-lhrrvx?file=index.js

Or else, you can use the `dataBound` event, which will be triggered once the sheet renders. In that event, you can get the cell value using the getData method like in the below code snippet and also attached the sample for your reference,

const dataBound = (args) => {

    const spreadsheet = spreadsheetRef.current;

    if (spreadsheet) {

      spreadsheet

        .getData('SheetA!A1:W25')

        .then((cells) => {

          const cell = cells.get('A1');

          console.log('cell', cell);

          console.log('Value', cell.value);

        })

        .catch((e) => console.log(e));

    }

  }


Sample link: https://stackblitz.com/edit/react-yu8m9t-ebmcos?file=index.js

Kindly, check the above details and get back to us for further clarifications.



NH Ngoc Hoang replied to Babu Periyasamy July 26, 2024 07:21 AM UTC

Thank you so much



BP Babu Periyasamy Syncfusion Team July 30, 2024 03:58 AM UTC

Hi Ngoc Hoang,

We are glad that your issue has been resolved. Kindly get back to us for any other assistance.


Loader.
Up arrow icon