Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Cross Tab Matrix Formatting

edited May 2002 in General
When adding rows to a TppCrossTab's Matrix I noticed that all the cells in
the added rows take on the cell formatting of the Top Dimension for a Cross
tab. Or at least in my cross tab it only has one dimension.
My quesiton is why does it do this?
And is there any way to controll how a cell is formatted when or after a new
row is added to the Matrix?

I tried using the OnFormat event for the Cross Tab and that didn't work.

I did the following to add additional rows to the Cross Tab matrix.

procedure TfmDR.CrossTabMatrix(var lCrosstab: TppCrosstab);
var
Mrow, Mcol: Integer;
liColCount, liRowCount: Integer;
lsText: String;
lValue: Double;
lMatrix: TppMatrix;
begin
lMatrix := lCrossTab.Matrix;
liColCount := lMatrix.ColumnCount;
liRowCount := lMatrix.RowCount;

for Mrow := 2 to liRowCount - 1 do
begin
lMatrix.AppendRows(1, dtString);
for Mcol := 2 to liColCount - 2 do
begin
lValue := (lMatrix.Value[Mcol, Mrow] / lMatrix.Value[liColCount - 1,
Mrow]) * 100.0;
lsText := FloatToStrF(lValue, ffFixed, 15, 2) + '%';

lValue := lMatrix.Value[Mcol, Mrow];
lsText := FloatToStrF(lValue, ffNumber, 15, 0) + ' ' + lsText;

lMatrix.Value[Mcol, lMatrix.RowCount - 1] := VarAsType(lsText, $0100);
end;
lMatrix.Value[lMatrix.ColumnCount - 1, lMatrix.RowCount - 1] :=
FloatToStrF(lMatrix.Value[lMatrix.ColumnCount - 1, Mrow], ffNumber, 15, 0);
lMatrix.Value[0, lMatrix.RowCount - 1] := lMatrix.Value[0, Mrow] ;
lMatrix.Value[1, lMatrix.RowCount - 1] := lMatrix.Value[1, Mrow] ;
end;
lMatrix.DeleteRows(2, liRowCount - 1);
end;

Comments

  • edited May 2002
    Please check out the demo below for an example that should give you an idea
    of how to accomplish this. In the demo new rows are added to the crosstab in
    the AfterCalc event and then certain cells are individially formatted in the
    OnFormat event.

    http://www.digital-metaphors.com/tips/CrossTabPercentages.zip

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited May 2002
    Thanks for the response Alexander. That was something I have already tried.
    However the formatting falls over onto all of the added rows of the matrix.

    Even when I do this
    if aColumn = 3 then
    aElement.Font.Color := clBlue;

    It formats all of the first Dimension font blue.

    I don't know if this is related, but I am trying to do the formatting in
    RAP.

    Bill
    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited May 2002
    You have to provide an else case, that is you need to have

    if aColumn = 3 then
    aElement.Font.Color := clBlue
    else
    aElement.Font.Color := clSomeColor.

    This is because the element is used to format multiple cells and does not
    reset itself after you set formatting options on it.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited May 2002
    Unfortunately font style is not part of RAP so I will have to go with a
    passthrough function.

    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited May 2002
    Font.Style is not available as a Set type property, but each individual
    element of that set is available as a boolean property:

    aElement.Font.Bold := True;
    aElement.Font.Italic := True;
    aElement.Font.Underline := True;

    Cheers,

    Tom Ollar
    Digital Metaphors Corporation
This discussion has been closed.