Created attachment 37809 [details] test case for blank cells in range calc Hi, attached excel file shows different Excel/poi 4.1.2 Slope/Intercept calcs caused by the slope/intercept cell range containing blank cells. Code use to generate Excel file: public static void main(String[] args) { try { File initialFile = new File( "C:\\Users\\twelch\\eclipse-workspace\\Main\\test_excel\\test_slope_intercept.xlsx"); InputStream is = new FileInputStream(initialFile); XSSFWorkbook workbook = new XSSFWorkbook(is); is.close(); // Excel formulas : D2 slope, D3 intercept // evaluate and save results in F2, F3 XSSFCell slopeCell = cellAtAddr(workbook, "Sheet1!D2"); XSSFCell interceptCell = cellAtAddr(workbook, "Sheet1!D3"); evalCellSaveAtAddr(workbook, slopeCell, "Sheet1!F2"); evalCellSaveAtAddr(workbook, interceptCell, "Sheet1!F3"); workbook.setForceFormulaRecalculation(true); File outFile = new File( "C:\\Users\\twelch\\eclipse-workspace\\Main\\test_excel\\test_slope_intercept.xlsx"); FileOutputStream os = new FileOutputStream(outFile); workbook.write(os); os.close(); } catch (Exception e) { e.printStackTrace(); } } public static XSSFCell cellAtAddr(XSSFWorkbook workbook, String cellAddr) { CellReference cr = new CellReference(cellAddr); XSSFRow row = workbook.getSheet(cr.getSheetName()).getRow(cr.getRow()); if (row == null) row = workbook.getSheet(cr.getSheetName()).createRow(cr.getRow()); XSSFCell cell = row.getCell(cr.getCol()); if (cell == null) cell = row.createCell(cr.getCol()); return cell; } public static void evalCellSaveAtAddr(XSSFWorkbook workbook, XSSFCell evalCell, String destCellAddr) { FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); XSSFCell destCell = cellAtAddr(workbook, destCellAddr); evaluator.evaluateFormulaCell(evalCell); double dval = evalCell.getNumericCellValue(); destCell.setCellValue(dval); }
Created attachment 37825 [details] bug fix using org.apache.commons.math3.stat.regression.SimpleRegression
Created attachment 37826 [details] add Excel RSQ implementation using org.apache.commons.math3.stat.regression.SimpleRegression
Created attachment 37827 [details] Excel RSQ implementation using org.apache.commons.math3.stat.regression.SimpleRegression
Created attachment 37828 [details] changed header doc using org.apache.commons.math3.stat.regression.SimpleRegression
Created attachment 37829 [details] changed header doc using org.apache.commons.math3.stat.regression.SimpleRegression
Created attachment 37830 [details] test case test case for changes
Created attachment 37831 [details] changed header doc using org.apache.commons.math3.stat.regression.SimpleRegression
run test case public static void main(String[] args) { try { File excleFile = new File( "C:\\Users\\twelch\\eclipse-workspace\\Main\\test_excel\\test_slope_intercept_rsquare.xlsx"); InputStream is = new FileInputStream(excleFile); XSSFWorkbook workbook = new XSSFWorkbook(is); is.close(); // Excel formulas : D2 slope, D3 intercept, D4 RSquare // evaluate and save results in F2, F3 XSSFCell slopeCell = cellAtAddr(workbook, "Sheet1!D2"); XSSFCell interceptCell = cellAtAddr(workbook, "Sheet1!D3"); XSSFCell rSquareCell = cellAtAddr(workbook, "Sheet1!D4"); evalCellSaveAtAddr(workbook, slopeCell, "Sheet1!F2"); evalCellSaveAtAddr(workbook, interceptCell, "Sheet1!F3"); evalCellSaveAtAddr(workbook, rSquareCell, "Sheet1!F4"); workbook.setForceFormulaRecalculation(true); FileOutputStream os = new FileOutputStream(excleFile); workbook.write(os); os.close(); } catch (Exception e) { e.printStackTrace(); } }