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

XLS Report export alignment

edited March 2011 in Devices
Hi,

We're using Delphi 2009, RB 12.04 Ent.

There appears to be a problem with right-aligned text fields when
exporting to XLS Report format. If we create reports that have header
text that is right-aligned but detail text that is left aligned (like a
financial report, for example) the header text and detail text will end
up in different columns when the report is exported to Excel, even if
they were the same size and aligned with each other at generation and
look aligned in both preview and PDF export. This is with
MergeAdjacentCells turned OFF.

I've played with the code, and commenting out the whole of:


// adjust ColumnIndex to reference the left most column in the range
if (lDrawText <> nil) then
begin
case lDrawText.TextAlignment of
taLeftJustified: ; // nothing

taCentered:
begin
liColumnIndex := liColumnIndex - (liColumnRange div 2);
if liColumnIndex < 0 then
liColumnIndex := 0;
end;

taRightJustified:
begin
liColumnIndex := liColumnIndex - liColumnRange + 1;
if liColumnIndex < 0 then
liColumnIndex := 0;
end;

end;
end;

from the TppXLSRendererCell.AddCell() function in ppXLSRenderer.pas
improves the situation a lot. This probably wouldn't be the case if
MergeAdjacentCells was TRUE though, but with it set to false it seems to
me that there's no need to worry about the column range, as it should
really always be 1. I do wonder if that whole section should be
conditional on XLSSettings.MergeAdjacentCells being true.

I have XLS and PDF files of the same report to demonstrate what I mean
by this, if you want them.

Thanks,

Steve Branley

Comments

  • edited March 2011
    Sorry to reply to my own post, but looking at this again I wonder if
    it's the alignment that's causing the problem at all because, although
    what I've changed does fix our problem, I've noticed that both the
    header fields AND the detail fields are right aligned and yet end up in
    different columns. The header field is only three characters though, and
    some of the detail values are so long that they are wider than the
    default Excel column widths, so I wonder if this actually has more to do
    with it?

  • edited March 2011

    Thanks for the feedback. Adjusting the ColumnIndex only when
    MergeAdjacentCells is true, is a good idea. I added the following check.

    if XLSSettings.MergeAdjacentCells and (lDrawText <> nil) then

    Also note that if a column heading and detail are aligned the same, then a
    good way to ensure they map to the same cell, is to set AutoSize to False
    and make them have the same width.

    If the column heading and detail have different text alignments, then
    problems can arise because one might be mapped based on it's left position
    and the other mapped based on it's right position.


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.