Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend UTF-8 BOM to CSV #279

Closed
kzkn opened this issue Mar 20, 2020 · 5 comments
Closed

Prepend UTF-8 BOM to CSV #279

kzkn opened this issue Mar 20, 2020 · 5 comments

Comments

@kzkn
Copy link

kzkn commented Mar 20, 2020

I want to be able to prepend UTF-8 BOM ("\xEF\xBB\xBF") to the downloaded CSV file.

MS Excel does not correctly recognize UTF-8 (without BOM, it's plain) files containing non-ASCII characters. If you prepend UTF-8 BOM, it will recognize correctly. I think this is a bug of MS Excel, but there is no way to fix it. We have no choice but to avoid it.

I have confirmed that it can be avoided by applying a monkey patch to Blazer::QueriesController.

load Blazer::Engine.root.join('app/controllers/blazer/queries_controller.rb')
Blazer::QueriesController.prepend(Module.new do
  def csv_data(columns, rows, data_source)
    "\xEF\xBB\xBF" + super
  end
end)

SEE: https://stackoverflow.com/questions/2881093/override-a-rails-engine-controller-action

I want to take this as a function.
In my idea, it is good that it can be contorlled with blazer.yml to keep compatibility.

@ankane
Copy link
Owner

ankane commented Apr 7, 2020

Hey @kzkn, thanks for the suggestion. Which versions of MS Excel are affected?

@kzkn
Copy link
Author

kzkn commented Apr 7, 2020

@ankane
As far as I know, version 2013 and earlier are affected at least.

@kzkn
Copy link
Author

kzkn commented Apr 16, 2020

@ankane
If I send a pull request, could you merge it?

@ankane
Copy link
Owner

ankane commented May 17, 2020

Hey @kzkn, this isn't something I want to include in the gem right now. Thanks for sharing your approach. Others who need this should be able to use it.

@ankane ankane closed this as completed May 17, 2020
@abrambailey
Copy link

Agree this would be a nice option. We ran into the same issue with our project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants