in reply to Need help with inserting images to excel from db

It looks like you can't insert the image without writing it to a file first - see here
http://stackoverflow.com/questions/23117540/use-perl-gd-to-create-and-insert-image-directly-into-excel-workbook.
poj
  • Comment on Re: Need help with inserting images to excel from db

Replies are listed 'Best First'.
Re^2: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jun 25, 2014 at 10:02 UTC
    Hi I know I will have to write it to a temp file/dir first and then pass it on the insert_image() method, since I am quite new in perl I don't know how to do that, if someone can write the necessary code for me and add it to my script that will be great. Thanks anyways for your help/suggestions. Rgds Terry
      while ($a = $sth->fetchrow_hashref()) { $worksheet->write($row,0, $a->{EmployeeID}, $number); $worksheet->write($row,1, $a->{FirstName}, $bold); $worksheet->write($row,2, $a->{LastName}, $bold); # Change directory and filename to suit. my $imgfile = './images/'.$a->{'EmployeeID'}.'.jpg'; # or png,bmp open OUT,'>',$imgfile or die "Could not open $imgfile : $!"; binmode OUT; print OUT $a->{'Photo'}; close OUT or die "Could not close $imgfile : $!"; $worksheet->insert_image($row,3, $imgfile); # delete file unlink($imgfile) or warn "Could not unlink $imgfile: $!";; autofit_columns($worksheet); $row++; }
      poj
        Does'nt matter, anywhere
        I created a folder images but its giving me the same error and the folder is empty. Thanks for your quick help.
        Thanks Poj, I added your code to my script and its giving me the following error :
        Could not open ./images/1.jpg : No such file or directory at emp.pl li +ne 62.
        Any idea why ? all images are with ext. jpg. Thanks for your kind help. Rgds. Terry
        Nope, I don't even have a subfolder images in the directory where I am executing the script :)
        Hi Poj, I does work !!! it did create a file i.e. test1.txt with TEST printed inside. Thanks Terry
        Hi Poj, Your script works fine only the deleting the images is causing the problems :
        # delete file unlink($imgfile) or warn "Could not unlink $imgfile: $!";;
        Many thanks for your kind help !! Rgds Terry