简体   繁体   中英

Crystal report textobject and fields

i am running the following code

foreach (ReportObject obj in oSectionObjects)
{
    if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.TextObject)
    {
        // do stuff
    }
}

but i have a problem. i do have multiple text that do contain text AND fields in them. But crystal return me the field being TextObject which is technically true.

How do i know i ONLY have text in the TextObject and not anything else (aka fields, parameters, formulas) ?

As far as I know the fields in a text box will be recognized by the text pattern. Try to search the text of the text object for {1@xxxxx} where xxxxx is the field name. "{1@" shows the type of the field: 1 is for a database , 2 is for formula, 3 is for parameter. You may try also for {@xxxxx} *(without numeric field identifier)

I searched alot around and found working solution for RAS report but nothing for crystal. Anyhow if someone end up here looking for an answer here's the work around.

Whenever you have to concatenate multiple fields on the report do NOT use TextObject . Instead use a Formula . The formula fields wont bet part of the ReportObjects but instead part of the ReportDocument.DataDefinition.FormulaFields with Kind being CrystalDecisions.Shared.FieldKind.FormulaField and you will want to check the ValueType so it is CrystalDecisions.Shared.FieldValueType.StringField .

then you can manipulate them.

I did need that for translation of report live so here's a parsing method for formulas :

try
{
    var sFormula = formula.Text;
    string pattern = "\"[\\w ]*\"";
    Regex r = new Regex(pattern);
    MatchCollection mc = r.Matches(sFormula);

    foreach (Match m in mc)
    {
        var sValue =m.Value;
        var sParsedValue = sValue.Substring(1, sValue.Length - 2);

        if (sParsedValue.StartsWith("s"))
        {
            var stest = "\"" + CApplicationData.TranslateStringValue(sParsedValue) + "\"";
            sFormula = sFormula.Replace(sValue, stest);
        }
    }

    formula.Text = sFormula;
}
catch{}

this above you will notice i use 's' as a key to know it might be a value to be translated so it's not mandatory. using the above on this formula with Spanish language :

"sPage" + " " + totext(PageNumber) + " " + "sOf" + " " + totext(TotalPageCount)

will modify the formula to :

"Página" + " " + totext(PageNumber) + " " + "de" + " " + totext(TotalPageCount)

giving output of :

Página 1 de 4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM