Angular spreadsheet SpreadsheetExcelImportEvent => event.sender.toJSON()

1 Answer 121 Views
Spreadsheet
stein
Top achievements
Rank 1
stein asked on 05 Jan 2024, 06:35 AM | edited on 05 Jan 2024, 06:43 AM

Hello,

I'm using kendo-angular-spreadsheet v14.3.0. When the spreadsheet component receives a file.

this.spreadsheet.spreadsheetWidget.fromFile(target.files[0]);

Then a `SpreadsheetExcelImportEvent` is triggered.

<kendo-spreadsheet (excelImport)="onExcelImport($event)"> </kendo-spreadsheet>

When doing `event.sender.toJSON()` I get the `DocumentDescriptor` that's currently on the spreadsheet component and not the descriptor of the file which was loaded.

  onExcelImport(event: SpreadsheetExcelImportEvent): void {
    // not the documentDescriptor of the file that was just loaded
    const documentDescriptor = event.sender.toJSON();
  }

Is this intended behavior? There's no event to get the DocumentDescriptor of the 'new' spreadsheet?

1 Answer, 1 is accepted

Sort by
0
Martin Bechev
Telerik team
answered on 09 Jan 2024, 01:14 PM

Hi Stein,

Please could you try the following approach to get the DocumentDescritpor of the Spreadsheet:

public onImport(spreadsheet: SpreadsheetComponent): void {
    console.log(spreadsheet.spreadsheetWidget.toJSON())
}

Regards,
Martin
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
kashif
Top achievements
Rank 1
commented on 28 May 2024, 05:06 PM

Hi Martin,

I have tried this approach mentioned in the your answer, but it is not working. Can you post a simple working example.

Martin Bechev
Telerik team
commented on 30 May 2024, 07:17 AM

Hi Kashif,

Please check the following article with a demo inside, on how to save the Spreadsheet to JSON data:

https://www.telerik.com/kendo-angular-ui/components/spreadsheet/data-import-export/#toc-saving-to-json-data

Regards,

Martin

 

kashif
Top achievements
Rank 1
commented on 01 Jun 2024, 09:49 PM

Martin, I have already tried it, but problem is not about getting data from spreadsheet, but main problem is described in original question, that I am unable to get data of newly imported file. It is giving me data of old file not newly loaded one. 
Martin Bechev
Telerik team
commented on 05 Jun 2024, 09:17 AM

 Hi Kashif,

I am not able to reproduce the reported scenario.

In this example, I uploaded another Excel file using the built-in import tool and exported it to JSON by using the custom button, and here is the result:

In case I am missing something, please could you provide some more details, or modify the StackBlitz in a way that reproduces the problem so that we can investigate further. Thank you. 

Regards

kashif
Top achievements
Rank 1
commented on 05 Jun 2024, 10:04 AM

Hi Martin,

Well, getting JSON using a button is not an issue. Main problem OP mentioned and I am also facing the same problem to get a event/callback or anything similar when Import of a Excel file is complete. If we try to get JSON data or update excel data during Import, it returns old object data before importing new file.

Martin Bechev
Telerik team
commented on 10 Jun 2024, 08:56 AM

Hi Kashif,

We understand what were the expectations from the Spreadsheet. Currently using setTimeout is required in order to wait for the Excel file to be loaded in the component. 

 public onExcelImport(ev: SpreadsheetExcelImportEvent) {
    setTimeout(() => {
      const desc = ev.sender.toJSON();
    }, 1000);
  }

We will consider our options in a way to provide a mechanism for knowing when the file is loaded and data available on the client. But at the meantime using setTimeout is the way to go.

 

stein
Top achievements
Rank 1
commented on 10 Jun 2024, 11:12 AM

Hi Martin,

There's no way to determine the necessary waiting time until the data is available on the spreadsheetWidget. For larger excel files I will need a longer waiting time.

Currently I've got a loop where I verify if the DocumentDescriptor is populated before continuing processing.

ps: I understand that the `spreadsheetWidget.toJSON()` always returns the current state of the widget but I find it strange that in your example above the `SpreadsheetExcelImportEvent.toJSON()` also returns the current state. Why isn't the event data immutable?
eg. a ClickEvent contains the pointer coordinates of where it clicked and not the current whereabouts of the pointer. 

stein
Top achievements
Rank 1
commented on 10 Jun 2024, 11:33 AM

I've forked and updated the stackblitz example: https://stackblitz.com/edit/angular-xu6wko-k31wpd

  public onExcelImport(event: SpreadsheetExcelImportEvent): void {
    // Issue lies here with the SpreadsheetExcelImportEvent
    // the event doesnt contain the data of the excel which was imported
    console.log(event.sender.toJSON());
    setTimeout(() => {
      // maybe it contains the data now? depends on the size of the excel.
      // why is this event data mutable?
      console.log(event.sender.toJSON());
    }, 1000);
  }

Martin Bechev
Telerik team
commented on 10 Jun 2024, 02:23 PM

Hi Stein,

Yes, currently using the available approach isn't very convenient and optimal.

After I discussed this case with the developers, I am logging the following feature request about providing a meaningful way to understand when the imported file is loaded in the Spreadsheet.

https://feedback.telerik.com/kendo-angular-ui/1654757-spreadsheet-event-callback-when-imported-excel-file-is-complete

I also added your votes to the request.

Tags
Spreadsheet
Asked by
stein
Top achievements
Rank 1
Answers by
Martin Bechev
Telerik team
Share this question
or