Search Results for

    Show / Hide Table of Contents

    TFlexCelUserFormat Class

    A class used to define a cell format in code, that you can call from a report.

    Remarks

    To Create a User format:

    1. Create a new class derived from TFlexCelUserFormat.
    2. Override the method Evaluate.
    3. Add the new user format to the report using FlexCelReport.SetUserFormat.

    Syntax

    Namespace: FlexCel.Report

    public abstract class TFlexCelUserFormat

    Methods

    Name Description
    Evaluate Override this method on a derived class to implement your own defined function.

    Examples

    To define a user format that will format the cell according to the first parameter you pass to the function, you would: 1) Define the class:

        public class MyUserFormat : TFlexCelUserFormat
        {
            public override TFlxPartialFormat Evaluate(ExcelFile workbook, TXlsCellRange range, object[] parameters)
            {
                if (parameters == null || parameters.Length > 1)
                    throw new ArgumentException("Invalid number of parameters for user defined format \"MyUserFormat\"");
                int color = Convert.ToInt32(parameters[0]);
    
                TFlxFormat Format = workbook.GetDefaultFormat;
                Format.FillPattern.FgColor = TExcelColor.FromArgb(color);
                Format.FillPattern.BgColor = TExcelColor.Automatic;
                Format.FillPattern.Pattern = TFlxPatternStyle.Solid;
    
                TFlxApplyFormat Apply = new TFlxApplyFormat();
                Apply.FillPattern.SetAllMembers(true);
    
                return new TFlxPartialFormat(Format, Apply, false);
            }
    
        }
    

    2) Add the function to the report.

        MyUserFormat myFormatImpl = new MyUserFormat(); //The MyUserFormat class implements an user defined format.
        flexCelReport.SetUserFormat("MFMT", myFormatImpl); //The name used in Excel will be =MFMT().
    

    3) Now, you can write "<#format cell(MFMT;255)>" on a cell in the template, and it will painted blue.

    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com