-1

Angular 2+ - After uploading excel file need to read its data(records present in the file) then want to send it to server via services

Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
  • 1
    i have implemented the same using sheetjs in Angular js , i think you can implement a similar approch in angular 2+ using https://github.com/SheetJS/js-xlsx/tree/master/demos/angular2 check out these articles too : https://stackoverflow.com/questions/50385028/filereader-read-file-using-correct-encoding-when-read-as-readasarraybuffer/50715289#50715289 , https://stackoverflow.com/questions/30830268/how-to-make-filereader-work-with-angular2 – Joel Joseph Jan 21 '19 at 11:09
  • @JoelJoseph: Cheers thanks a lot i took your SheetJs Approach its the best you saved me from my Boss. Is it possible to POST the array data using service to server, pls help me on that also. I owe you :) :) –  Jan 21 '19 at 16:05
  • @JoelJoseph: I did it using Angular POST service, one question let me know after using your SheetJs approach will i be able to work with excel data, for example suppose my excel file had column 'Age' and several values, will i be able to apply validations like if(age > 23)..... like these things ?? –  Jan 21 '19 at 17:35
  • you can do the working with data either on client side before sending the data to the server ( in Angular ) or in the server side after sending the data to the server. – Joel Joseph Jan 21 '19 at 17:37
  • @JoelJoseph: okay i can do that now, sending data to server from your SheetJs approach is not working can you tell any link to refer which will work with it –  Jan 21 '19 at 17:49
  • 1
    in the second link i provided the `$scope.fileContent` has the array of data afer reading data from the file , you can just send it to the server or work with it in the client side just like any javascript array. ( in your case TypeScript array i guess ) – Joel Joseph Jan 21 '19 at 17:52
  • @JoelJoseph: You SheetJs approach is working best, any way to send entire excel file to server. (File i mean entire excel for ex - filename.xlsx of size 2 MB suppose then how to send an entire 2MB file to server) ? –  Jan 24 '19 at 08:47

1 Answers1

0

That will cause a "too many requests" or "quota limit exceeded" error unless it has very few records. The best option is to use cloud functions to parse the file from the storage bucket once you have uploaded it by using a trigger. This will require creating a new record in one of your collections once a document is uploaded.

Check this out to get started:

How to upload image file via HTTP Google Cloud Function?

David Kabii
  • 642
  • 6
  • 17