cancel
Showing results for 
Search instead for 
Did you mean: 

Text Interpretation lost

0 Kudos

Hi,

When I change the text of a Paragraph Text Element inside a Text Object, I lose the Text Interpretation (RTF Text, HTML Text) of all fields inside that Text Object.

In fact, when I read the Text Format of a Paragraph Field Element, no matter what I've set in design mode, I always get "crTextFormatStandardText". And any modification made are not applied.

I'm testing with version 13.0.26.

using ReportDefModel = CrystalDecisions.ReportAppServer.ReportDefModel;

private void test()
        {
            CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = crystalReportViewer1.ReportSource as CrystalDecisions.CrystalReports.Engine.ReportDocument;

            foreach (ReportDefModel.ISCRReportObject reportObject in reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.GetReportObjectsByKind(ReportDefModel.CrReportObjectKindEnum.crReportObjectKindText))
            {
                ReportDefModel.TextObject textObject = reportObject as ReportDefModel.TextObject;

                foreach (ReportDefModel.Paragraph paragraph in textObject.Paragraphs)
                    foreach (ReportDefModel.ParagraphElement paragraphElement in paragraph.ParagraphElements)
                        switch (paragraphElement.Kind)
                        {
                            case ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindText:
                                ReportDefModel.ParagraphTextElement paragraphTextElement = paragraphElement as ReportDefModel.ParagraphTextElement;

                                paragraphTextElement.Text = "new text";

                                /**
                                 * this will make me lose the Text Interpretation (RTF Text, HTML Text) of all fields objects inside the Text Object
                                 */
                                reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.Modify(textObject, textObject);
                                break;
                            case ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindField:
                                ReportDefModel.ParagraphFieldElement paragraphFieldElement = paragraphElement as ReportDefModel.ParagraphFieldElement;

                                /**
                                 * in design mode, I have set all field objects with Text Interpretation to HTML Text, but
                                 * paragraphFieldElement.FieldFormat.StringFormat.TextFormat return crTextFormatStandardText
                                 * I will set to crTextFormatHTMLText
                                 */
                                paragraphFieldElement.FieldFormat.StringFormat.TextFormat = ReportDefModel.CrTextFormatEnum.crTextFormatHTMLText;

                                /**
                                 * this will make me lose the Text Interpretation (RTF Text, HTML Text) of all fields objects inside the Text Object
                                 * I have set to crTextFormatHTMLText, but with no effect
                                 */
                                reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.Modify(textObject, textObject);
                                break;
                        }
            }
        }

Would it be possible to change text inside the ParagraphTextElement without loosing the Text Interpretation of the other ParagraphFieldElement?

Regards,

Marco Monteiro

Accepted Solutions (1)

Accepted Solutions (1)

I escalated the issue, should be fixed in SP 28, no release date set at this time.

Answers (8)

Answers (8)

0 Kudos

Oops, my mistake. It doesn't work either, it bolded the whole line.

This is the way it should be done but there is a bug still.

I'll ping R&D and see what they say.

Don

0 Kudos
got it working, all documented in this KBA:

https://answers.sap.com/questions/4797963/replacing-text-in-textbox-with-parameter.html

CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects rptObjs;

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

foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject rptObj1 in rptObjs)
{
    switch (rptObj1.Kind)
    {
case CrReportObjectKindEnum.crReportObjectKindText:
    if (txtObj.Name == "Text1")
    {
        CrystalDecisions.ReportAppServer.Controllers.ReportObjectController boReportObjectController;
        CrystalDecisions.ReportAppServer.ReportDefModel.TextObject boOldTextObject, boNewTextObject;
        CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph boParagraph;
        CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement boParagraphTextElement;
        boReportObjectController = rptClientDoc.ReportDefController.ReportObjectController;


        boOldTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;
        boNewTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)boOldTextObject.Clone(true);

        // Clear out all paragraphs from the current text object
        boNewTextObject.Paragraphs.RemoveAll();

        // Create a new Paragraph to add to our TextObject
        boParagraph = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph();

        // Create a new ParagraphTextElement to be added to our paragraph

        boParagraphTextElement = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement();
        boParagraphTextElement.Text = "The new Text I want append " + boOldTextObject.Text;
        boParagraph.ParagraphElements.Add(boParagraphTextElement);

        boNewTextObject.Paragraphs.Add(boParagraph);

        boReportObjectController.Modify(boOldTextObject, boNewTextObject);
    }

break;<br>
0 Kudos

Now we are working together!

I read and applied David Hilton's suggestion in the KBA, and this is what I expected:

The value of my parameter is: This text is bold.

But this is what I got:

The value of my parameter is: This text is <b>bold</b>.

How can I set the Text Interpretation?

I tried your code, and this is what I expected:

The new Text I want append Label: This text is bold.

But this is what I got:

The new Text I want append Label: {@formula}


Your code is against the solution in the KBA. In David Hilton comment, he said "These ParagraphElements are what you actually need to manipulate. These could be simple text or fields from your field explorer." But you put it all together in one Text Element, making it interpreted as normal test.

boParagraphTextElement.Text = "The new Text I want append " + boOldTextObject.Text;
0 Kudos

Ah, so you are changing the text in the text object, correct?

I'll try some more things.

0 Kudos

So you are replacing the "HTML" or appending to the formula field text?

Not sure that API was designed to do what you think it should do.

Using the Formula controller you can append text this way:

foreach (FormulaField resultField in rptClientDoc.DataDefController.DataDefinition.FormulaFields)
{
    String FormulaMessage;
    textBox1 = resultField.LongName.ToString();
    btnReportObjects.Text += textBox1;
    btnReportObjects.AppendText(" : Used: " + resultField.UseCount.ToString() + " times'End' ");
    ++flcnt;
    btnCount.Text = flcnt.ToString();

    btnCount.Text = rptClientDoc.DataDefController.DataDefinition.FormulaFields.Count.ToString();

    FormulaField oOldFormulaField = resultField;
    FormulaField oFormulaField = new FormulaField();
    resultField.CopyTo(oFormulaField, false);
    oFormulaField.Text = @"'Don " + oFormulaField.Text.ToString() + "'";
    rptClientDoc.DataDefController.FormulaFieldController.Modify(oOldFormulaField, oFormulaField); 


    try
    {
        FormulaMessage = "\n" + rptClientDoc.DataDefController.FormulaFieldController.Check(resultField);
    }
    catch (Exception ex)
    {
        btnReportObjects.Text += "\n" + ex.Message + "\n";
        btnReportObjects.AppendText("");
        FormulaMessage = "\n";
        //resultField.Text = "1234";
        boFields[0].Name.ToString();
        boFields[0].FormulaForm.ToString();

        //MessageBox.Show("ERROR: " + ex.Message); // + " ;" + ex.InnerException.Message);

        ////cool but of no use to release mode
        //string myURL = @"http://search.sap.com/ui/scn#query=" + ex.Message + "☆tindex=1&filter=scm_a_site%28scm_v_Site11%29&filter=scm_a_modDate%28*%29&timeScope=all";
        //string fixedString = myURL.Replace(" ", "%20");

        ////System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Internet Explorer\iexplore.exe", myURL);
        //System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", fixedString);

        //string myURL = @"C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports 2011\Help\en\crw.chm";
        //System.Diagnostics.Process.Start(myURL);
        ////cool but of no use to release mode

    }
0 Kudos

Thanks for your effort in giving me an answer, but you should read my answers too. I said I was not changing the formula, and I don't want to change it.

About the API, it's working because I can replace what I want to replace, the ParagraphTextElement inside the TextObject.

paragraphTextElement.Text="new text"

Take this example, where the {formula} is set with the Text Interpretation to HTML:

---------------------
| Label: {formula} |
---------------------

It prints:

Label: This text is bold.

I want to change to this:

-----------------------------
| Another Label: {formula} |
-----------------------------

So, I do this:

paragraphTextElement.Text = "Another Label:"
And it works!The API works and I get what I want, but the {formula} loses the Text Interpretion! It prints:
Another Label: This text is <b>bold</b>.

Are you saying that this is normal?
0 Kudos

Thanks Marco,

Not clear still though, do you want to append text to the String Object or alter the formula or change what is being bolded?

I see you are appending text to the formula field that has the escape sequence in it so you should be editing the Formula and not the Paragraph.

Don

0 Kudos

I'm not sure what you mean with 'String Object', but I think the answer to your question is in the code:

switch (paragraphElement.Kind)
{
    case ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindText:
        ReportDefModel.ParagraphTextElement paragraphTextElement = paragraphElement as ReportDefModel.ParagraphTextElement;

        paragraphTextElement.Text = "new text"


I'm changing the Text Element, not the Field Element neither the formula.

So, why the Field Element loses the Text Intepretation?

0 Kudos

Hi Marco,

Need more info on your object. Can you send me a sample report?

Don


0 Kudos

See if you Clone the object and use it to replace the original.

0 Kudos

I tried to replace with Modify:

ReportDefModel.ISCRReportObject reportObjectNEW = reportObjectOLD.Clone();
reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.Modify(reportObjectOLD, reportObjectNEW);

and the Text Interpretation was lost.

I also tried to replace with Remove/Add:

ReportDefModel.ISCRReportObject reportObjectNEW = reportObjectOLD.Clone();
reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.Remove(reportObjectOLD);
reportDocument.ReportClientDocument.ReportDefController.ReportObjectController.Add(reportObjectNEW, reportDocument.ReportClientDocument.ReportDefController.ReportDefinition.FindSectionByName(reportObjectOLD.SectionName));

and the Text Interpretation was lost to.

Can you tell me if it works for you?

DellSC
Active Contributor
0 Kudos

I might try using a parameter to provide the text instead of updating the text directly.

-Dell

0 Kudos

Maybe, in some cases, that would be a useful workaround.

But in my case, I need to read what is in the Text Object and set, accordingly, a new value. More, I need to do this without losing the formatting.