Link to home
Start Free TrialLog in
Avatar of TheAvenger
TheAvengerFlag for Switzerland

asked on

Something like table layout in Crystal

Hi Experts,

I am using Crystal Reports 9.2.2 and am trying to achieve the following layout in a single field:

-------------------------------------------------------------------------------------------------------
Parameter 1 name:      Value 1                  Parameter 2 name:      Value 2
Parameter 3 name:      Value 3                  Parameter 4 name:      Value 4
-------------------------------------------------------------------------------------------------------

The number of parameters can vary. I have the whole string (starting from Parameter 1 and reaching the last value) in my application and send it to the report as a report parameter. I can change the string in whatever way I want.

The problem is that sometimes values can be very very long, so the result is something like:

-------------------------------------------------------------------------------------------------------
Parameter 1 name:      Long Value 1                  Parameter 2 name:      Value 2
Parameter 3 name:      Value 3                  Parameter 4 name:      Long
Value 4
-------------------------------------------------------------------------------------------------------

What I would like is:
-------------------------------------------------------------------------------------------------------
Parameter 1 name:    Long                  Parameter 2 name:    Value 2
                                Value 1
Parameter 3 name:    Value 3              Parameter 4 name:    Long
                                                                                         Value 4
-------------------------------------------------------------------------------------------------------

What I tried was to put this string in a HTML formatted field in the report and use a HTML table to align things as wanted. However Crystal does not like tables in HTML - just skips them. The same with DIVs.

Can anyone give me an idea how to align things correctly? The HTML was just a shot, it's not necessary to use it.

Any help will be appreciated.
TheAvenger
Avatar of bdreed35
bdreed35
Flag of United States of America image

Can you send us a sample of what the data looks like when you send it?
Avatar of TheAvenger

ASKER

It's a simple string in C#. Something like:

"Period start:\t10/23/2003\tPeriod end:\t10/22/2004\nSelected product:\tThe car you always wished because this value is very long\nPrice:\tDon't ask"

The \n represents new line, the \t represents a tab character. I can change these characters with whatever is needed, e.g. <td> and </td> for table cells or something....

As long as you use a fixed width font, this formula should be close to what you want.  It doesn't split the param values at a space character - right now it just breaks it at 50 chars but it can certainly be changed to break at a space if that's what's needed.

//@DisplayFormula
stringVar p1;
stringVar p2;
stringVar p3;
stringVar p4;
stringVar Output := '';
stringVar param:= 'Parameter 1 Name: ' + {?Parameter1Value};
if length(param) > 50 then   <-- set your own value here
(
   p1 := left(param, 50);
   p2 := left(right(param, length(param)-50) + space(50),50);
)
else
(
   p1 := param;
   p2 := (50);
)
param := 'Parameter 2 Name: ' + {?Parameter2Value};
if length(param) > 50 then   <-- set your own value here
(
   p3 := left(param, 50);
   p4 := left(right(param, length(param)-50)+space(50),50);
)
(
   p3 := param;
   p4 := space(50);
)
Output := Output + p1 + p3 + chr(10) + chr(13);
if length(trim(p2 + p4)) > 0 then
   Output := Output + p2 + p4 + chr(10) + chr(13);

// Now repeat for param #3 & 4

Output;  

HTH

frodoman
SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just saw your posting with your data.  Forget the above because I misunderstood what you needed - thought you were actually passing in parameters.

Since you're passing this string from your c app anyway, why not just format it there to contain enough empty spaces and then display with a fixed width font?  It's possible in Crystal to parse the string out into pieces and append space characters but it would be much more efficient to do that in your application before you append everything together.

frodoman
@ frodoman: a little problem: the font is currently Verdana (so no fixed size) and cannot be changed as it is a customer requirement. Even if it was fixed size, the customer can change it in the future. So no fixed size solutions can fit here :-((

@ mlmcc: I know I can use RTF, however I have no idea what the contents of such field should be. Is it again a string with some format? Can you give me a short hint of how the contents should look like?
Simply use \tab in your format string - that's the rtf tag for a tab character.  You can see which tags are & aren't supported by Crystal here: http://support.businessobjects.com/library/kbase/articles/c2011504.asp

However, this still isn't going to get you the wrapping for long parameters.  For that you're going to need to parse out the string - is there a reason you can't send this information to Crystal in different parameters instead of all in one?  That would enable you to simply place the params themselves right on the report and format them to grow vertically (with 'Can Grow') and they would automatically retain the correct left-alignment...

frodoman
The only way I see that you can get these lined up all the time from within Crystal, is to create seperate formulas.
I created 4 formulas that you can place in the same section.  Make sure that you set Format Field, Common tab, Can Grow for all 4 formulas.

//@Col1
stringvar text := {?paramter};
stringvar array fields := split(replace(text,"\n","\t"),"\t");
local numbervar i;
local stringvar result := "";

for i := 1 to ubound(fields) do
(
    if i mod 4 = 1 then
        result := result & chr(13) & fields[i]
);
mid(result,2)

//@Col2
evaluateafter({@Col1});
stringvar array fields;
local numbervar i;
local stringvar result := "";

for i := 1 to ubound(fields) do
(
    if i mod 4 = 2 then
        result := result & chr(13) & fields[i]
);
mid(result,2)

//@Col3
evaluateafter({@Col1});
stringvar array fields;
local numbervar i;
local stringvar result := "";

for i := 1 to ubound(fields) do
(
    if i mod 4 = 3 then
        result := result & chr(13) & fields[i]
);
mid(result,2)

//@Col4
evaluateafter({@Col1});
stringvar array fields;
local numbervar i;
local stringvar result := "";

for i := 1 to ubound(fields) do
(
    if i mod 4 = 0 then
        result := result & chr(13) & fields[i]
);
mid(result,2)

Place all four in the same horizontal line.  Set the Can Grow property for each.
The one issue that I have so far is that if the value cannot fit on a single line, it will wrap around which may cause alignment problems for values on additional lines.
Let me know if this will be an issue or not.
@frodoman: Unfortunately simple tabs are not enough. I never know if I have to put one or two or more. For example:

Parameter 1 name: -> Value 1
Param 2 name: -> ->  Value 2

Here -> represents a tab and it is not clear how many should be there, as I don't know the lengths of the parameter names, especially when painted with that specific font. Also if the values are long, tabs will not help at all to align the values correctly.

@bdreed35: I can directly send the 4 columns as 4 different parameters, so a formula like this is not needed. However even if I have 4 fields, this will not solve the problem of long values. The result would be:

Param 1:   Long         Param 2: Value 2
Param 3:   Value 1     Param 4: Value 4
                Value 3

As you can see Value 3 is shifted down. Unfortunately I don't know how many characters will fit on a line, so I cannot pre-calculate this and add an empty line between Param 1 and Param 3
Actually with separate parameters you can simply create two detail sections and put param1 & 2 in DetailA and the other two in DetailB.  When Param1 expands vertically it will add the space necessary to shift down param 3 & 4 correctly.

frodoman
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This table is in the header part of the report -> it shows the parameters for the report. I have different detail sections
Look at my last post.  You can do this in whatever setion you want.
As mentioned in the original post, "The number of parameters can vary". So I don't know how many they are. They can be 2, but can be also 100. So two header sections will not work....
The only section that is repeated until the data ends is the details section, so I cannot do it with whichever section I want :-((
With a dynamic number of parameters the only way I can see that you'll every accomplish the alignment is with a formula that will parse out the string and insert line breaks where needed.  However, this will only save the alignment if you use a fixed width font which you've said you won't do - tabs aren't going to work because there's no way to evaluate the width of the text to determine how many tabs are necessary.

Sorry Avenger, but I just don't see any way to accomplish what you want with the restrictions you have.
I can alter my 4 formula solution to work for long data, but you would need to come up with the max length of a line of data.
For instance, if a parameter value is 50 characters, how wide should it be before it wraps to the next line?  20 chars, 25 chars, etc
@frodoman: that's why I tried to put tables with invisible borders. They can wrap everything the way I want it. However HTML does not work. I don't know about RTF, I have no example table, so that I can test it

@bdreed35: sorry, I don't know how many chars can fit. Have a look in any text editor (word for example) that supports the Verdana font. Write the following lines:
WWW
III
You can see it even here: 3 times W is much more than 3 times I. So how many Ws can you fit on one line before it breaks and how many Is? And how many random characters? This question is very difficult to answer and needs graphics, font sizes, distances, etc, etc.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

Try building a table in Word that satisfies your requirements.  Save it as an RTF file.  Look at the RTF in NOTEPAD to get the formatting specifications for RTF.

mlmcc
I tried that. It's huuuge and CR does not like it
OK, I succeeded to build an RTF that is accepted from CR and contains a table. However Crystal does not recognize/show the table at all. If I open an .RTF file in Word with the same content, it shows perfectly. So I suppose the RTF option does not work either.
@bdreed35: the subreport is actually not a bad idea. One simple problem though: Business Objects ask me to pay something like $20'000 for a kind of extension, enterprise something, if I want to use subreports in Web... I'll check further if there is another possibility to use the report in Web.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all for the help!
Glad i could help

mlmcc