Sometimes you may face a necessity to edit many reports or templates to add some minor changes there. When the quantity of these reports is over dozens, this becomes a problem.

 

SharpShooter Reports provides a handy API to interact with a report. There are many useful samples which come with the product package.

The following sample: Reports\Samples\SharpShooter Reports\CSharp\Dynamic demonstrates how to create a report dynamically from code.

 

And now let’s see how to edit an existing report.

The following sample will be very helpful in this case:

http://www.perpetuumsoft.com/Support/M1/DynamicZipcodeReportSample2010.zip 

Here, a textbox positioned 2mm from the top and 2mm from the left is added to the existing report and saved.

To use API, it is needed to build a report. Here, it is not necessary to draw it, but it is necessary to call           

ActiveSlot.Prepare();

ActiveSlot.RenderDocument();

 

After that, the whole object model of a report is available.

 

The following code adds a text box:

 

var zipBox = new PerpetuumSoft.Reporting.DOM.TextBox();

zipBox.Name = "zipBox";

zipBox.Location = new Vector(0.2f, 0.2f).ConvertUnits(Unit.Centimeter,
                                                      Unit.InternalUnit);

zipBox.Size = new Vector(3.5f, 0.5f).ConvertUnits(Unit.Centimeter,
                                                  Unit.InternalUnit);

zipBox.DataBindings.Add(new ReportDataBinding("Value", "\"ZIPCODE\""));

zipBox.TextAlign = System.Drawing.ContentAlignment.TopLeft;

zipBox.CanGrow = zipBox.CanShrink = zipBox.GrowToBottom = true;


ActiveSlot.Document.Pages[0].Controls.Add(zipBox);

Now we need to save the changes. Since we don’t want to re-write the original report, we save it to a separate file. To do this, it is needed to create a temporary slot and save changes to it.


FileReportSlot
outputSlot = new FileReportSlot();

outputSlot.FilePath = "output.rst";

 

outputSlot.SaveReport(ActiveSlot.Document);

outputSlot.DesignTemplate();

Now you can create handlers for any number of reports, keep the legacy and make changes to them.

Add Feedback