in reply to Re^2: Need help with inserting images to excel from db
in thread Need help with inserting images to excel from db

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

Replies are listed 'Best First'.
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jun 25, 2014 at 14:24 UTC
    Does'nt matter, anywhere
      In that case create a sub-folder images under where your script is.
      poj
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jun 25, 2014 at 14:31 UTC
    I created a folder images but its giving me the same error and the folder is empty. Thanks for your quick help.
      Try this test script in same folder as your failing script and check that test1.txt is created.
      #!/usr/bin/perl use strict; use warnings; my $dir = './images'; if (-d $dir){ open OUT,'>', $dir.'/test1.txt' or die "error open OUT $!"; print OUT "TEST"; close OUT or die "error close OUT $!"; } else { print "$dir folder does not exist"; }
      poj
        Hi Poj It does work !! it created a file name tast1.txt with TEST printed inside. Thanks Terry
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jun 25, 2014 at 13:34 UTC
    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
      Do you have a sub-folder images ?
      poj
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jun 25, 2014 at 14:21 UTC
    Nope, I don't even have a subfolder images in the directory where I am executing the script :)
      Where do you want the images to be created ? poj
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jul 01, 2014 at 09:12 UTC
    Hi Poj, I does work !!! it did create a file i.e. test1.txt with TEST printed inside. Thanks Terry
Re^4: Need help with inserting images to excel from db
by terrykhatri (Acolyte) on Jul 01, 2014 at 13:43 UTC
    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