Author Topic: asp.net mvc import xlsx  (Read 670 times)

hdl

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 5
    • View Profile
asp.net mvc import xlsx
« on: March 08, 2022, 09:19:44 am »
How do I import Excel files returned from asp.net webapi ?


Suppose I have a WebApi to download files.

like:    http://localhost/api/download?fileid=111




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: asp.net mvc import xlsx
« Reply #1 on: March 08, 2022, 10:30:48 am »
It's done with help of pq.excel.importXl and grid.importWb methods:

https://paramquery.com/pro/api#method-importXl

https://paramquery.com/pro/api#method-importWb

Code: [Select]
//import xlsx file from remote location.
    pq.excel.importXl( {url: 'http://localhost/api/download?fileid=111'}, function( wb ){
        grid.importWb({ workbook: wb, extraRows: 10, extraCols: 10 });
        grid.hideLoading();
    })

hdl

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: asp.net mvc import xlsx
« Reply #2 on: March 09, 2022, 09:47:09 pm »
I tried.  But an exception is thrown.
Code: [Select]

Uncaught TypeError: Cannot read properties of undefined (reading 'uint8array')
    at Object.c.transformTo (jszip.min.js:12:23187)
    at c.prepareReader (jszip.min.js:12:27706)
    at c.load (jszip.min.js:12:27806)
    at new c (jszip.min.js:12:24114)
    at c.b.exports [as load] (jszip.min.js:12:8048)
    at new c (jszip.min.js:12:7348)
    at Object.getWorkBook (pqgrid.min.js:17:7374)
    at l (pqgrid.min.js:17:9437)
    at Object.Import (pqgrid.min.js:17:9675)
    at Object.importXl (pqgrid.min.js:18:2317)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: asp.net mvc import xlsx
« Reply #3 on: March 09, 2022, 10:39:22 pm »
That means something is wrong in the webAPI. Please check the output when you open the webAPI url directly in browser: http://localhost/api/download?fileid=111

It's supposed to download a file similar to this: http://paramquery.com/pro2/Content/workbook.xlsx
« Last Edit: March 09, 2022, 10:48:37 pm by paramvir »