midrange.com code scratchpad
Name:
John Rusling
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/02/2014 03:08:33 pm
IP:
Logged
Description:
Snip of rpg code to use poi36 formula evaluator
Code:
  1.         // this code is in addition to the hssfr4 code
  2.         //  it provides the formula evaluator functionality (i believe)
  3. eeee  // Support objects/prototypes for formula evaluator, these are used
  4.  .    //  to extract numeric values from a formula type cell that
  5.  .    //  calculates a numeric value.
  6.      d CELL_VALUE_CLASS...
  7.      d                 c                   'org.apache.poi.ss.usermodel-
  8.      d                                     .CellValue'
  9.      d CellValue...
  10.      d                 s               o   class(*JAVA: CELL_VALUE_CLASS)
  11.      d new_CellValue...
  12.      d                 pr                  like(CellValue)
  13.      d                                     extproc(*JAVA:
  14.      d                                     CELL_VALUE_CLASS:
  15.      d                                     *constructor)
  16.      d   value                             like(jDouble) value
  17.      d CellValue_getCellType...
  18.      d                 pr                  like(jInt)
  19.      d                                     extproc(*JAVA:
  20.      d                                     CELL_VALUE_CLASS:
  21.      d                                     'getCellType')
  22.      d CellValue_getNumberValue...
  23.      d                 pr                  like(jDouble)
  24.      d                                     extproc(*JAVA:
  25.      d                                     CELL_VALUE_CLASS:
  26.      d                                     'getNumberValue')
  27.       // Evaluate a formula and return the value, leaving the original cell intact
  28.       //  because FormulaEvaluator is an interface and cant directly create one
  29.      d FORMULA_EVALUATOR_CLASS...
  30.      d                 c                   'org.apache.poi.ss.usermodel-
  31.      d                                     .FormulaEvaluator'
  32.      d FormulaEvaluator...
  33.      d                 s               o   class(*JAVA: FORMULA_EVALUATOR_CLASS)
  34.      d CreationHelper_createFormulaEvaluator...
  35.      d                 pr                  like(formulaEvaluator)
  36.      d                                     extproc(*java:
  37.      d                                     CREATIONHELPER_CLASS:
  38.      d                                     'createFormulaEvaluator')
  39.      d evaluate...
  40.      d                 pr                  like(CellValue)
  41.      d                                     extproc(*JAVA:
  42.      d                                     FORMULA_EVALUATOR_CLASS:
  43.      d                                     'evaluate')
  44.      d   cell                              like(SSCell)
  45.       *SSWorkbook_getCreationHelper in HSSFCGI/QRPGLESRC2(HSSF_H) here it is for reference:
  46.      d HSSF_CREATIONHELPER_CLASS...
  47.      d                 c                   'org.apache.poi.hssf.usermodel-
  48.      d                                     .HSSFCreationHelper'
  49.      d HSSFCreationHelper...
  50.  .   d                 s               o   class( *java
  51.  .   d                                          : HSSF_CREATIONHELPER_CLASS )
  52. eeee d helper          s                   like(SSCreationHelper)
  53.  
  54. calcs. . .
  55.  
  56.        //*********************************************************************
  57.        begsr @process;
  58.  
  59.        // Subr =
  60.        //*********************************************************************
  61.  
  62.          ss_begin_object_group(1000);
  63.  
  64.          // Open an existing spreadsheet
  65.          book = ss_open(gSSPathFile);
  66.          if (book = *null);
  67.            Complain('Unable to open workbook!');
  68.          endif;
  69.  
  70.          // Set the worksheet to read
  71.          sheet = ss_getSheet(book:gSheet);
  72.          if (sheet = *null);
  73.            Complain('Sheet not in workbook!');
  74.          endif;
  75.  
  76. eeee     // Do this after workbook is opened to be able to evaluate formulas
  77. eeee     helper = SSWorkbook_getCreationHelper(book);
  78. eeee     formulaEvaluator = creationHelper_createFormulaEvaluator(helper);
  79.  
  80.          // set row, col to read
  81.          gCol = col_B;
  82.          gRow = row_4;
  83.          setRow(gRow);
  84.          setCell(gCol);
  85.  
  86. eeee  myNbr = extractNumericValue(cell);
  87.  
  88.          //gResultSS = '/johnr/tspoi8 results.xlsx';
  89.          //ss_save(book:gResultSS);
  90.          ss_end_object_group();
  91.  
  92.          msg_User(psds.User:'Calculated formula value is... ' + %char(myNbr));
  93.  
  94.        endsr;
  95.  
  96.  
  97.  
© 2004-2019 by midrange.com generated in 0.008s valid xhtml & css