cancel
Showing results for 
Search instead for 
Did you mean: 

Generating an RPT file

Former Member
0 Kudos

This question has probably been asked before, but I didn't find anything that specifically answered it, so here we go:

We have a database with hundreds of tables, and I need the capability to generate reports on the fly from a custom query.  These would, of course, be simple reports showing the contents of a table or a view. 

However, I will also need to be able to specify the fields, set the column headings, include rudimentary filters, indicate the report orientation (portrait or landscape), and possibly other report characteristics.  In other words, I would like to be able to generate an RPT file by taking an existing RPT file template, making the necessary changes, and then running the report.

Ideally, I would like to be able to work with an xml version of a Crystal Report template, and generate an RPT file from that.

We have both CR 2013 and CR for Visual Studio, so either one could be used.

What is the best way of doing this?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Richard,

On the Overview tab on the left side you'll see a link for sample app's. You can use RAS to do this but you need to create your own "report designer" we no longer have one that can be used outside of Visual Studio.

If you are looking for a third party app there are some other there... but they are not free.

Don

Answers (1)

Answers (1)

ido_millet
Active Contributor
0 Kudos

Chances are you are moving in a wrong direction.  Creating such a "Report Designer" is no small task.

Perhaps if you describe the context for this request in more detail it would be possible to suggest a better path.
For example, does the user truly need unlimited flexibility in creating new reports, or do they mainly need to modify filtering/grouping via interactive controls (there are 3rd-party Crystal tools that support that).
Would a solution that automatically delivers the data to the user for easy slice & dice (e.g. Pivot Table) be good enough? Again, 3rd-party Crystal tools that support that use scenario exist.

Former Member
0 Kudos

This would not at all be a tool for users to develop reports.  Rather we as developers would use it to speed the development process.

I am faced with the task of creating hundreds of reports that for the most part vary only in the tables, fields, and column headers required.  If I have to design every report it will take weeks, as well as creating a huge maintenance issue.

Therefore, what I need is a template report definition that I can programmatically modify with the desired table/fields/headers, and then launch to produce the desired report.

RPT files are in a binary format, so I need one of two things:

1. Documentation on the structure and format of RPT files, and perhaps tools and/or code snippets to work with them.

or

2. A facility for transforming the binary format into xml or text, and vice versa.

ido_millet
Active Contributor
0 Kudos

That indeed clarifies things.

Do these reports include Table Joins, Grouping, or Summaries?

One option is to create a report template that displays only formulas that simply map to the database columns. In code, you can then change the data source and the formula expressions.

However, you still need a process to translate from a new customer request to the necessary data source and column mapping choices.  It would take a similar amount of time (perhaps even less time) to manually "Save As" that report template and adjust the formulas.

Former Member
0 Kudos

These reports would in all probability not contain any joins, grouping, or summaries.

Views would be used in place of joins, and if we need reports containing grouping or summaries (anything beyond the total number of records) we would manually design them.

In regard to your report template suggestion, I assume you mean that I should create a dummy data definition (e.g., an xsd file) defined with Field1, Field2, Field3, etc., create an RPT file using that definition, and then populate and launch the report.

Several questions:

1. How do I deal with the problem of different number of fields for each report?

2. How can I programmically set the column headers?

3. How can I programmically adjust the column widths?

0 Kudos

Hi Richard,

In the template report add as many formula fields and text objects to the report as you will limit the user to use.

Below is what I use to get all of the objects and some commented code on how to change them.

As Ido said, this is going to be a lot of work but this should get you started:

Add all of these assemblies:

using System.Reflection;

using System.Runtime.InteropServices;

using System;

using System.IO;

using System.Xml;

using System.Drawing;

using System.Drawing.Printing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Threading;

using System.Diagnostics;

using System.Globalization;

using ADODB;  

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using CrystalDecisions.ReportAppServer;

using CrystalDecisions.ReportAppServer.ClientDoc;

using CrystalDecisions.ReportAppServer.Controllers;

using CrystalDecisions.ReportAppServer.ReportDefModel;

using CrystalDecisions.ReportAppServer.CommonControls;

using CrystalDecisions.ReportAppServer.CommLayer;

using CrystalDecisions.ReportAppServer.CommonObjectModel;

using CrystalDecisions.ReportAppServer.ObjectFactory;

using CrystalDecisions.ReportAppServer.Prompting;

using System.Data.OleDb;

using CrystalDecisions.ReportAppServer.DataSetConversion;

using CrystalDecisions.ReportAppServer.DataDefModel;

using CrystalDecisions.ReportSource;

using CrystalDecisions.Windows.Forms;

using CrystalDecisions.ReportAppServer.XmlSerialize;

using System.Timers;

#region OBJtoFName

btnReportObjects.Text = "";

textBox1 = "";

flcnt = 0;

CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects rptObjs;

//rptObjs = rptClientDoc.ReportDefController.ReportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField);

rptObjs = rptClientDoc.ReportDefController.ReportObjectController.GetAllReportObjects();

foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject rptObj1 in rptObjs)

{

    switch (rptObj1.Kind)

    {

        case CrReportObjectKindEnum.crReportObjectKindField:

            CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject fldObj1;

            fldObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)rptObj1;

                               

            textBox1 = fldObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += fldObj1.DataSourceName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            //// This works do not change

            //if (fldObj1.Name == "LINETOTALTAXAMOUNT1")

            //{

            //    CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject OldfieldObject = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)rptObj1;

            //    CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject NewfieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();

            //    //OldfieldObject.CopyTo(NewfieldObject, true);

            //    NewfieldObject = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)OldfieldObject.Clone(true);

            //    CrystalDecisions.ReportAppServer.ReportDefModel.NumericFieldFormat numericFieldFormat = NewfieldObject.FieldFormat.NumericFormat;

            //    //CrystalDecisions.ReportAppServer.ReportDefModel.CrCurrencySymbolTypeEnum = CrCurrencySymbolTypeEnum.crCurrencySymbolTypeFixedSymbol;

            //    numericFieldFormat.NDecimalPlaces = 8;

            //    numericFieldFormat.EnableUseLeadZero = false;

            //    //numericFieldFormat.ThousandSymbol = "&";

            //    //numericFieldFormat.ThousandsSeparator = true;

            //    numericFieldFormat.NegativeFormat = CrystalDecisions.ReportAppServer.ReportDefModel.CrNegativeTypeEnum.crNegativeTypeLeadingMinus;

            //    numericFieldFormat.RoundingFormat = CrystalDecisions.ReportAppServer.ReportDefModel.CrRoundingTypeEnum.crRoundingTypeRoundToTenBillionth;

            //    rptClientDoc.ReportDefController.ReportObjectController.Modify(OldfieldObject, NewfieldObject);

            //    // Another bug in the controller need to call this 2 times to take the Rounding property - same as ADAPT01727457

            //    rptClientDoc.ReportDefController.ReportObjectController.Modify(OldfieldObject, NewfieldObject);

            //    IsRpt = false;

            //}

            //// This works do not change

            break;

        case CrReportObjectKindEnum.crReportObjectKindText:

            CrystalDecisions.ReportAppServer.ReportDefModel.TextObject txtObj;

            txtObj = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;

            textBox1 = txtObj.Name.ToString();

            textBox1 += " -> " + txtObj.Text.ToString();

            textBox1 += "\nEnableSuppressEmbedBlankLines: " + ((dynamic) rptObj1).TextObjectFormat.EnableSuppressEmbedBlankLines + "\n";

            textBox1 += "SectionCode: " + ((dynamic) rptObj1).SectionCode;

            btnReportObjects.Text += textBox1 + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            //// This works do not change

            //if (txtObj.Name == "Text1")

            //{

            //    CrystalDecisions.ReportAppServer.ReportDefModel.TextObject OldTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;

            //    CrystalDecisions.ReportAppServer.ReportDefModel.TextObject NewTextObject = new CrystalDecisions.ReportAppServer.ReportDefModel.TextObject();

            //    //OldfieldObject.CopyTo(NewfieldObject, true);

            //    NewTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)OldTextObject.Clone(true);

            //    NewTextObject.Border.BackgroundColor = 255;

            //    rptClientDoc.ReportDefController.ReportObjectController.Modify(OldTextObject, NewTextObject);

            //    //rptClientDoc.ReportDefController.ReportObjectController.Modify(OldTextObject, NewTextObject);

            //    IsRpt = false;

            //}

            //// This works do not change

            break;

        case CrReportObjectKindEnum.crReportObjectKindBox:

            CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject boxObj1;

            CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject boxObj2 = new CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject();

            boxObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject)rptObj1;

            boxObj2 = boxObj1;

            //// modify the box size

            //boxObj.Bottom = 360;

            //boxObj1.Height = 2385;

            //boxObj1.Format.EnableCanGrow = true;

            //boxObj1.EndSectionName = "ReportFooterSection1";

            //boxObj1.EnableExtendToBottomOfSection = true;

            //rptClientDoc.ReportDefController.ReportObjectController.Modify(boxObj, boxObj1);

            textBox1 = boxObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += boxObj1.Name.ToString();

            textBox1 += " : X - ";

            textBox1 += (boxObj1.Left / 1440.00).ToString();

            textBox1 += " : Y - ";

            textBox1 += ((boxObj1.Right - boxObj1.Left) / 1440.00).ToString();

            textBox1 += " : Width - ";

            textBox1 += (boxObj1.Width / 1440.00).ToString();

            textBox1 += " : Height - ";

            textBox1 += (boxObj1.Height / 1440.00).ToString();

            btnReportObjects.Text += textBox1 + "\n";

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            IsRpt = false;

            break;

        case CrReportObjectKindEnum.crReportObjectKindPicture:

            textBox1 = rptObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += rptObj1.Name.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            btnReportObjects.Text += "Height: " + rptObj1.Height.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Width: " + rptObj1.Width.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Top: " + rptObj1.Top.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Left: " + rptObj1.Left.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindChart:

            textBox1 = rptObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += rptObj1.Name.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            btnReportObjects.Text += "Height: " + rptObj1.Height.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Width: " + rptObj1.Width.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Top: " + rptObj1.Top.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Left: " + rptObj1.Left.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindSubreport:

            CrystalDecisions.ReportAppServer.ReportDefModel.SubreportObject subObj1;

            subObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.SubreportObject)rptObj1;

            textBox1 = subObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += subObj1.SubreportName.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindOlapGrid:

            CrystalDecisions.ReportAppServer.ReportDefModel.OlapGridObject OLAPObj1;

            OLAPObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.OlapGridObject)rptObj1;

            textBox1 = OLAPObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += OLAPObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindMap:

            CrystalDecisions.ReportAppServer.ReportDefModel.MapObject MapObj1;

            MapObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.MapObject)rptObj1;

            textBox1 = MapObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += MapObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindLine:

            CrystalDecisions.ReportAppServer.ReportDefModel.LineObject LineObj1;

            LineObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.LineObject)rptObj1;

            textBox1 = LineObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += LineObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindFlash:

            CrystalDecisions.ReportAppServer.ReportDefModel.FlashObject FlashObj1;

            FlashObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.FlashObject)rptObj1;

            textBox1 = FlashObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += FlashObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindFieldHeading:

            CrystalDecisions.ReportAppServer.ReportDefModel.FieldHeadingObject FieldHeadingObj1;

            FieldHeadingObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldHeadingObject)rptObj1;

            textBox1 = FieldHeadingObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += FieldHeadingObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindCrosstab:

            CrystalDecisions.ReportAppServer.ReportDefModel.CrossTabObject CrossObj1;

            CrossObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.CrossTabObject)rptObj1;

            textBox1 = CrossObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += CrossObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindBlobField:

            CrystalDecisions.ReportAppServer.ReportDefModel.BlobFieldObject BlobObj1;

            BlobObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.BlobFieldObject)rptObj1;

            textBox1 = BlobObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += BlobObj1.Name.ToString() + " - ";

            btnReportObjects.Text += textBox1;

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

            btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        //case CrReportObjectKindEnum.crReportObjectKindInvalid:

        //    CrystalDecisions.ReportAppServer.ReportDefModel. InvalidObj1;

        //    BlobObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.BlobFieldObject)rptObj1;

        //    textBox1 = BlobObj1.Name.ToString();

        //    textBox1 += " -> ";

        //    textBox1 += BlobObj1.Name.ToString() + " - ";

        //    btnReportObjects.Text += textBox1;

        //    btnReportObjects.Text += "Section Name: " + rptObj1.SectionCode.ToString() + " " + rptObj1.SectionName.ToString() + "\n";

        //    btnReportObjects.AppendText("\n");

        //    ++flcnt;

        //    btnCount.Text = flcnt.ToString();

        //    break;

        //    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindInvalid;

    }

}

#endregion OBJtoFName

Former Member
0 Kudos

Thanks - I will try working with this