Closed rsmithlal closed 8 years ago
What is the full error message?
In google spreadsheets: "Sorry, an error occurred when opening this file. Please try again." In Numbers: "“order_report.xlsx” can’t be opened." I don't get any error messages on generation.
Try adding formats: [:xlsx]
What is the request format? Before 0.4.0 axlsx_rails would force the formats array to include xlsx. But in Rails 4.2 this array is cached, so it caused trouble everywhere else, since the default format array had been changed. I dropped that behavior. It requires that the request format come across with xlsx. This is normal behavior. Meaning, if you request /foo/bar.html and serve an xlsx file it won't work unless you force the format. The option above should force it for the one render.
That formats parameter is for Rails 4. Which Rails are you using?
4.1.2
Oops, formats can be used as of Rails 3.2.3.
What do you mean by "What is the request format?"? I posted the whole method used to generate the report. It's not using
respond_to do |format|
format.xlsx
Where should I add formats: [:xlsx]
?
You're right about what is the request format. So there is no issue of it not being xlsx.
Pass the formats parameter to the render command. Let me know if it changes anything.
So the only change from working to not working is going form axlsx_rails 0.3.0 to 0.4.0? Any other changes in the Gemfile?
@rsmithlal Did that parameter change anything?
I haven't had a chance to test it out with 0.4.0 since we first spoke about it, haven't been able to put any dev time into looking into the issue as 0.3.0 works well for us at the moment. When I get an opportunity, I'll test it out and let you know so you can update the docs.
However, I can confirm that the only change to the gemfile was the version change for this gem.
@rsmithlal Please let me know what rubyzip you have in your Gemfile.lock. Try fixing rubyzip on 1.1.0. Rubyzip seems to cause most of the problems.
As I was having the same issue, I tried what you suggested about updating rubyzip version but I am getting this error with bundle update:
Bundler could not find compatible versions for gem "rubyzip":
In Gemfile:
axlsx_rails (>= 0) ruby depends on
axlsx (>= 2.0.1) ruby depends on
rubyzip (~> 1.0.0) ruby
rubyzip (~> 1.1.0) ruby
Ok I managed to update rubyzip by adding this into my Gemfile
gem 'axlsx', git: "git@github.com:randym/axlsx.git"
But even with rubyzip 1.1.7 I am still not able to open a xlsx generated file
Ok I found my issue. I was having a layout for another format which was happened to the generated xlsx file. Setting layout: false to my render call made it work. Maybe this could help someone sometime
@phyzalis Thanks for the info. Would you post a gist of your controller code, and what versions of Rails, axlsx, axlsx_rails, rubyzip you are using? I've seen this before and will try to find out what is going on. It shouldn't be trying to use a layout.
I have not been able to reproduce this bug. But, based on the experience of others (here and in other issues) the latest release of axlsx_rails (0.5.0) explicitly sets layout to false. Advising others to set the layout to false appears to fix these issues. I am cautiously optimistic. Please try 0.5.0 and comment on this issue (or open another) if the failure happens again.
I'm working with an extension of Spree 2.3. The method that generates the excel report is as follows:
my template is called "order_report.xlsx.axlsx" and contains:
The sheet generated using 0.3.0 using this exact code can be viewed at https://docs.google.com/a/grenadinetech.com/spreadsheets/d/17qV3gC23V-JR255_peZauy6WUBf1Ur5UJeUVD3tGPX8/edit?usp=sharing
I've had to version-lock the gem in order to continue developing the template on our extension. Any thoughts about what could have changed between versions to cause this error? Need any additional information?