Commit bf24c4e8 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink
Browse files

handle intersection operators better, there are probably still some cases that...

handle intersection operators better, there are probably still some cases that are not fully correct, but this at least improves things a lot
CCBUG: 244414
This doesn't solve the bug completely yet, since calligra-tables doesn't support the intersection operator, but it at least the odf generated by the xlsx filter now has the correct formula
parent 48a48457
......@@ -59,6 +59,9 @@ void TestFormulaParser::testConvertFormula_data()
QTest::newRow("whitespace in normal arguments")
<< "IF(A1=A2, 2, \" IF(1,2) \")"
<< "=IF(A1=A2; 2; \" IF(1,2) \")";
QTest::newRow("multiple whitespace in normal arguments")
<< "IF(A1=A2 , 2 , \" IF(1,2) \")"
<< "=IF(A1=A2 ; 2 ; \" IF(1,2) \")";
QTest::newRow("mixing union and intersection")
<< "AREAS((A1:C5 B2:B3,C2:C3))"
<< "=AREAS((A1:C5!B2:B3~C2:C3))";
......@@ -71,6 +74,12 @@ void TestFormulaParser::testConvertFormula_data()
QTest::newRow("Sheetname")
<< "=IF('Sheet 1'!A1,''Sheet '1''!A2,'''Sheet 1'''!A3"
<< "=IF('Sheet 1'!A1;'Sheet ''1'!A2;'Sheet 1'!A3";
QTest::newRow("intersection operator without extra parenthesis")
<< "AREAS(B2:D4 B2)"
<< "=AREAS(B2:D4!B2)";
QTest::newRow("intersection operator without extra parenthesis, extra whitespace")
<< "AREAS(B2:D4 B2)"
<< "=AREAS(B2:D4! B2)";
}
void TestFormulaParser::testConvertFormula()
......
......@@ -768,6 +768,19 @@ QString Calligra::Tables::MSOOXML::convertFormula(const QString& formula)
result[i] = ';'; // replace argument delimiter
else if (ch == '(' && !result[i-1].isLetterOrNumber())
state = InParenthesizedArgument;
else if (ch == ' ') {
// check if it might be an intersection operator
// for it to be an intersection operator the next non-space char must be a cell-name-character or '
int firstNonSpace = i+1;
while (firstNonSpace < result.length() && result[firstNonSpace] == ' ') {
firstNonSpace++;
}
bool isIntersection = firstNonSpace < result.length() && (result[firstNonSpace].isLetter() || result[firstNonSpace] == '$' || result[firstNonSpace] == '\'');
if (isIntersection) {
result[i] = '!';
i = firstNonSpace-1;
}
}
break;
case InParenthesizedArgument:
if (ch == ',')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment