caxlsx / caxlsx_rails

A Rails plugin to provide templates for the axlsx gem
MIT License
744 stars 84 forks source link

Rails 6 Images not displaying #135

Closed alliedarmour closed 3 years ago

alliedarmour commented 4 years ago

I don't know if it's my fault or if it just doesn't work with Rails 6, but my images in the file are not displaying:

I tried: img = File.expand_path(Rails.root+'app/assets/images/icon_small.jpg') and also like described in the examples: img = File.expand_path('../logo.jpg', __FILE__)

sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
            image.start_at 5, 20
            image.end_at 7, 22
end

The image is found (at least I don't get an error for this) but the only thing I see in the generated file (the rest of the creation works fine) is:

erroraxlsx

Could it be the image size not fitting in the cells? Or is it resizing automatically?

Any suggestions or ideas? I don't know what's wrong or what else I could try

straydogstudio commented 4 years ago

@alliedarmour Have you been able to make this work inside a simple ruby script with local files? And is this being run within a controller, or in sidekiq or something offline?

alliedarmour commented 4 years ago

@alliedarmour Have you been able to make this work inside a simple ruby script with local files? And is this being run within a controller, or in sidekiq or something offline?

It's being run within a controller, really simple:

def export
    @meals = Meal.all.order(day: :asc)
    @clinic = @clinic_name

    respond_to do |format|
      format.xlsx { render xlsx: "export", filename: "SpeiseplanExport-#{Date.today}.xlsx" }
    end
  end

The file is locally present. At the moment it's running in development mode, but the version without the image is also running in production without problems. It's just that I can't get the image in.

I also tried setting the width and height explicitly but with no effect.

straydogstudio commented 4 years ago

Did the deploy to production process optimize the image and make it an asset? I'm pretty sure it's location and name will change.

alliedarmour commented 4 years ago

I didn't try the image export in production yet cause it doesn't run locally. In production, just the export WITHOUT the image is running. If I can make it work locally (in development), I will try it in production :).

straydogstudio commented 4 years ago

@alliedarmour Try explicitly checking for the existence of the file. Make sure there isn't a hidden error.

alliedarmour commented 4 years ago

@alliedarmour Try explicitly checking for the existence of the file. Make sure there isn't a hidden error.

Thanks for your answer. I checked the file and Rails tells me it exists:

img = Rails.root.join('app', 'assets', 'images', 'logo.jpg')

Returning:

"C:/Users/Admin/Desktop/NKBRFQualityManagement/app/assets/images/logo.jpg"

Checking for file:

File.exist?(img) (returns true)
File.file?(img) (returns true)

I guess I will just go without the image for now until I (or someone else) finds out what's happening there :D

ThroneGames commented 4 years ago

Same issue here with Rails 5.2.3 on Windows 10. Running it under Ubuntu the images render great.

straydogstudio commented 4 years ago

If anyone is willing, we need a test repo so this issue can be duplicated. Any volunteers?

straydogstudio commented 3 years ago

@alliedarmour This may have been fixed by a recent pull request in caxlsx that fixed importing binary files. You could test this again.

straydogstudio commented 3 years ago

This should have been addressed in the binary import changes in Caxlsx.