kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

HTML inside exported file #291

Closed maxxer closed 5 years ago

maxxer commented 5 years ago

Sorry for stripping down questions but this issue seems very specific to the project itself. Unfortunately I did all the debug I could think about and I didn't manage to get it working, so I'm opening an issue as it's possibly a bug. It's very similar to #102, but as said I checked everything I found which could cause it and didn't find the culprit.

I've documented all the steps and view files on the forum, but if you prefer I can repost everything here.

To summarize I'm getting page HTML inside the exported CSV/XLS, invalidating the output file format. I tried stripping out everything I could from the page, from the layout to the view itself, and if I add a single html line (even a space) I get BOM chars before the real output. As I wrote on the forum I tried looking into the source files but they're all witout BOM!

I have no more ideas. Not 100% sure it's a bug but cannot thing anything else.

Libraries

kartik-v commented 5 years ago

yii2-export relies on the PHPSpreadsheet library for converting the HTML to various other formats. So it seems there is some HTML to Excel conversion issue for the library which needs to be debugged.

Suggest you to share or try the following:

Few other suggestions:

kartik-v commented 5 years ago

Few other configuration issues on the code:

kartik-v commented 5 years ago

There is an enhancement #292 added to better clear output buffers. Check if this resolves your issue.

maxxer commented 5 years ago

Thank you very much for the feedback. I've made a quick test by upgrading to dev-master but didn't made it. I'll try your other suggestions asap and report back! Thanks again

maxxer commented 5 years ago

Hi. Thanks again for your support. First, there's no such pjaxContainerId option in GridView 😅 I tried setting pjaxSettings > options > id but no change. I checked all the suggestions up to disabling pjax at all but nothing changed.

After all I was reading again and again the export menu documentation and found the clearBuffer options. Tried that and finally it worked! The output file doesn't contain unwanted html nor anything else!

This works on the stable 1.3.8 and .9 versions.

Thanks again.

kartik-v commented 5 years ago

Thanks for the update and glad it worked for you - as the ExportMenu::clearBuffers has been indeed provided for specific use cases based on your app specific code and what view content (and how that) is being rendered by developers.

BTW... The pjaxContainerId for GridView is set via GridView::pjaxSettings['options']['id']

baltechies commented 5 years ago

Few other configuration issues on the code:

  • One issue I see is that you have set pjaxContainerId wrongly in ExportMenu. You actually need PJAX for the GridView widget.
  • Set the pjaxContainerId within GridView
  • Remove the pjaxContainerId property from ExportMenu.
  • Set the pjax property to false within ExportMenu. I have a feeling the PJAX is causing additional HTML to be pushed onto the page.
  • Alternatively try once by disabling pjax at the GridView level also to check if it works (though it should not be needed).

@kartik-v How we can set 'pjax' property to false within 'ExportMenu'? I am using pjax to render multiple grids in tabs and download files saving unwanted html forms as well.