How to programmatically change a Crystal Reports formula from Crystal Syntax to Basic Syntax - in Visual Studio 2005

这一生的挚爱 提交于 2019-12-24 15:46:43

问题


I want to programmatically change formulas in a whole lot of reports, like in this question, but I also need to change the formula between Crystal Syntax and Basic Syntax. I can't see any way to do this in the object model. Is it possible?

i.e. I have a formula called 'Period' that already exists in a whole lot of reports, and it's currently defined in Crystal Syntax. I want to set the formula to be in Basic Syntax and provide updated text of the formula. I don't need to automatically convert the current definition from crystal to basic; I already have the new formula text.

If I simply loop through all the reports, open them, then set the FormulaFieldDefinition's Text property then the formulas are still set to 'Crystal Syntax' and won't evaluate correctly. Currently my only solution is manually opening each report, editing the formula, changing the dropdown from Crystal Syntax to Basic Syntax.


回答1:


this http://msdn.microsoft.com/en-us/library/ms225743%28VS.80%29.aspx says that formulas are supported with Crystal Syntax and Basic Syntax - doesn't it automatically accept both of them? Or do you want to convert between these two syntaxes?




回答2:


I believe and @CodeByMoonlight confirms that this isn't available. So for anyone in the same boat as me with many reports to update: enjoy that manual process and hope you never have to change back!




回答3:


You can walk through the report objectmodel like this. Just change the formula and formula name.

public ReportDocument GetReport(DataSet ds)
    {
        const string formula = "WhileReadingRecords;" +
                               "<<your formula>>";


        ReportDocument report = new InvoiceReport();
        report.SetDataSource(ds);

        // iterate report objects
        foreach (ReportObject ro in report.ReportDefinition.ReportObjects)
        {

            if ((ro.Kind == ReportObjectKind.FieldObject && ro.Name == "<<FormuleName>>"))
            {
                ((FormulaFieldDefinition) ((FieldObject) o).DataSource).Text = formula;
            }
        }
        return report;
    }


来源:https://stackoverflow.com/questions/2386710/how-to-programmatically-change-a-crystal-reports-formula-from-crystal-syntax-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!