• Resolved Haoxian

    (@lonelicloud)


    Hi, Tobias,

    Happy New Year!

    Is it possible to provide an option to set the encoding of exported table file to be UTF-8 instead of current UTF-8 without BOM? An utf-8 without BOM encoded files with charaters in eastern Asian language like Chinese are not treated well in Excel.

    Yours,
    Haoxian

    https://wordpress.org/plugins/tablepress/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question!

    I’m not really sure where I could provide such an option or where I would have to set this.
    From what I understand, the exported file uses the same character set as the database or PHP internally.

    Regards,
    Tobias

    Thread Starter Haoxian

    (@lonelicloud)

    Hi,

    I am not fimiliar with PHP file output function. But I found a page about this. Could you take a look at this stackoverflow page:
    http://stackoverflow.com/questions/19067492/how-to-set-text-file-encoding-in-php? Could the methods suggested in the answers be implemented as an option in TablePress’s export page?

    Best wishes,
    Haoxian

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the link. Those methods all seem to be targetted at the file saving functions of PHP. TablePress does however not use those, so they don’t apply there 🙁

    The functions in TablePress that offer the file for download start at https://github.com/TobiasBg/TablePress/blob/master/controllers/controller-admin.php#L1184
    Maybe you can experiment with that a little bit to see if you can get UTF-8 with BOM?

    (An additional remark: I’m not sure if the BOM is helping that much here. It might be possible that you’ll have to use the UTF-16 format, but I’m not sure.)

    Regards,
    Tobias

    Thread Starter Haoxian

    (@lonelicloud)

    Hi,

    Thanks for the instructions. It actually worked at my test for export format of csv. Other formats have not been tested.

    I add following line after https://github.com/TobiasBg/TablePress/blob/master/controllers/controller-admin.php#L1133,

    $export_data = "\xEF\xBB\xBF" . $export_data;

    as stated in former suggested page on stackoverflow, then the exported csv file of one table containing Chinese characters in not zipped form is encoded in utf-8 with BOM, and can be opened without garbled characters.

    Could you add an option for user to choose to export csv format file with some treatments like this, just as the zip option provided, with a kind tooltip to inform that it’s an experimental feature or something like that?

    Regards,
    Haoxian

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah ok, these are the characters for a BOM. Good to hear that that helped!

    Instead of adding this line in the controller-admin.php file, it might be better to add it to the relevant CSV export line in the class-export.php file. That way, it will not influence other export formats (and it will even work in ZIP files).

    For the future, I’ll think about a good place for a filter to add for this, so that it won’t be necessary to edit the file, but so that it can be added with a filter.
    Offering this as an option on the “Export” screen is not really something that I like, as options like this can really make things more complicated for inexperienced users. In fact, WordPress recently removed the option for the blog character set to simplify things. Therefore, a filter will be much better for this.

    Regards,
    Tobias

    Thread Starter Haoxian

    (@lonelicloud)

    Hi,

    Thank you very much. A filter would be enough for someone who wants to export tables.

    At this moment, if somebody wants this feature, the former code snippet,

    $export_data = "\xEF\xBB\xBF" . $export_data;

    should be placed right before 96th line of class-export.php:

    https://github.com/TobiasBg/TablePress/blob/master/classes/class-export.php#L96

    Regards,
    Haoxian

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great! Thanks for the confirmation! I’ll try to find a good place for a filter for this then.

    Best wishes,
    Tobias

    Plugin Author TobiasBg

    (@tobiasbg)

    HI,

    a quick update here: The upcoming TablePress 1.6 will have a tablepress_export_data filter hook that allows adding things like this without having to modify the plugin files.

    Regards,
    Tobias

    Thread Starter Haoxian

    (@lonelicloud)

    Thanks a lot! That will be very helpful for those regularly import/export tables using TablePress.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, and it was an easy change, so a win for everybody 🙂

    Regards,
    Tobias

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘requested feature: set encoding of exported table to be utf-8 with BOM’ is closed to new replies.