javalotus-noteslotusscriptodfls2j

Has anybody successfully used the ODF "Simple API" from LotusScript to generate documents?


I'm trying to use LS2J to invoke the Simple API for the ODF Toolkit (https://incubator.apache.org/odftoolkit/simple/index.html) from LotusScript, and I've been unable to use it properly.

I've included in a Java library called ODFDOM the following:

With this code in the Sub Initialize of the agent:

Dim js As javasession
Dim jc As Javaclass
Dim jerr As JAVAERROR
Dim jms As JavaMethodCollection
Dim jobj As Javaobject, jdoc As JavaObject
Dim jm As JAVAMETHOD

Set js = New JavaSession
Set jc = js.Getclass("org/odftoolkit/simple/SpreadsheetDocument")
Set jm = jc.GetMethod("newSpreadsheetDocument", "()Lorg/odftoolkit/simple/SpreadsheetDocument;")
Set jdoc = jm.Invoke

execution gives an error:

JS2J Error: Threw java.lang.NullPointerException

Any clues about what am I doing wrong?


Solution

  • You have to "Use" your library "ODFDOM" and get your class in Java notation with dots. You can shorten your code with direct call of your static method:

    Use "ODFDOM"
    Dim js As javasession
    Dim jSpreadsheetDocumentClass As Javaclass
    Dim jdoc As JavaObject
    
    Set js = New JavaSession
    Set jSpreadsheetDocumentClass  = js.Getclass("org.odftoolkit.simple.SpreadsheetDocument")
    Set jdoc = jSpreadsheetDocumentClass.newSpreadsheetDocument()
    

    UPDATE:

    LS2J doesn't work with resources. Whenever you use resources in Java code it won't work with LS2J. After a short look into ODF Toolkit source code I saw resources used.

    So, create an Java agent instead and call it from LotusScript.