예제 #1
0
        public void Should_Render_Matrix_With_Cells_Lookup_On_A_Concataned_Matrix()
        {
            // GIVEN
            var finalTotalStyle = _workbook.CreateCellStyle();

            finalTotalStyle.FillPattern         = FillPattern.SolidForeground;
            finalTotalStyle.FillForegroundColor = IndexedColors.LightOrange.Index;
            var format = new NPOIFormat {
                CellStyle = finalTotalStyle
            };
            Matrix m1 = MatrixDatasets.Given_MatrixWithCellLookup(1, format);
            Matrix m2 = MatrixDatasets.Given_MatrixWithCellLookup(2, format);
            Matrix m3 = m1.ConcatX(m2);

            // WHEN
            var filename = WriteDebugFile(_defaultFormatApplier, m3, FILE_TEST_LOOKUP_2, _workbook);

            // THEN
            var readWb    = new XSSFWorkbook(File.OpenRead(filename));
            var readSheet = readWb.GetSheetAt(0);

            var row1 = readSheet.GetRow(1);

            Check.That(row1.Cells[0].StringCellValue).IsEqualTo("Mario");
            Check.That(row1.Cells.Skip(1).Take(5).Extracting("NumericCellValue")).ContainsExactly(10, 20, 30, 60, 0);
            Check.That(row1.Cells[5].CellFormula).IsEqualTo("AVERAGE(10,20,30)");
            Check.That(row1.Cells[6].StringCellValue).IsEqualTo("Mario");
            Check.That(row1.Cells.Skip(7).Take(5).Extracting("NumericCellValue")).ContainsExactly(10, 20, 30, 60, 0);
            Check.That(row1.Cells.Last().CellFormula).IsEqualTo("AVERAGE(10,20,30)");

            var row2 = readSheet.GetRow(2);

            Check.That(row2.Cells[0].StringCellValue).IsEqualTo("Luigi");
            Check.That(row2.Cells.Skip(1).Take(5).Extracting("NumericCellValue")).ContainsExactly(12, 23, 34, 69, 0);
            Check.That(row2.Cells[5].CellFormula).IsEqualTo("AVERAGE(12,23,34)");
            Check.That(row2.Cells[6].StringCellValue).IsEqualTo("Luigi");
            Check.That(row2.Cells.Skip(7).Take(5).Extracting("NumericCellValue")).ContainsExactly(12, 23, 34, 69, 0);
            Check.That(row2.Cells.Last().CellFormula).IsEqualTo("AVERAGE(12,23,34)");

            var row3 = readSheet.GetRow(3);

            Check.That(row3.Cells[0].StringCellValue).IsEqualTo("TOTAL");
            Check.That(row3.Cells.Skip(1).Take(5).Extracting("NumericCellValue")).ContainsExactly(22, 0, 0, 0, 0);
            Check.That(row3.Cells[2].CellFormula).IsEqualTo("SUM(C2:C3)");
            Check.That(row3.Cells[3].CellFormula).IsEqualTo("D2+D3");
            Check.That(row3.Cells[4].CellFormula).IsEqualTo("SUM(E2:E3)");
            Check.That(row3.Cells[5].CellFormula).IsEqualTo("AVERAGE(F2:F3)");
            Check.That(row3.Cells[6].StringCellValue).IsEqualTo("TOTAL");
            Check.That(row3.Cells.Skip(7).Take(5).Extracting("NumericCellValue")).ContainsExactly(22, 0, 0, 0, 0);
            Check.That(row3.Cells[8].CellFormula).IsEqualTo("SUM(I2:I3)");
            Check.That(row3.Cells[9].CellFormula).IsEqualTo("J2+J3");
            Check.That(row3.Cells[10].CellFormula).IsEqualTo("SUM(K2:K3)");
            Check.That(row3.Cells[11].CellFormula).IsEqualTo("AVERAGE(L2:L3)");
        }
예제 #2
0
        public void Should_Render_Matrix_With_Cells_Lookup_On_A_Single_Matrix()
        {
            // GIVEN
            var finalTotalStyle = _workbook.CreateCellStyle();

            finalTotalStyle.FillPattern         = FillPattern.SolidForeground;
            finalTotalStyle.FillForegroundColor = IndexedColors.LightOrange.Index;
            var format = new NPOIFormat {
                CellStyle = finalTotalStyle
            };
            Matrix m1 = MatrixDatasets.Given_MatrixWithCellLookup(1, format);

            // WHEN
            var filename = WriteDebugFile(_defaultFormatApplier, m1, FILE_TEST_LOOKUP_1, _workbook);

            // THEN
            SharedAssertions.Assert_Matrix_Cells_Lookup_On_A_Single_Matrix(filename);
        }