Adding Custom Code in Pixel Perfect Reports

Jan 13 2025
5 min read

Introduction

Pixel Perfect Reports is a powerful tool for designing and creating reports. While Pixel Perfect Reports provides a range of built-in functions and features, there are times when you need to extend its capabilities with custom code. This blog post will guide you through the process of adding and using custom code in Pixel Perfect Reports to enhance your reporting solutions.

Why Use Custom Code in Pixel Perfect Reports?

Custom code in Pixel Perfect Reports allows you to:

Perform Complex Calculations: Implement advanced mathematical or business logic that goes beyond the built-in functions.

Improve Performance: Optimize performance by offloading complex logic from the report's expressions to custom code.

In Pixel Perfect Reports, you can add custom code by creating functions written in C# or VB.NET and call them in an expression.

It is a straightforward way to incorporate custom logic. This code is written in C# or Visual Basic .NET (VB.NET) and is embedded within the report itself.

Here are the steps to add custom logic.

 

  1. Open Your Report.

  2. Select the language.

    • Mouse down on the canvas. In the properties pane on the right, go to the Custom Code section. In the Language comboBox, select your preferred language.

  3. Open the Custom Code Edit.

    • Click the Custom Code button to bring up the Custom Code Edit.

  4. Enter Your C# or VB.NET Code:

    • Write your custom C# or VB.NET code by adding a function. Here’s a simple example:

    • public static string LongDateFormat(DateTime anyDate)
      {
          
      string suffix;

          
      switch (anyDate.Day)
          {
              
      case 1:
              
      case 21:
              
      case 31:
                  suffix =
      "st";
                  
      break;
              
      case 2:
              
      case 22:
                  suffix =
      "nd";
                  
      break;
              
      case 3:
              
      case 23:
                  suffix =
      "rd";
                  
      break;
              
      default:
                  suffix =
      "th";
                  
      break;
          }

          
      return anyDate.ToString("dddd d") + suffix + anyDate.ToString(" MMMM yyyy");
      }

  5. Use the Code in Your Report:

    • To call this function in your report, use an expression like:

                      LongDateFormat(date);

Tips for Using Custom Code

Error Handling: Implement robust error handling in your custom code to prevent report failures.

Performance Considerations: Avoid heavy computations in custom code that could affect report performance.

Testing: Thoroughly test custom code to ensure it works as expected across different scenarios and data.

Documentation: Document custom code and its usage for future maintenance and for other team members.

Conclusion

Custom code in Pixel Perfect Reports is a powerful feature that can significantly enhance the functionality and flexibility of your reports. Understanding how to properly implement and manage this code will help you create more dynamic and efficient reporting solutions.

Experiment with custom code and see how it can streamline your reporting processes. With careful implementation, you can unlock new capabilities and deliver more insightful reports to your stakeholders. Happy reporting!

Share this post