views:

819

answers:

2

I was wondering if it is possible to change formulas of a crystal report programmatically. I want to list all formulas of a report in my web app and give the user the possibility to modify them.

Is that possible?

+1  A: 

Yes, for example we use the follwoing function to change formulas:

 Public Sub SetReportFormulaContents(ByRef Report As ReportDocument, ByVal FormulaName As String, ByVal FormulaContents As String)
    Dim Formula As FormulaFieldDefinition = Nothing

    ' Get the ReportObject by name and cast it as a FieldObject
    If TypeOf (Report.DataDefinition.FormulaFields.Item(FormulaName)) Is CrystalDecisions.CrystalReports.Engine.FormulaFieldDefinition Then
        Formula = Report.DataDefinition.FormulaFields.Item(FormulaName)
        Formula.Text = FormulaContents
    End If
End Sub
Anthony K
Is it possible to change whether the syntax of the formula is Crystal or Basic? Question: http://stackoverflow.com/questions/2386710/how-to-programmatically-change-a-crystal-reports-formula-from-crystal-syntax-to-b
Rory
+2  A: 
using CrystalDecisions.CrystalReports.Engine;

namespace Craft
{
 class Mate
 {
  Order_Print _r = new Order_Print();

  void Preview()
  {
   foreach (FormulaFieldDefinition f in _r.DataDefinition.FormulaFields)
   {
    MessageBox.Show(f.Name);

    f.Text = InputBox.Show("Input the formula for " + f.Name);
   }
  }
 }
}
Michael Buen