Пример #1
0
        private void RenderCell(FormulaEvaluator evaluator, TemplateCell cell, params Parameter[] pars)
        {
            object value;

            try
            {
                value = cell.IsCalculated
                    ? evaluator.Evaluate(cell.GetString(), pars)
                    : cell.CellType == TemplateCellType.Formula ? cell.Formula : cell.Value;
            }
            catch (ParseException ex)
            {
                _buff.WriteValue(ex.Message, cell.Style);
                _buff.GetCell(_buff.PrevAddress.RowNumber, _buff.PrevAddress.ColumnNumber).Style.Font.FontColor = XLColor.Red;
                _errors.Add(new TemplateError(ex.Message, cell.XLCell.AsRange()));
                return;
            }

            if (cell.CellType == TemplateCellType.Formula)
            {
                var r1c1 = cell.XLCell.GetFormulaR1C1(value.ToString());
                _buff.WriteFormulaR1C1(r1c1, cell.Style);
            }
            else
            {
                _buff.WriteValue(value, cell.Style);
            }
        }
Пример #2
0
        private void RenderCell(FormulaEvaluator evaluator, TemplateCell cell, params Parameter[] pars)
        {
            var value = cell.IsCalculated
                ? evaluator.Evaluate(cell.GetString(), pars)
                : cell.CellType == TemplateCellType.Formula ? cell.Formula : cell.Value;

            if (cell.CellType == TemplateCellType.Formula)
            {
                var r1c1 = cell.XLCell.GetFormulaR1C1(value.ToString());
                _buff.WriteFormulaR1C1(r1c1, cell.Style);
            }
            else
            {
                _buff.WriteValue(value, cell.Style);
            }
        }
Пример #3
0
        private void RenderCell(FormulaEvaluator evaluator, TemplateCell cell, params Parameter[] pars)
        {
            object value;

            try
            {
                value = cell.IsCalculated
                    ? evaluator.Evaluate(cell.GetString(), pars)
                    : cell.CellType == TemplateCellType.Formula ? cell.Formula : cell.Value;
            }
            catch (ParseException ex)
            {
                _buff.WriteValue(ex.Message, cell.XLCell);
                _buff.GetCell(_buff.PrevAddress.RowNumber, _buff.PrevAddress.ColumnNumber).Style.Font.FontColor = XLColor.Red;
                _errors.Add(new TemplateError(ex.Message, cell.XLCell.AsRange()));
                return;
            }

            IXLCell xlCell;

            if (cell.CellType == TemplateCellType.Formula)
            {
                var r1c1 = cell.XLCell.GetFormulaR1C1(value.ToString());
                xlCell = _buff.WriteFormulaR1C1(r1c1, cell.XLCell);
            }
            else
            {
                xlCell = _buff.WriteValue(value, cell.XLCell);
            }

            string EvalString(string str)
            {
                try
                {
                    return(evaluator.Evaluate(str, pars).ToString());
                }
                catch (ParseException ex)
                {
                    _errors.Add(new TemplateError(ex.Message, cell.XLCell.AsRange()));
                    return(ex.Message);
                }
            }

            if (xlCell.HasComment)
            {
                var comment = EvalString(xlCell.Comment.Text);
                xlCell.Comment.ClearText();
                xlCell.Comment.AddText(comment);
            }

            if (xlCell.HasHyperlink)
            {
                if (xlCell.Hyperlink.IsExternal)
                {
                    xlCell.Hyperlink.ExternalAddress = new Uri(EvalString(xlCell.Hyperlink.ExternalAddress.ToString()));
                }
                else
                {
                    xlCell.Hyperlink.InternalAddress = EvalString(xlCell.Hyperlink.InternalAddress);
                }
            }

            if (xlCell.HasRichText)
            {
                var richText = EvalString(xlCell.RichText.Text);
                xlCell.RichText.ClearText();
                xlCell.RichText.AddText(richText);
            }
        }