Introduction
Aspose.Cells for Java is a pure Java component and you may use it with Perl as we have successfully carried out tests using Aspose.Cells for Java with Perl script. Using the component is just same as invoking other common Java API in Perl. To call any Java library in Perl, you do need to install the Java-Perl extension for Perl first that is needed to to access JVM.
Required Software and Libraries
The following softwares / libraries are required.
- Perl
- Aspose.Cells for Java
- Java - Perl extension
- Java runtime that meets the requirement of Aspose.Cells for Java and Java-Perl extension
Guide
To call Java API in Perl, you need to install the Java-Perl extension for Perl first (It is assumed that Perl has been installed and set properly). You can get the Java-Perl extendsion from http://search.cpan.org/~metzzo/Java-4.7/
At the end of this document, there is an example of Perl script to call Aspose.Cells for Java. To run it, follow the following steps:
1. Download the file "Java-4.7.tar.gz", unzip it to your local drive.
2. Install this package for Perl.
3. Start JavaServer. The command is like:
java -classpath ... com.zzo.javaserver.JavaServer
where the ... is for classpath must include all the libraries required by your application.
For using Aspose.Cells for java, it should contains two jar file at least:
- Aspose.Cells.jar (from Aspose.Cells for Java)
- JavaServer.jar (from Java-4.7.tar.gz)
4. Run the Perl script which invokes the API of Aspose.Cells for Java.
For more information on how to work with java in Perl, see documentation of Java - Perl extension at http://search.cpan.org/~metzzo/Java-4.7/
Example
my $ok = 0;
BEGIN { $| = 1; print "1..33\n"; }
END {print "not ok $ok - is JavaServer on localhost running?\nJavaServer must be running for these tests to function.\n" unless $loaded;}
BEGIN {
print "WARNING: You cannot run these tests unless JavaServer is running!\n";
print "Do you want to continue? (Y/n) ";
my $in = <STDIN>;
exit 1 if ($in =~ /^n/i);
}
use lib '.';
use Java;
my $java = new Java();
$loaded = 1;
$ok++;
print "ok $ok\n";
my $workbook = $java->create_object("com.aspose.cells.Workbook");
$ok++;
print "workbook $ok\n";
#$workbook->open("t.xls");
$ok++;
print "open $ok\n";
my $worksheets = $workbook->getWorksheets();
$ok++;
print "worksheets $ok\n";
my $worksheet = $worksheets->getSheet(0);
$ok++;
print "worksheet $ok\n";
my $cells = $worksheet->getCells();
$ok++;
print "cells $ok\n";
my $cell = $cells->getCell(0,1);
$ok++;
print "cell $ok\n";
$cell->setValue(123);
$cell = $cells->getCell(1,1);
$cell->setValue(456);
$cell = $cells->getCell(2,1);
$cell->setFormula("=SUM(B1:B2)");
$cell = $cells->getCell(3,1);
$cell->setValue("abc");
$workbook->save("t1.xls");
$ok++;
print "save $ok\n";