Hi, Please look into this problem. See the code below: Here i am loading workbook object without specifying loadOptions. Since the file i am processing is corrupted it will throw exception. In catch block if i try to rename the file by using java's file.renameTo it fails to rename the file. Programm executes successfuly but file is not renamed. If i use loadOptions while creating workbook object then too exception is thrown but the file is then successfully renamed. It seems like when i load workbook object without specifying the loadOptions then even in catch block that file is reffered or is in use somewhere. So it fails to rename it. even by setting workbook object to null it fails. please test this with any corrupted file which will throw exception.
public static void main(String[] args) {
String filePath1 = "AnyCorruptedXlsFileWhichThrowsException";
String filePath2 = "NewName";
com.aspose.cells.Workbook wb = null;
File file1 = new File(filePath1);
LoadOptions loadOptions = new LoadOptions(FileFormatType.EXCEL_97_TO_2003);
try {
wb = new com.aspose.cells.Workbook(filePath1);
// wb = new com.aspose.cells.Workbook(filePath1,loadOptions);
} catch (Exception ce) {
try {
File file2 = new File(filePath2);
file1.renameTo(file2);
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
Thanks & Regards,
Rohan Naik
Hi,
Thank you for reporting the issue. Can you please provide us your sample corrupted file? This will help us investigate further and look into the issue.
Thanks and Best Regards,
Hi, I cannot post the file i am working on. It would be great if you are able to build any file which will fail to load by
wb = new com.aspose.cells.Workbook(filePath1); and throw exception at this line then you can reproduce the problem described above.
Thanks & Regards,
Rohan Naik
Hi,
Thanks for your input.
Please download and use the latest version:
Aspose.Cells
for Java v7.2.0.6
It should fix the problem as mentioned by you.
If the problem still occurs, then I am afraid, we will need your source xls/xlsx file as mentioned by us in the above post to replicate this issue at our end.
Please also let us know the exception you are getting. It will help us fixing the problem.
Hi, I am getting following exception with my xls file:
java.lang.ClassCastException: Overflow in String to int conversion. String value: 18.4.
complete stacktrace:
java.lang.ClassCastException: Overflow in String to int conversion. String value: 18.4.
at com.aspose.cells.b.a.e.f(Unknown Source)
at com.aspose.cells.kj.d(Unknown Source)
at com.aspose.cells.kk.a(Unknown Source)
at com.aspose.cells.kq.o(Unknown Source)
at com.aspose.cells.kq.l(Unknown Source)
at com.aspose.cells.kr.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
Tried with latest version too. But the problem still exists. Can you build a corrupted file which will throw exception at:
wb = new com.aspose.cells.Workbook(filePath1);
and check. Why that rename fails. I think its failing because that workbook object after exception remains in use.
Thanks & Regards,
Rohan Naik
Hi,
We are sorry but without your source file, we won't be able to find out the issue that you are reporting. We can make this thread private so that the file you share is not visible to any other forum members. At Aspose, we give utmost importance to our user's privacy and their data. I hope you understand our concerns.
Thanks and Best Regards,
Hi. Though you are assuring about the privacy by making the thread as private, but still my company privacy policy won't allow me to post the working file. The exception i am getting is as given below.
I am not bothered about the exception actually. My problem is if i catch this exception in catch block and if i try to do a java file.renameTo() on the same file in catch block, then it does not work. It does not give any exception at this file.renameTo() line. But the file fails to rename. May be when such exception occurs the file is still being reffered so it fails to rename. It would be great if your team is able to work it out with these details.
Note: My ultimate intention is to rename the file when the above exception occurs.
The exception i get is as below:
java.lang.ClassCastException: Overflow in String to int conversion. String value: 14.4.
at com.aspose.cells.b.a.e.f(Unknown Source)
at com.aspose.cells.kx.d(Unknown Source)
at com.aspose.cells.ky.a(Unknown Source)
at com.aspose.cells.kE.o(Unknown Source)
at com.aspose.cells.kE.l(Unknown Source)
at com.aspose.cells.kF.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
Hi,
Thank you for your feedback. I try to reproduce the issue at my end and will update you after this.
Hi,
I was unable to reproduce the issue at my end. I tried renaming the attached corrupt excel file and the program renamed it successfully. I have used the following lines of code to achieve this (actually its your code with file names changed only):
String filePath1 = “E:\pivottable.xls”;
String filePath2 = "E://NewName.xls";
com.aspose.cells.Workbook wb = null;
File file1 = new File(filePath1);
LoadOptions loadOptions = new LoadOptions(FileFormatType.EXCEL_97_TO_2003);
wb = new com.aspose.cells.Workbook(filePath1);
// wb = new com.aspose.cells.Workbook(filePath1,loadOptions);
File file2 = new File(filePath2);
Though it is very difficult for our development team to investigate an issue that can't be reproduced at our end due to the absence of source files that are causing the problem, I am still forwarding this matter to our development team to have a word from them about this. We will let you know once we get any update from our development team.
The issue has been logged as: CELLSJAVA-40196.
Hi Rohan,
After further looking into the issue, we have created one corrupted xls file by ourselves and tested the File.rename() function in the catch block. We found the file can be renamed successfully. So, we are afraid we cannot figure the issue out without your actual code and template file.
This has been tested with Xlsx file as well.
Hi Kashif,
Thanks for all the patience first of all. Even when i create some corrupted file which gives CellsException, i am able to rename the file in catch block. The problem arises when i get the exception mentioned in the above posts. Only in that case it fails to rename in the catch block!
Thanks & Regards,
Rohan Naik
Hi Rohan,
Well as you suggested we tried it with a corrupted excel file, but were not able to reproduce the issue. Even if you can send us some of the string contents of your excel file, we can give it a try and see if we can reproduce the issue. Or please populate a new xls file with some similar string contents and see if you can reproduce the issue again.
I am sorry but, without your source/template file and your source code, we won’t be able to reproduce this issue and investigate it further. We appreciate your understanding of our concern.
Hi,
Ok. Thanks for the efforts. Will look for some workaround.
Regards,
Rohan Naik
You are welcome and we will feel happy for helping you out to our best.
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan