0

我有关于java的现有工作项目。我需要更改模板“.docx”文档。当我试图用另一个“.docx”文档创建一个新的 WordDocument 时,我得到了一个例外。有什么问题?对不起我的英语不好。

有一个我的代码:

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

有一个堆栈跟踪:

`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)`
4

2 回答 2

1

问题解决了!问题出在一个文件中,它是用谷歌文档保存的。现在我用 MSOffice 重新保存它,这样代码就可以工作了!

于 2018-05-31T17:02:44.733 回答
0

您应该查看您在异常中收到的消息:它说

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

在您的代码中的某处,您试图IntegerString无法转换Integer.
在您的情况下:11340.0: 尽管数学值是一个整数值,但 Java 理解它是 aFloat或 aDouble因为结尾.0并引发异常。

尝试查找发生转换的位置,看看您是否可以捕获/管理异常。

于 2018-05-30T15:26:46.937 回答