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

Images don't work #51

Closed
palmaste opened this issue May 12, 2020 · 18 comments
Closed

Images don't work #51

palmaste opened this issue May 12, 2020 · 18 comments

Comments

@palmaste
Copy link

I'm using Ruby 2.6.6-1-x64 on Windows and caxlsx 3.0.1.
The images do not appear on the worksheet.
It seems that the images are only partially copied in subfolder xl/media of xlsx file.
If I simply swap to the axlsx library, everything works again.

Example:

#require 'axlsx'
require 'caxlsx'

p = Axlsx::Package.new

p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
  
  sheet.add_row ["First Column", "Second", "Third"]
  sheet.add_row [1, 2, 3]
  
  img = 'image1.jpeg'
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"https://github.com/caxlsx/caxlsx") do |image|
    image.width=720
    image.height=666
    image.hyperlink.tooltip = "Labeled Link"
    image.start_at 1, 5
  end
  
end

p.use_shared_strings = true
p.serialize('simple.xlsx')

simple.xlsx

@noniq
Copy link
Member

noniq commented May 13, 2020

Thanks for the report! I’m not using Windows so it’s hard for me to investigate this further.

Which version of axlsx are you using?

@noniq noniq closed this as completed May 13, 2020
@noniq noniq reopened this May 13, 2020
@palmaste
Copy link
Author

axlsx-2.0.1

@straydogstudio
Copy link
Contributor

Just ran it on my Windows machine and can confirm.

@palmaste Did you use a ruby windows installer, or another method, to install ruby?

@straydogstudio
Copy link
Contributor

Note: Switching from axlsx to caxlsx changes from rubyzip-1.0.0 to rubyzip-2.3.0.

@palmaste
Copy link
Author

@straydogstudio Yes, I used rubyinstaller-devkit-2.6.6-1-x64.exe

@straydogstudio
Copy link
Contributor

@palmaste @noniq Note I have been able to reproduce this, and spend some time on it. I've not been able to isolate the problem yet. It took me a while to get debugging working on my Windows machine.

@noniq
Copy link
Member

noniq commented May 19, 2020

Just a wild guess: Could it be that we are reading / writing the image file somewhere without the “binary” flag? IIRC this doesn’t hurt on Unix-based systems, but may lead to corrupt files on Windows.

@palmaste
Copy link
Author

@straydogstudio Thank you. Currently I continue to use axlsx, but the problem is the dependency on the old version of rubyzip which prevents updating other gems.

@noniq
Copy link
Member

noniq commented May 19, 2020

@palmaste There's a version 2.0.2 of caxlsx which is still based on the v2-branch of axlsx, but contains an updated Rubyzip dependency: https://rubygems.org/gems/caxlsx/versions/2.0.2

Maybe you could use this as a workaroud before upgrading to caxlsx 3.

@palmaste
Copy link
Author

@noniq Thank you. It works! It seems to depend on rubyzip-1.3.0. Anyway it'is a step forward.

@dicamarques14
Copy link

Has this issue been fixed? I recently found this problem on my work Windows pc. But tried the script in a Ubuntu server and it worked

@straydogstudio
Copy link
Contributor

@dicamarques14 @noniq @palmaste I have isolated the problem to an IO call. I've tried to reproduce the issue outside of Rails but haven't completed that part. I will try to get to it soon.

Here is the location it occurs in caxlsx: https://github.com/caxlsx/caxlsx/blob/master/lib/axlsx/package.rb#L165-L168

@noniq
Copy link
Member

noniq commented Jul 16, 2020

Maybe changing line 167 like this fixes the problem?

zip.write IO.read(part[:path], mode: "rb")

@straydogstudio
Copy link
Contributor

Looks like that did it. I think you mentioned that before Stefan. I'm sorry I missed it. I'll push out a new release. Do we have anything else that should be included?

straydogstudio added a commit that referenced this issue Jul 16, 2020
@noniq
Copy link
Member

noniq commented Jul 16, 2020

I think there have been two or three small fixes since the last release, but they are already merged and mentioned in the Changelog (section “Unreleased”). Nothing else on my radar, currently. Let's do a release! 🚀

@straydogstudio
Copy link
Contributor

Sounds good. Once testing passes I'll bump the version number and release.

@straydogstudio
Copy link
Contributor

3.0.2 released. @palmaste Please test as you have time.

@palmaste
Copy link
Author

@straydogstudio It works! Thank you all.

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

4 participants