0

I have converted .xls file to .ods by using below command in terminal

COMMAND : soffice --headless --convert-to ods abcd.xls

After conversion I am not able to read fileName.ods using SpreadSheet API of jOpenDocument1.3.jar. When ever I try to read .ods file it will throw NullPointer Exception .

I am working in Ubuntu platform, if I convert .xls file to .ods using LibreOffice then it is working fine but if I convert it using soffice terminal then it is throwing exception!.

Is there any way to convert file(s) using command line, so that Java code able to read it properly.

I am using below code to read converted fileName.ods file .

File file = new File(path);
String sheetName = "SheetName"; // spread Sheet Name
Sheet sheet = SpreadSheet.createFromFile(file).getSheet(sheetName);

"createFromFile" is giving NullPointer Exception

ava.lang.NullPointerException
    at org.jopendocument.dom.ODPackage.getODDocument(Unknown Source)
    at org.jopendocument.dom.ODPackage.getSpreadSheet(Unknown Source)
    at org.jopendocument.dom.spreadsheet.SpreadSheet.createFromFile(Unknown Source)
    at com.thales.dbtool.controller.DBManageController.getUiParamsFromExcel(DBManageController.java:1316)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandl

Any help will be appreciated.

Rajesh Hatwar
  • 1,843
  • 6
  • 39
  • 58
  • 1
    Check if `file.exists()`. I would bet on that. PS : That's wonderful to have a nice [java doc](https://www.jopendocument.org/docs/org/jopendocument/dom/spreadsheet/SpreadSheet.html#createFromFile(java.io.File)) ! That's helping... – AxelH May 11 '17 at 09:02
  • @AxelH file.exists() it is giving true, I able to get file object as well – Rajesh Hatwar May 11 '17 at 09:07
  • I found this page showing the same kind of error : https://github.com/mmulqueen/odswriter/issues/4 – St3an May 11 '17 at 09:14
  • Include the jopendocument source jar in your project to find the actual problem. If I trust [grepcode](http://grepcode.com/file/repo1.maven.org/maven2/org.jopendocument/jOpenDocument/1.3/org/jopendocument/dom/ODPackage.java#ODPackage.getODDocument%28%29), either `this.getContentType()` returns null in `final ContentType ct = this.getContentType().getType();` or `ct` is assigned `null`in that statement. – Axel May 11 '17 at 09:21
  • Oh, if `file.exists()` returns `true`, what do `file.isDirectory()` and `file.canRead()` return? – Axel May 11 '17 at 09:23
  • Meh, just [some poor code](https://github.com/denixx/jOpenDocument-1.3/blob/master/src/main/java/org/jopendocument/dom/ODPackage.java#L607-L618). He's calling `getContentType()` method while it simply returns `this.type`. (Yet `this.type` is used more frequently...) Iff you look to the usage of `this.type` (especially initializations) in that package... then * shivers *. Eh, look also at [`createFromFile`](https://github.com/denixx/jOpenDocument-1.3/blob/master/src/main/java/org/jopendocument/dom/ODPackage.java#L260) – KarelG May 11 '17 at 09:23
  • @Axel file.isDirectory() is giving false and file.canRead() is true – Rajesh Hatwar May 11 '17 at 09:33
  • A comment in the constructor said "_fill in the missing types from the manifest, if any_". Since this is not working with `soffice`, I would guess it didn't fill the "manifest" corretly, so the type is never defined.(thanks to @KarelG for the github). It's only a guess for now. – AxelH May 11 '17 at 09:41
  • soffice --headless --convert-to ods abcd.xls : this command convert the file which is larger then the actual file .if actual abcd.xls file is 1.9 mb then converted abcd.ods file size is 14.5 mb ,is conversion is not correct ,is it missing any header ? – Rajesh Hatwar May 11 '17 at 09:52

0 Answers0