Closed maxxer closed 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:
ExportMenu::encoding
property which can be changed). While such content may get rendered properly in HTML and PDF, the Excel or CSV conversion may not detect such content properly. In some cases they may need to be converted to some other format -e,g, UTF-16LE or ISO
mb_convert_encoding($output, 'UTF-16LE', 'UTF-8');
// ISO-8859
iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $value),
Few other configuration issues on the code:
pjaxContainerId
wrongly in ExportMenu
. You actually need PJAX for the GridView widget. pjaxContainerId
within GridView
pjaxContainerId
property from ExportMenu
.pjax
property to false
within ExportMenu
. I have a feeling the PJAX is causing additional HTML to be pushed onto the page.pjax
at the GridView level also to check if it works (though it should not be needed).There is an enhancement #292 added to better clear output buffers. Check if this resolves your issue.
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
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.
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']
Few other configuration issues on the code:
- One issue I see is that you have set
pjaxContainerId
wrongly inExportMenu
. You actually need PJAX for the GridView widget.- Set the
pjaxContainerId
withinGridView
- Remove the
pjaxContainerId
property fromExportMenu
.- Set the
pjax
property tofalse
withinExportMenu
. 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.
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