【问题标题】:Exception with new WordDocument() com.independentsoftnew WordDocument() com.independentsoft 的异常
【发布时间】:2018-05-30 15:03:24
【问题描述】:

我在 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)`

【问题讨论】:

    标签: java independentsoft


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你应该检查你在异常中得到的消息:它说

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

      在代码中的某处,您尝试从 String 生成 Integer,但该 Integer 无法转换Integer
      在您的情况下:11340.0:虽然数学值是一个整数值,但 Java 理解它是 FloatDouble,因为结尾 .0 并引发异常。

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

      【讨论】:

      • 感谢您的回答!但我认为我的代码中没有问题。当我更改模板 .docx 文件时引发此异常。可能是这个文件的问题(可能是表格宽度),但我不知道,究竟在哪里以及我应该怎么做才能修复它:“在 com.independentsoft.office.word.tables.Width.a(未知来源) "
      猜你喜欢
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      相关资源
      最近更新 更多