Trouble using Aspose.Cells for Java on a UNIX environment

Hi,

I have some trouble to use Aspose.Cells for Java 1.4 on a Unix environment.

When I try to open an Excel-workbook like this


Workbook aWorkbook = new Workbook();
InputStream in = getClass().getResourceAsStream("template.xls");
aWorkbook.open(in);

I get the following error message:

[ 6606] [08.09.06 14:30:16:834 IRDT] 00000021 SystemErr R java.lang.StringIndexOutOfBoundsException: String index out of range: 8222
[ 6607] at java.lang.String.checkBounds(String.java:287)
[ 6608] at java.lang.String.(String.java:319)
[ 6609] at com.aspose.cells.Z.(Unknown Source)
[ 6610] at com.aspose.cells.aO.b(Unknown Source)
[ 6611] at com.aspose.cells.aO.a(Unknown Source)
[ 6612] at com.aspose.cells.aO.(Unknown Source)
[ 6613] at com.aspose.cells.Workbook.open(Unknown Source)
[ 6614] at com.aspose.cells.Workbook.open(Unknown Source)
[ 6615] at com.bhfbank.custodyreporting.report.misreport.workbook.AbstractMISReportWorkbook.(AbstractMISReportWorkbook.java:94)

When I run my prorgram on a windows-environment everything is fine.

I'm using just two .jars out of the lib-directory (the 1.4 edition of Aspose.Cells.jar and retrotranslator-runtime-0.9.8.jar)

Exact Version of OS and VM is:

Host Operating System is SunOS, version 5.8
Java version = 1.4.2_05, Java Compiler = null, Java VM name = Java HotSpot(TM) Client VM

Any help is appreciated.

Thanks in advance.

Cheers,

Stephan

Can this problem be related to the different character encodings on the machine, which created the Excel-File and the machine running Aspose.Cells? Because in Java a byte-array is always transformed into a String via the default plattform character encoding?

Could you please post your template file here?

I’ll check this ASAP.

okay,

it seems as if getResourceAsStream(...)-method is the key to my problem.

Now we have a servlet running on the unix-machine, which takes excel-template files as an upload and which writes them back to the outputstream, producing perfect copies of the original template files using Aspose.Cells.

But if the servlet uses getResourceAsStream(...) I still receive the mentioned exception.

Interesting thing is, that I also have very simple excel-files, which could be read by the getResourceAsStream()-method.

Hi,

well, we found a way to overcome the described exception.

The following code fragment is not working on the SUN plattform for some excel files, but is working on Windows:


in = getClass().getResourceAsStream("template.xls");
aTemplate = new Workbook();
aTemplate.open(in); // produces an exception for some excel files on SUN Solaris
in.close();
aTemplate.write(someOutputStream);
someOutputStream.close();

But the following code fragment works for every Excel-File on a Windows AND on the SUN Plattform.


in = getClass().getResourceAsStream("template.xls");

ByteArrayOutputStream outArray = new ByteArrayOutputStream(in.available());

byte b[] = new byte[4096];
int bytesread=0;

while((bytesread=in.read(b))>0) {
outArray.write(b,0,bytesread);
}
in.close();

ByteArrayInputStream bIn = new ByteArrayInputStream(outArray.toByteArray());

aTemplate = new Workbook();
aTemplate.open(bIn);
bIn.close();

out.putNextEntry(new ZipEntry("test1c_writtem.xls"));
aTemplate.write(out);

Yet we don't elaborate the reason for the observed behaviour, we hope this is of use for others which encounter similiar problems.

Maybe the exception is related to the way InputStream-reading is performed within Workbook.open(...).

Bye,

Stephan

Hi,

Please try this fix.

Hi Warren,

thanks for your reply. Unfortunately up to now I didn't have a chance to try your fix. My workaround worked fine for us. We purchased a license for Aspose.Cells for Java. Unfortunately the license file is not recognized on my Unix machine. I receive the following exception:

com.aspose.cells.CellsException: The license is invalid. The signature is invalid.

Of course I haven't opened the license file or altered it in anyway. Can this problem be related to the fact, that the license file is encoded in UTF-8 for DOS and now it is read on a Unix-Machine?

Will your fix solve this issue as well, because my ByteArray-Workaround didn't fix it this time.

Thanks in advance!

Hi,

Please try this fix.If the error still exists,please post your lic file to nanjing@aspose.com

Hi again,

your fix worked, thanks for the quick reply. Now I'm able to pass the .setLicense Method, but I receive an exception when I try to write the created workbook.

[ 3579] java.lang.NoClassDefFoundError: java/math/MathContext
[ 3580] at com.aspose.cells.aA.c(Unknown Source)
[ 3581] at com.aspose.cells.Cell.c(Unknown Source)
[ 3582] at com.aspose.cells.cs.a(Unknown Source)
[ 3583] at com.aspose.cells.cs.g(Unknown Source)
[ 3584] at com.aspose.cells.cs.a(Unknown Source)
[ 3585] at com.aspose.cells.cs.a(Unknown Source)
[ 3586] at com.aspose.cells.G.b(Unknown Source)
[ 3587] at com.aspose.cells.G.b(Unknown Source)
[ 3588] at com.aspose.cells.G.a(Unknown Source)
[ 3589] at com.aspose.cells.Cell.c(Unknown Source)
[ 3590] at com.aspose.cells.cs.a(Unknown Source)
[ 3591] at com.aspose.cells.cs.g(Unknown Source)
[ 3592] at com.aspose.cells.cs.a(Unknown Source)
[ 3593] at com.aspose.cells.cs.a(Unknown Source)
[ 3594] at com.aspose.cells.G.b(Unknown Source)
[ 3595] at com.aspose.cells.G.b(Unknown Source)
[ 3596] at com.aspose.cells.G.b(Unknown Source)
[ 3597] at com.aspose.cells.G.b(Unknown Source)
[ 3598] at com.aspose.cells.G.a(Unknown Source)
[ 3599] at com.aspose.cells.Cell.c(Unknown Source)
[ 3600] at com.aspose.cells.Workbook.calculateFormula(Unknown Source)

I'm still using Java 1.4, not 1.5

Thanks for your support.

Stephan

Hi,

Please try this fix.

Sorry for our mistake that MathContext is since 1.5.We have removed it.

Hi again,

ok, everything seems fine now.

Thanks for your quick reply.

Hi,

not sure if this really fits into this thread but it seems there is still an unresolved Java 1.5 issue in your hotfix. It became necessary, that I use the Excel ROUND(...) function within my excel-template.

Now I get the following exception within the Workbook.calculateFormula()-method:

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Math: method signum(D)D not found
at com.aspose.cells.E.k(Unknown Source)
at com.aspose.cells.E.a(Unknown Source)
at com.aspose.cells.B.b(Unknown Source)
at com.aspose.cells.B.b(Unknown Source)
at com.aspose.cells.B.b(Unknown Source)
at com.aspose.cells.B.b(Unknown Source)
at com.aspose.cells.B.a(Unknown Source
at com.aspose.cells.Cell.b(Unknown Source)
at com.aspose.cells.Workbook.calculateFormula(Unknown Source)

Thanks in advance.

Bye

Stephan

Hi,

We will look into the methods of Math and replace the methods which is since 1.5.