Exception with new WordDocument() com.independentsoft

146 Views Asked by At

I have existing working project on java. I need to change template ".docx" document. When I'm trying to create a new WordDocument with another ".docx" document, I get an exception. What can be wrong? Sorry for my english.

There is a my code:

`WordDocument document = new WordDocument(templatesDirectory + "order.docx");`

There is a stacktrace:

`java.lang.NumberFormatException: For input string: "11340.0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at com.independentsoft.office.word.tables.Width.a(Unknown Source)
at com.independentsoft.office.word.tables.Width.<init>(Unknown Source)
at com.independentsoft.office.word.tables.TableProperties.a(Unknown Source)
at com.independentsoft.office.word.tables.TableProperties.<init>(Unknown Source)
at com.independentsoft.office.word.tables.Table.a(Unknown Source)
at com.independentsoft.office.word.tables.Table.<init>(Unknown Source)
at com.independentsoft.office.word.Body.a(Unknown Source)
at com.independentsoft.office.word.Body.<init>(Unknown Source)
at com.independentsoft.office.word.WordDocument.a(Unknown Source)
at com.independentsoft.office.word.WordDocument.openImplementation(Unknown Source)
at com.independentsoft.office.word.WordDocument.open(Unknown Source)
at com.independentsoft.office.word.WordDocument.open(Unknown Source)
at com.independentsoft.office.word.WordDocument.<init>(Unknown Source)`
2

There are 2 best solutions below

1
avi.elkharrat On

You should check out the message you get in the Exception: it says

java.lang.NumberFormatException: For input string: "11340.0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)

Somewhere in your code you are trying to generate an Integer from a String that cannot be converted to an Integer.
In your case: 11340.0: although the mathematical value is an integer value, Java understands that it is a Float or a Double because of the ending .0 and raises an exception.

Try to find where that convertion occurs from and see if you can catch / manage the exception.

0
KseniyaK On

The problem was solved! The problem was in a file, it was saved with google docs. Now I resave it with MSOffice, and so code works!