Example #1
0
        public void Should_Get_Col_From_Row()
        {
            // GIVEN
            var values = new List <RowValue>
            {
                new RowValue {
                    ValuesByColName = new Dictionary <string, object> {
                        { "colA", 11 }, { "colB", 44 }
                    }
                },
                new RowValue {
                    ValuesByColName = new Dictionary <string, object> {
                        { "colA", 22 }, { "colB", 55 }
                    }
                },
                new RowValue {
                    ValuesByColName = new Dictionary <string, object> {
                        { "colA", 33 }, { "colB", 66 }
                    }
                },
            };

            var mat = Matrix.With()
                      .RowValues(values)
                      .Build();

            // WHEN
            MatrixCellValue cell = mat.Row(values[0].Cells.ElementAt(0)).Col("colB");

            // THEN
            Check.That(cell.RowIndex).IsEqualTo(1);
            Check.That(cell.ColIndex).IsEqualTo(1);
            Check.That(cell.Address).IsEqualTo("B2");
            Check.That(cell.Value).IsEqualTo(44);
        }
Example #2
0
        private void SetCellValue(Matrix mat, MatrixCellValue matrixCell, RowDefinition rowDef, IXLCell cell)
        {
            var  value     = matrixCell.Value;
            bool isFormula = false;

            if (matrixCell.ColName != null && rowDef.ValuesMapping.TryGetValue(matrixCell.ColName, out var func))
            {
                var calculatedValue = func.Invoke(mat, matrixCell);
                if (calculatedValue is string stringValue && stringValue.StartsWith(MatrixConstants.CHAR_FORMULA_STARTS))
                {
                    value     = stringValue.Substring(1);
                    isFormula = true;
                }
                else
                {
                    value = calculatedValue;
                }
            }