Author Topic: exportData not working after upgrading to vs 9.0.2  (Read 280 times)

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
exportData not working after upgrading to vs 9.0.2
« on: December 04, 2023, 09:16:43 pm »
Hello,

I updated paramQuery from v8.2.1 to v9.0.2. With this change, my export to excel has stopped working. I am using .net for server code.  Below is my code which was working for v8.2.1 but now noting happens when ExportGridView() is called. Even it is not calling server side code. I did put debugger at server side but nothing happened.

JS code
===============
function ExportGridView() {
    gridApi.exportData({
        url: pageURL + "/exportData",
        format: 'xlsx',
        nopqdata: true,
        render: false,
        sheetName: 'Team Assignments',
        filename: "WFP_TeamAssignments " + moment().format('DD-MMM-YYYY') + '.xlsx'
    });
}


.net code
===============
[HttpPost, ValidateInput(false)]
        public string exportData(string pq_ext, string pq_data, bool pq_decode, string pq_filename)
        {
            System.Web.HttpContext.Current.Application["pq_data"] = pq_data;
            System.Web.HttpContext.Current.Application["pq_decode"] = pq_decode;
            System.Web.HttpContext.Current.Application["pq_filename"] = pq_filename;
            return pq_filename;
        }
        [HttpGet]
        public FileContentResult exportData(string pq_filename)
        {
            String contents = System.Web.HttpContext.Current.Application["pq_data"].ToString();
            byte[] bytes = ((bool)System.Web.HttpContext.Current.Application["pq_decode"]) ? Convert.FromBase64String(contents) :
                new System.Text.UTF8Encoding().GetBytes(contents);
            return File(bytes, "application/octet-stream", pq_filename);
        }

Please help me to get this issue resolved.

Thanks

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: exportData not working after upgrading to vs 9.0.2
« Reply #1 on: December 05, 2023, 11:21:36 am »
Please check the upgrade guide for v9

https://paramquery.com/pro/upgrade#option-exportData

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: exportData not working after upgrading to vs 9.0.2
« Reply #2 on: December 05, 2023, 11:37:33 am »
Easier way is to use this:

Code: [Select]
var blob = gridApi.exportData({
        //url: pageURL + "/exportData",
        format: 'xlsx',
        //nopqdata: true,
        render: false,
        sheetName: 'Team Assignments'
        //filename: "WFP_TeamAssignments " + moment().format('DD-MMM-YYYY') + '.xlsx'
    });

pq.saveAs( blob, "WFP_TeamAssignments " + moment().format('DD-MMM-YYYY') + '.xlsx' );

There is no remote call associated with this.

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: exportData not working after upgrading to vs 9.0.2
« Reply #3 on: December 05, 2023, 12:24:46 pm »
Thanks.

I tried the approach suggested by you, but now I am getting error while opening the file(as Attached ScreenShot3).

I also found pq.postData method in documentation but I am not sure how to pass grid data in pq_data.

pq.postData("../exportData", {
      pq_filename: 'pqgrid',
      pq_ext: 'csv',
      pq_data: data,
      pq_decode: false
   },
   //optional parameter
   {
      success: function(response){
         //do something with response.
      }
   }           
)
« Last Edit: December 05, 2023, 12:40:32 pm by gopigupta »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: exportData not working after upgrading to vs 9.0.2
« Reply #4 on: December 05, 2023, 02:02:16 pm »
Here is an example of remote export for v9: https://paramquery.com/pro/demos/export_csv

In your case of xlsx remote export, you have to pass type: 'base64' to exportData method:

Code: [Select]
//returns base64 string.
var data = gridApi.exportData({
        type: 'base64',
        format: 'xlsx',
        render: false,
        sheetName: 'Team Assignments'
    });

pq.postData("/pro/demos/exportData", {
      pq_filename: 'pqgrid',
      pq_ext: 'xlsx',
      pq_data: data,
      pq_decode: true
})

//pq.saveAs( blob, "WFP_TeamAssignments " + moment().format('DD-MMM-YYYY') + '.xlsx' );


Anyway the error means local export is working fine but there is some issue with formatting the xlsx. Have you tried to click "yes" and find out what formatting is lost by it.

Is it possible for you to share that xlsx file or a similar test case with reproducible issue.
« Last Edit: December 05, 2023, 02:33:03 pm by paramvir »

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: exportData not working after upgrading to vs 9.0.2
« Reply #5 on: December 05, 2023, 03:57:27 pm »
Thank you for quick help. You are right, this could be data formatting issue in particular grid since same approach is working in other grids.

Thanks again.