// // Function: MULTIPLE.OPERATIONS // Value func_multiple_operations(valVector args, ValueCalc *, FuncExtra *e) { if (args.count() != 3 && args.count() != 5) return Value::errorVALUE(); // invalid number of parameters for (int i = 0; i < args.count(); i++) { if (e->ranges[i].col1 == -1 || e->ranges[i].row1 == -1) return Value::errorVALUE(); } CellStorage *s = e->sheet->cellStorage(); // get formula to evaluate int formulaCol = e->ranges[0].col1; int formulaRow = e->ranges[0].row1; Formula formula = s->formula(formulaCol, formulaRow); if (!formula.isValid()) return Value::errorVALUE(); CellIndirection cellIndirections; cellIndirections.insert(Cell(e->sheet, e->ranges[1].col1, e->ranges[1].row1), Cell(e->sheet, e->ranges[2].col1, e->ranges[2].row1)); if (args.count() > 3) { cellIndirections.insert(Cell(e->sheet, e->ranges[3].col1, e->ranges[3].row1), Cell(e->sheet, e->ranges[4].col1, e->ranges[4].row1)); } return formula.eval(cellIndirections); }
// Function: ISFORMULA Value func_isformula(valVector /*args*/, ValueCalc */*calc*/, FuncExtra *e) { const Calligra::Sheets::Region ®ion = e->regions[0]; QPoint p = region.firstRange().topLeft(); CellStorage *s = region.firstSheet()->cellStorage(); Formula formula = s->formula(p.x(), p.y()); return Value(formula.isValid()); }
void TestInformationFunctions::initTestCase() { FunctionModuleRegistry::instance()->loadFunctionModules(); m_map = new Map(0 /* no Doc */); m_map->addNewSheet(); Sheet* sheet = m_map->sheet(0); sheet->setSheetName("Sheet1"); CellStorage* storage = sheet->cellStorage(); // // Test case data set // // A19:A31 storage->setValue(1,19, Value( 1 ) ); storage->setValue(1,20, Value( 2 ) ); storage->setValue(1,21, Value( 4 ) ); storage->setValue(1,22, Value( 8 ) ); storage->setValue(1,23, Value( 16 ) ); storage->setValue(1,24, Value( 32 ) ); storage->setValue(1,25, Value( 64 ) ); storage->setValue(1,26, Value( 128 ) ); storage->setValue(1,27, Value( 256 ) ); storage->setValue(1,28, Value( 512 ) ); storage->setValue(1,29, Value( 1024 ) ); storage->setValue(1,30, Value( 2048 ) ); storage->setValue(1,31, Value( 4096 ) ); // B1:B2 Formula formula(sheet); formula.setExpression("=SUM(A19:A31)"); storage->setFormula(2,1, formula); storage->setFormula(2,2, Formula::empty()); // B3:B17 storage->setValue(2, 3, Value("7")); storage->setValue(2, 4, Value(2)); storage->setValue(2, 5, Value(3)); storage->setValue(2, 6, Value(true)); storage->setValue(2, 7, Value("Hello")); // B8 leave empty storage->setValue(2, 9, Value::errorDIV0()); storage->setValue(2, 10, Value(0)); // storage->setValue(2,11, Value( 3 ) ); // storage->setValue(2,12, Value( 4 ) ); // storage->setValue(2,13, Value( "2005-0131T01:00:00" )); // storage->setValue(2,14, Value( 1 ) ); // storage->setValue(2,15, Value( 2 ) ); // storage->setValue(2,16, Value( 3 ) ); // storage->setValue(2,17, Value( 4 ) ); // // // // C4:C7 storage->setValue(3, 4, Value(4)); storage->setValue(3, 5, Value(5)); // storage->setValue(3, 6, Value( 7 ) ); storage->setValue(3, 7, Value("2005-01-31")); // C11:C17 storage->setValue(3,11, Value( 5 ) ); storage->setValue(3,12, Value( 6 ) ); storage->setValue(3,13, Value( 8 ) ); storage->setValue(3,14, Value( 4 ) ); storage->setValue(3,15, Value( 3 ) ); storage->setValue(3,16, Value( 2 ) ); storage->setValue(3,17, Value( 1 ) ); // // C19:C31 // storage->setValue(3,19, Value( 0 ) ); // storage->setValue(3,20, Value( 5 ) ); // storage->setValue(3,21, Value( 2 ) ); // storage->setValue(3,22, Value( 5 ) ); // storage->setValue(3,23, Value( 3 ) ); // storage->setValue(3,24, Value( 4 ) ); // storage->setValue(3,25, Value( 4 ) ); // storage->setValue(3,26, Value( 0 ) ); // storage->setValue(3,27, Value( 8 ) ); // storage->setValue(3,28, Value( 1 ) ); // storage->setValue(3,29, Value( 9 ) ); // storage->setValue(3,30, Value( 6 ) ); // storage->setValue(3,31, Value( 2 ) ); // // C51:C57 // storage->setValue(3,51, Value( 7 ) ); // storage->setValue(3,52, Value( 9 ) ); // storage->setValue(3,53, Value( 11 ) ); // storage->setValue(3,54, Value( 12 ) ); // storage->setValue(3,55, Value( 15 ) ); // storage->setValue(3,56, Value( 17 ) ); // storage->setValue(3,57, Value( 19 ) ); // // // D51:D57 // storage->setValue(4,51, Value( 100 ) ); // storage->setValue(4,52, Value( 105 ) ); // storage->setValue(4,53, Value( 104 ) ); // storage->setValue(4,54, Value( 108 ) ); // storage->setValue(4,55, Value( 111 ) ); // storage->setValue(4,56, Value( 120 ) ); // storage->setValue(4,57, Value( 133 ) ); // // // // F51:F60 // storage->setValue(6,51, Value( 3 ) ); // storage->setValue(6,52, Value( 4 ) ); // storage->setValue(6,53, Value( 5 ) ); // storage->setValue(6,54, Value( 2 ) ); // storage->setValue(6,55, Value( 3 ) ); // storage->setValue(6,56, Value( 4 ) ); // storage->setValue(6,57, Value( 5 ) ); // storage->setValue(6,58, Value( 6 ) ); // storage->setValue(6,59, Value( 4 ) ); // storage->setValue(6,60, Value( 7 ) ); // // // // G51:G60 // storage->setValue(7,51, Value( 23 ) ); // storage->setValue(7,52, Value( 24 ) ); // storage->setValue(7,53, Value( 25 ) ); // storage->setValue(7,54, Value( 22 ) ); // storage->setValue(7,55, Value( 23 ) ); // storage->setValue(7,56, Value( 24 ) ); // storage->setValue(7,57, Value( 25 ) ); // storage->setValue(7,58, Value( 26 ) ); // storage->setValue(7,59, Value( 24 ) ); // storage->setValue(7,60, Value( 27 ) ); // A1000:G1000 storage->setValue(1, 1000, Value("abc")); storage->setValue(2, 1000, Value("def")); storage->setValue(3, 1000, Value("efoob")); storage->setValue(4, 1000, Value("flka")); storage->setValue(5, 1000, Value("kde")); storage->setValue(6, 1000, Value("kde")); storage->setValue(7, 1000, Value("xxx")); // Z19:Z23 storage->setValue(26,19, Value( 16 ) ); storage->setValue(26,20, Value( 8 ) ); storage->setValue(26,21, Value( 4 ) ); storage->setValue(26,22, Value( 2 ) ); storage->setValue(26,23, Value( 1 ) ); // Add the second sheet m_map->addNewSheet(); sheet = m_map->sheet(1); sheet->setSheetName("Sheet2"); storage = sheet->cellStorage(); // B1:B2 Formula formula2(sheet); formula2.setExpression("=SUM(Sheet1!A19:Sheet1!A31)"); storage->setFormula(2,1, formula2); storage->setFormula(2,2, Formula::empty()); // Add the third sheet m_map->addNewSheet(); sheet = m_map->sheet(2); sheet->setSheetName("Sheet3"); storage = sheet->cellStorage(); // A1:A2 storage->setValue(1,1, Value( 1.1 ) ); storage->setValue(1,2, Value( 2.2 ) ); }
void CellTest::testRichText() { KoOdfStylesReader stylesReader; QBuffer buffer; buffer.open(QIODevice::ReadOnly); KoStore *store = KoStore::createStore(&buffer, KoStore::Read); KoOdfLoadingContext odfContext(stylesReader, store); OdfLoadingContext context(odfContext); KoDocumentResourceManager documentResources; KoShapeLoadingContext shapeContext(odfContext, &documentResources); context.shapeContext = &shapeContext; Styles autoStyles; QString cellStyleName; Map map; Sheet* sheet = map.addNewSheet(); CellStorage* storage = sheet->cellStorage(); storage->setValue(1, 1, Value(1)); Cell cell = storage->firstInRow(1); QVERIFY(!cell.isNull()); { // Test the simple case. Only one paragraph with some simple text. KoXmlDocument doc = xmlDocument("<text:p>Some text</text:p>"); KoXmlElement e = doc.documentElement(); QVERIFY(!e.isNull()); cell.loadOdfCellText(e, context, autoStyles, cellStyleName); QVERIFY(!cell.isNull()); QVERIFY(!cell.richText()); QVERIFY(cell.userInput().split('\n').count() == 1); } { // Text in the paragraph and in a child text:span means rich-text. KoXmlDocument doc = xmlDocument("<text:p>First<text:span>Second<text:span>Theird</text:span></text:span></text:p>"); KoXmlElement e = doc.documentElement(); QVERIFY(!e.isNull()); cell.loadOdfCellText(e, context, autoStyles, cellStyleName); QVERIFY(!cell.isNull()); QVERIFY(cell.richText()); QVERIFY(cell.userInput().split('\n').count() == 1); } { // The text:line-break should be translated into a \n newline and since there is no other rich-text it should not be detected as such. KoXmlDocument doc = xmlDocument("<text:p>First<text:line-break/>Second</text:p>"); KoXmlElement e = doc.documentElement(); QVERIFY(!e.isNull()); cell.loadOdfCellText(e, context, autoStyles, cellStyleName); QVERIFY(!cell.isNull()); QVERIFY(!cell.richText()); QVERIFY(cell.userInput().split('\n').count() == 2); } { // The text:s and text:tab should be translated into space and tabulator. No rich-text else. KoXmlDocument doc = xmlDocument("<text:p>First<text:s/>Second<text:tab/>Theird</text:p>"); KoXmlElement e = doc.documentElement(); QVERIFY(!e.isNull()); cell.loadOdfCellText(e, context, autoStyles, cellStyleName); QVERIFY(!cell.isNull()); QVERIFY(!cell.richText()); QVERIFY(cell.userInput().split('\n').count() == 1); } }