0

i am trying to add the images to excel. am able to send the different images when calling the method res_data. but after the execution i see the last image overwrites all the previous images captured.

here is my code. please help .am using axlsx gem in ruby

class abc
    @@row=1
    @@f = File.open('result.xlsx', 'w+')
    @@p = Axlsx::Package.new
    @@ws = @@p.workbook.add_worksheet
    @@ws.name="result"

    def res_data(path)  
        @@ws.add_image(:image_src => path, :noSelect => true, :noMove => true) do |image|
          image.width=1366
          image.height=768
          image.start_at 0, @@row
        end

        @@row=@@row+42      
        @@p.serialize(@@f)
    end
end

calling the method as (using capybara methods along with this)

require 'axlsx'

obj = abc.new

path='c:\test\image_file.png'

visit "http://google.com

save_screenshot(path, :full => true) # google home page screenshot is captured

obj.res_data(path)

click_button "btnI"

save_screenshot(path, :full => true) #clicks "i'm feeling lucky " and capture the screenshot again

obj.res_data(path)

am able to see the 'c:\test\image_file.png' file gets updated with the new image (when save screenshot is called) but when i see the 'result_xlsx" file, it shows only the last image in all images.

Jennifer
  • 45
  • 1
  • 9
  • 1
    _Sidenotes_: class names **must** start with a capital; file, opened with `File.open` **must** be closed explicitly; class variables should not be used. Also, it would be fine if you show how you call this ...hmmm piece of code. – Aleksei Matiushkin May 25 '16 at 12:03
  • I do not understand what is really happening in your code. You have many images from what I understand, you try to pass them all to the excel but the last one gets overwritten by which one ? What happens if you pass only 1 image ? – Volodymyr Balytskyy May 25 '16 at 13:48
  • Sorry for the confusion. last one overwrites all the images. i see only last image in all . updated the question. – Jennifer May 25 '16 at 15:02
  • can you create a working code (with the bug of course) and post it ? By working, I mean a code which I could copy past and test on my laptop and see the bug with my eyes. That would be great. thanks – Volodymyr Balytskyy May 25 '16 at 17:55
  • I am lost. I just wrote simple code to add two images to a excel file. Works great. I am not sure what are you doing wrong here. – Volodymyr Balytskyy May 26 '16 at 16:21
  • @VolodymyrBalytskyy can you please provide that code? – Umer Farooq Jan 18 '23 at 06:36

0 Answers0