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

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
  • Comment on Re^2: Need help with inserting images to excel from db

Replies are listed 'Best First'.
Re^3: Need help with inserting images to excel from db
by poj (Abbot) on Jun 25, 2014 at 11:19 UTC
    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
        In that case create a sub-folder images under where your script is.
        poj
      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
      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
      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
      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
      Hi Poj, I does work !!! it did create a file i.e. test1.txt with TEST printed inside. Thanks Terry