1 2 Previous Next 15 Replies Latest reply on Jan 14, 2016 5:14 PM by 2976336

    XLSX files to PDFs with Peoplecode and Java (XSSFWorkbook)

    2976336

      I'm working on a project to convert Excel .xlsx files to pdf files. I've done some research and found that maybe using Java in Peoplecode is the best way. Correct me if I'm wrong. I'm still quite new on this.

       

      I installed these Java libraries:

      • poi-3.11.jar
      • commons-codec-1.9.jar
      • poi-ooxml-3.11.jar
      • poi-ooxml-schemas-3.11.jar
      • xmlbeans-2.6.0.jar
      • stax-api-1.0.1.jar

       

      I'm trying to use Reflection technique. I started my code to read an .xlsx file and I'm stuck here:

       

      Local string &file_name = "C:\temp\test1.xlsx";

      Local integer &tempint = 0;

       

      Local JavaObject &input_file = CreateJavaObject("java.io.File", &file_name);

      Local JavaObject &XSSFWorkbook = CreateJavaObject("org.apache.poi.xssf.usermodel.XSSFWorkbook", &input_file);

      Local JavaObject &jClass = GetJavaClass("java.lang.Class");

      Local JavaObject &jInt = GetJavaClass("java.lang.Integer");

      Local JavaObject &jIntType = &jInt.TYPE;

      Local JavaObject &jIntArgTypes = CreateJavaObject("java.lang.Class[]", &jIntType);

      Local JavaObject &jGetSheetAt = &XSSFWorkbook.getClass().getDeclaredMethod("getSheetAt", &jIntArgTypes);

       

      Local JavaObject &jSheet1 = &jGetSheetAt.invoke(&XSSFWorkbook, CreateJavaObject("java.lang.Object[]", CreateJavaObject("java.lang.Integer", "0")));

      rem Local JavaObject &jSheet1 = &jGetSheetAt.invoke(&XSSFWorkbook, CreateJavaObject("java.lang.Object[]", 0));

       

      Local JavaObject &jRowIterator = &jSheet1.getClass().getDeclaredMethod("iterator", Null);

      Local JavaObject &jIterator = &jRowIterator.invoke(&jSheet1, CreateJavaObject("java.lang.Object[]"));

       

      rem Local JavaObject &jRowNext = &jIterator.getClass().getDeclaredMethod("next", Null);

      rem Local JavaObject &jNextRow = &jRowNext.invoke(&jIterator, CreateJavaObject("java.lang.Object[]"));

       

      rem Local JavaObject &jRowHasNext = &jIterator.getClass().getDeclaredMethod("hasNext", Null);

      rem Local JavaObject &jHasNext = &jRowHasNext.invoke(&jIterator, CreateJavaObject("java.lang.Object[]"));

       

       

      The last four commented lines are where I'm having a lot of trouble with. I understand eventually I need to put them in a While loop to read each row that has content and within that each cell. But I even can't get that far. I don't seem to be able to call either the next() or the hasNext() methods properly. When I uncomment the first two lines to call next(), it gives me error "Java Exception: java.lang.InternalError: during call of java.lang.reflect.Method.invoke. (2,763) VH_XLTOPDF.MAIN.GBL.default.1900-01-01.Step07.OnExecute  PCPC:1675  Statement:14"

       

      And when I uncomment the last two lines to call hasNext(), it gives error "Java Exception: java.lang.NoSuchMethodException: java.util.TreeMap$ValueIterator.hasNext(): during call of java.lang.Class.getDeclaredMethod. (2,763) VH_XLTOPDF.MAIN.GBL.default.1900-01-01.Step07.OnExecute  PCPC:1539  Statement:13"

       

      Any help would be appreciated. Or if this is the wrong path to go for what I'm trying to achieve, please advice. Thank you very much in advance.

        1 2 Previous Next