Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

phpexcel 1.8.1 Calculation error #1176

Open
ScorpioRen opened this issue Apr 7, 2017 · 6 comments
Open

phpexcel 1.8.1 Calculation error #1176

ScorpioRen opened this issue Apr 7, 2017 · 6 comments

Comments

@ScorpioRen
Copy link

ScorpioRen commented Apr 7, 2017

Expected Value is 12.1848172419427 (from function getOldCalculatedValue)
Calculated Value is 5.272696389978087 (from function getCalculatedValue)

I'm read a excel , the office result value is 12.18...... but the phpexcel read result is 5.2

@MarkBaker
Copy link
Member

Entirely possible.... getOldCalculatedValue() isn't guaranteed. It's an old value that is stored in the spreadsheet file that you've loaded, but can be disabled from within MS Excel, or erroneous if a formula requires access to external files that aren't accessible, or the file has been opened and recalculated using other programs.

But how can you possibly expect us to know whether either figure is right or wrong without providing details of the formula, values, etc?

@ScorpioRen
Copy link
Author

ok, this upload file is my use excel file i read is sheet index of 11 cell D28 and E28, Thank you for your reply
modeData.zip

@ScorpioRen
Copy link
Author

Hi,MarkBaker I use the java poi to read the excel from give you excel file ,I get a right result, so i think is bug? i don't no ,so .....

@ScorpioRen
Copy link
Author

ScorpioRen commented Apr 10, 2017

import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFCell;

         
        File file = new File(path);
	FileInputStream fis = new FileInputStream(file);`
	//XSSF
	XSSFWorkbook xssfWorkBook = new XSSFWorkbook(fis);
	XSSFSheet sheet0 = xssfWorkBook.getSheetAt(0);
	XSSFCell  xssfCell = sheet0.getRow(26).getCell(2);
	switch (xssfCell.getCellType()) {
		 case HSSFCell.CELL_TYPE_NUMERIC:
			double  val = xssfCell.getNumericCellValue();
			System.out.println(val);
	                break;
                case HSSFCell.CELL_TYPE_STRING:
			String val2 = xssfCell.getStringCellValue() + "";
		    	System.out.println(val2);
		    	break;
	        default:
		    	String val3 = "";
		    	System.out.println(val3);
		}
		//xssfCell.setCellValue(3.0);
		XSSFSheet sheet11 = xssfWorkBook.getSheetAt(11);
		XSSFFormulaEvaluator eva = new XSSFFormulaEvaluator(xssfWorkBook);
		double result = eva.evaluate(sheet11.getRow(24).getCell(3)).getNumberValue();
		System.out.println(result);

@ScorpioRen
Copy link
Author

this is PhpSpreadsheet code but this result is same to phpExcel
$filename = __DIR__ . '/templates/modeData.xlsx';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($filename);
$reader->setReadDataOnly(true);
$excel = $reader->load($filename);

$sheet = $excel->getSheet(11);

$val = $sheet->getCell('D28')->getCalculatedValue();
echo $val. "\n";

$val = $sheet->getCell('E28')->getCalculatedValue();
echo $val,PHP_EOL; exit();`

@ScorpioRen
Copy link
Author

hi, @MarkBaker I'm looking forward to your reply

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants