Bug 56146

Summary: coerceValueToString does not return an empty string when given a MissingArgEval parameter
Product: POI Reporter: cquezel
Component: SS CommonAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: minor CC: ian.giguere
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Fixed usage of cell reference in Quotient Function

Description cquezel 2014-02-17 17:01:54 UTC
When dealing with spreadsheets (tested Excel and LibreOfice) when a function is called with a missing parameter, they sometimes provide a default empty string parameter.

I noticed this with the substitute function:

SUBSTITUTE( text, old_text, new_text, [nth_appearance] )

In the spreadsheet I was using, the mandatory "new_text" parameter was not specified. Excel and LibreOffice both provided a default empty string.

I think the POI behaviour to throw an exception is correct (althought the error message is not very usefull) but, if the goal is to be compatible with Excel, then the behviour should probably be changed.

	public static String coerceValueToString(ValueEval ve) {
		if (ve instanceof StringValueEval) {
			StringValueEval sve = (StringValueEval) ve;
			return sve.getStringValue();
		}
		if (ve == BlankEval.instance) {
			return "";
		}
// Start of patch 
		if (ve == MissingArgEval.instance) {
			return "";
		}
// End of patch
		throw new IllegalArgumentException("Unexpected eval class (" + ve.getClass().getName() + ")");
	}
Comment 1 Ian Giguère 2019-04-19 12:43:57 UTC
Created attachment 36536 [details]
Fixed usage of cell reference in Quotient Function

I work with cquezel.

I checked out the trunk and edited Quotient.java to de-reference cell references in Quotient function. I also added a line in the QuotientFunctionTestCaseData.xls test file to test having a cell reference as a numerator and denominator.