CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Add Image to excel

 



rekcut01
Novice

May 8, 2014, 1:59 PM

Post #1 of 2 (2875 views)
Add Image to excel Can't Post

 
OK perl experts, it's me again with another question. I have created a barcode .png file and want to insert in into a cell on my spreadsheet. I keep getting and error that it can't find the method for insert image. I have looked and tried several examples that are posted online but with no luck. Can someone take a look and advise me what I'm doing wrong?

Thanks in advance
Rick



#!c:/strawberry/perl/bin/perl.exe
# PERL MODULES WE WILL BE USING
use strict;
use warnings;
use integer;
use CGI;
use Win32::OLE;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
use Spreadsheet::WriteExcel;
use Spreadsheet::ParseExcel::SaveParser::Workbook;
use Spreadsheet::ParseExcel::Worksheet;
use Spreadsheet::ParseExcel::Workbook;
use Spreadsheet::WriteExcel::Format;
use Spreadsheet::WriteExcel::OLEwriter;
use Spreadsheet::WriteExcel::Properties ':property_sets';
use Time::localtime;
use POSIX qw(strftime);
use Time::Piece;
use OLE;
use Win32::OLE::Const "Microsoft Excel";

print "Content-type: text/html\n\n";
# Config DB variables
our $q = new CGI;

#Get the parameter from your html form.
my $TxtName=$q->param('TxtName');
my $TxtOrg=$q->param('TxtOrg');
my $TxtCit=$q->param('TxtCit');
my $TxtHPEmp=$q->param('TxtHPEmp');
my $TxtEscort=$q->param('TxtEscort');
my $now_string = localtime;
my $date = localtime->strftime('%m/%d/%y');


my $min_range = 1000000000;
my $max_range = 9999999999;

my $bc_number = rand($max_range) + $min_range; # More interested in repeatability than randomness
print $bc_number . "\n";


if ($TxtName eq "")
{
print "Error: Must enter Name\n";
print "<input type='button' value='Back' onclick='javascript:history.back(1);' />";
}
elsif ($TxtOrg eq "")
{
print "Error: Must enter Organization\n";
print "<input type='button' value='Back' onclick='javascript:history.back(1);' />";
}
elsif ($TxtCit eq "")
{
print "Error: Must enter Citizenship\n";
print "<input type='button' value='Back' onclick='javascript:history.back(1);' />";
}
elsif ($TxtHPEmp eq "")
{
print "Error: Must Confirm HP Employment\n";
print "<input type='button' value='Back' onclick='javascript:history.back(1);' />";
}
elsif ($TxtEscort eq "")
{
print "Error: Must enter Escort Name\n";
print "<input type='button' value='Back' onclick='javascript:history.back(1);' />";
}
else
{
my $status = system("C:/zint/zint.exe --height=20 -o C:/users/rtucker/desktop/vbadgeBC.png -d $bc_number");

# -------> CREATE BADGE HERE <-------
# Open an existing file with SaveParser
my $excel = Win32::OLE->new('Excel.Application');
$excel->{Visible} = 1;
my $parser2 = Spreadsheet::ParseExcel::SaveParser->new();
my $workbook2 = $parser2->Parse('/Users/Rtucker/Desktop/vBadge.xls');

if ( !defined $workbook2 ) {
die $parser2->error(), ".\n";
}



## Get the first worksheet.
my $worksheet2 = $workbook2->worksheet(0);

my $iF1 = $workbook2->AddFont(
Name => 'Arial',
Height => 20,
Bold => 1,
Italic => 0,
Underline => 0,
Strikeout => 0,
Super =>0,
Align => 'center',
Valign => 'vcenter',
);
my $iF2 = $workbook2->AddFont(
Name => 'Arial',
Height => 10,
Bold => 1,
Italic => 0,
Underline => 0,
Strikeout => 0,
Super =>0,
Align => 'center',
Valign => 'vcenter',
);
my $iF3 = $workbook2->AddFont(
Name => 'Arial',
Height => 10,
Bold => 0,
Italic => 0,
Underline => 0,
Strikeout => 0,
Super =>0,
Align => 'center',
Valign => 'vcenter',
);

my $format1 = $workbook2->AddFormat(
Font => $workbook2->{Font}[$iF2],
Align => 'center',
);

my $format2 = $workbook2->AddFormat(
Font => $workbook2->{Font}[$iF1],
);

my $format3 = $workbook2->AddFormat(
Font => $workbook2->{Font}[$iF3],
);

my ( $row_min1, $row_max1 ) = $worksheet2->row_range();
my $bRow = 0;
my $bCol = 0;
my $cell1 = $worksheet2->get_cell( $bRow, $bCol );
my $path = 'c:/users/rtucker/desktop/';
my $sponsor = 'SPONSER: ';
my $sponsor_name = join '', $sponsor, $TxtEscort;

$worksheet2->AddCell( $bRow, $bCol, $TxtName, $format2 );
$worksheet2->AddCell( $bRow + 1, $bCol, $TxtOrg, $format1 );
$worksheet2->AddCell( $bRow + 2, $bCol, $date );
$worksheet2->AddCell( $bRow + 3, $bCol, $sponsor_name, $format3 );
#$worksheet2->AddCell( $bRow + 3, $bCol, $TxtEscort, $format3 );
#$worksheet2->insert_image('A6:A1', 'c:/Users/Rtucker/Desktop/vbadgeBC.png', 0, 0, 2, 0.8);<---------- FAILS RIGHT HERE!!!

# Write over the existing file or write a new file.
$workbook2->SaveAs('/Users/Rtucker/Desktop/vBadge.xls');

# -------> END CREATE BADGE HERE <-------







# -------> CREATE REPORT HERE <-------
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $workbook = $parser->Parse('/Users/Rtucker/Desktop/Report.xls');

if ( !defined $workbook ) {
die $parser->error(), ".\n";
}

## Get the first worksheet.
my $worksheet = $workbook->worksheet(0);
my ( $row_min, $row_max ) = $worksheet->row_range();
my $row = $row_max + 1;
my $col = 0;
my $cell = $worksheet->get_cell( $row, $col );

$worksheet->AddCell( $row, $col, $TxtName );
$worksheet->AddCell( $row, $col + 1, $TxtOrg );
$worksheet->AddCell( $row, $col + 2, $TxtCit );
$worksheet->AddCell( $row, $col + 3, $TxtHPEmp );
$worksheet->AddCell( $row, $col + 4, 'Sponser:', $TxtEscort );
$worksheet->AddCell( $row, $col + 5, $now_string);

# Write over the existing file or write a new file.
$workbook->SaveAs('/Users/Rtucker/Desktop/Report.xls');

# -------> END CREATE REPORT HERE <-------


#Return to the main screen
print "Sign in complete, hit back to return to the main screen \n";
print "<input type='button' value='Return to main menu' onclick='javascript:history.back(1);' />";

}


rekcut01
Novice

May 9, 2014, 6:59 AM

Post #2 of 2 (2525 views)
Re: [rekcut01] Add Image to excel [In reply to] Can't Post

I keep getting this error, can anyone shed some light on what I'm doing wrong????

Can't locate object method "insert_image" via package "Spreadsheet::ParseExcel::SaveParser::Worksheet" at C:/Program Files (x86)/Apache Group/Apache2/cgi-bin/sqlconfig.pl line 158

Thanks in advance

Rick

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives