Usando Aspose.Cells for Java con Perl

Software e librerie richiesti

Sono richiesti il software e le librerie seguenti.

  • Perle.
  • Aspose.Cells for Java.
  • Java - Estensione Perl.
  • Java runtime che soddisfa i requisiti dell’estensione Aspose.Cells for Java e Java-Perl.

Guida

Per chiamare uno Java API in Perl, devi prima installare l’estensione Java-Perl per Perl. (Ai fini di questo articolo, presumiamo che Perl sia stato installato e impostato correttamente.) È possibile ottenere l’estensione Java-Perl daMetzzo/Java-4.7/

Alla fine di questo documento, c’è un esempio di script Perl che chiama Aspose.Cells for Java. Per eseguirlo, attenersi alla seguente procedura:

  1. Scarica il file Java-4.7.tar.gz e decomprimilo sull’unità locale.
  2. Installa questo pacchetto per Perl.
  3. Avvia JavaServer. Il comando sarà:
 java -classpath ...  com.zzo.javaserver.JavaServer 

dove … è il classpath che deve includere tutte le librerie richieste dalla tua applicazione.

Per utilizzare Aspose.Cells for Java, deve contenere almeno due file JAR:

  1. Aspose.Cells.jar dal Aspose.Cells for Java
  2. javaserver.jar da Java-4.7.tar.gz
  3. Eseguire lo script Perl che richiama Aspose.Cells for Java API.

Per ulteriori informazioni su come lavorare con Java in Perl, vedere la documentazione di Java - estensione Perl suhttps://metacpan.org/release/METZZO/Java-4.7

Java

 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->get(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";