Author Topic: Export working, except for .xlsx  (Read 1467 times)

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Export working, except for .xlsx
« on: January 14, 2022, 11:23:06 pm »
I'm getting this error when exporting w/.xlsx. Any ideas? I'm using V.8

pqgrid.min.js:17 Uncaught TypeError: JSZip is not a constructor
    at Object.exportWb (pqgrid.min.js:17:13462)
    at e.cExport.Export (pqgrid.min.js:17:7559)
    at e.<computed>.<computed>.n.exportData (pqgrid.min.js:17:5121)
    at e.<computed>.<computed>.exportData (test.html:53:33)
    at e.<computed>.<computed>.action (test.html:224:48)
    at e.cContext.onclickDoc (pqgrid.min.js:16:314)
    at HTMLBodyElement.dispatch (jquery-2.2.4.min.js:3:7537)
    at HTMLBodyElement.r.handle (jquery-2.2.4.min.js:3:5620)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: Export working, except for .xlsx
« Reply #1 on: January 14, 2022, 11:38:36 pm »
Please include JSZip js file from the SDK.

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #2 on: January 14, 2022, 11:49:04 pm »
That's it. Thanks for quick response!!

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #3 on: January 15, 2022, 12:47:48 am »
Including the file worked for .xlsx in my vanilla test page, but I'm getting this error in my app page when calling exportData: "Uncaught invalid color: gray at pqgrid.min.js.17"

Any ideas what to try next?

Here are  my script includes for the page:
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />

    <script src="PQ/pqgrid.min.js"></script>
    <script src="PQ/pq-localize-en.js"></script>
    <script src="PQ/jszip.min.js"></script>
    <script src="PQ/FileSaver.js"></script>

    <link href="PQ/pqgrid.min.css" rel="stylesheet" />
    <link href="PQ/pqgrid.ui.min.css" rel="stylesheet" />
« Last Edit: January 15, 2022, 01:42:07 am by mikep »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: Export working, except for .xlsx
« Reply #4 on: January 17, 2022, 01:17:11 pm »
Named colors are not supported in Excel export. Please convert it into Hex color code.

#999999

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #5 on: January 21, 2022, 02:56:40 am »
Thanks, next issue for .xlsx.

It looks like the .xlsx file is ultimately formatted as html. I debugged the SaveAs method in FileSaver.js and the output appeared identical to my demo page, which successfully exports to .xlsx. I'm attaching the excel and js files for you review. Here's the javascript I'm using that calls the js File.

                var grid = $gridMain.pqGrid('instance');
                var blob = grid.exportData({
                    format: format,
                    render: true
                });

                if (typeof blob === "string") {
                    blob = new Blob([blob]);
                }
                saveAs(blob, "SMART_export." + format);



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: Export working, except for .xlsx
« Reply #6 on: January 21, 2022, 11:11:19 am »
Please check render parameter of exportData method and column.exportRender option to configure rendered cell (with HTML) output in the xlsx file.

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

https://paramquery.com/pro/api#option-column-exportRender

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #7 on: January 21, 2022, 05:23:26 pm »
Thanks. I am exporting grid columns that have images, could this be causing the issue?
I have just set the those grid columns with: "exportRender:false", but when I export, these columns are still visible. Do I need to do something else so that the grid columns don't get exported?

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #8 on: January 21, 2022, 07:39:56 pm »
Another question for .xlsx, attached is a screenshot showing csv and xlsx exports for the same grid. The csv is correctly only showing the columns visible in the grid, and .xlsx is showing more columns, the 1st column has no data in it and is on it's own row in excel. Also, I continue to get the attached error before opening the .xlsx file.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: Export working, except for .xlsx
« Reply #9 on: January 24, 2022, 10:51:36 am »
There is a difference between csv export and xlsx export wrt. hidden columns.

Hidden columns are exported as hidden columns during Excel export.

Hidden columns are not exported at all during csv export.

If you want to skip some columns while xlsx export, then add copy:false in case of non-grouped columns or create a new colModel without those columns in case of grouped columns before xlsx export.

Error while opening the xlsx file may be caused due to html tags in the grid title option. Please make it a simple string without any HTML content.
« Last Edit: January 24, 2022, 10:53:44 am by paramvir »

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #10 on: January 27, 2022, 06:35:42 pm »
There's no html in the grid title. Attached is error on load, and the actual .xlsx file. Any other ideas?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: Export working, except for .xlsx
« Reply #11 on: January 31, 2022, 01:18:52 pm »
There is a colon ":" in your grid title which is causing error. Please remove it to fix the issue.

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Export working, except for .xlsx
« Reply #12 on: February 02, 2022, 01:50:55 am »
That was it. Thank you.