Export to XLSReport and Changing Font Colors

edited April 2012 in Devices
Hi,

When exporting text which has a font color of white and opening it in
Excel the text is hidden as it blends into the background of the cells
which are also white in Excel (I can change the font color by
highlighting the cells and changing the color).

However I want to automate this when a report is exported and have the
text color changed to black when the color of the text being exported
is white.

What is the best way of achieving this?

David.

Comments

  • edited April 2012
    Hi David,

    If the user is exporting to XLS, I would suggest performing a report
    object loop before printing (BeforePrint event perhaps) and altering the
    text color of each text component in the report if needed. You will
    then need to run another loop after to return the color back.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Layouts/Report_Object_Loop

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2012
    Hi Nico,

    I have added some code to the BeforePrint and AfterPrint functions
    for the report. The BeforePrint code I use works and the labels change
    to black in the ppViewer, however the AfterPrint code is not resetting
    the color back to white.

    Just to give you some background information. The user first
    previews the report to a ppViewer and there is a button on the form
    which allows the user to print the report to file.

    When they do this I can see the headings change to black in the ppViewer
    but the labels are not changing back to white after printing.

    Any help would be appreciated.

    David.

  • edited April 2012
    Hi David,

    If you trace into the AfterPrint event's code, is it actually executing?

    Perhaps try creating two Report Object Loop routines, one to turn all
    text black and one to return it to white. Then just inside the
    BeforePrint event, if the DeviceType is XLS, call the black text
    routine, if the DeviceType is something else, call the white text routine.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2012
    Hi Nico,

    Yes the AfterPrint event is calling the code I have to change the
    color back, however the color is not changing in the ppViewer.

    David.

  • edited June 2012
    Hi David,

    This likely means the AfterPrint will not work for this requirement.
    Did you try my second suggestion of only using the BeforePrint?

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2012
    Hi Nico,

    You reply below will not work for my situation. My issue is more to
    do with a single report just being exported to XLS from the ppViewer.

    Currently the report is print previewed to screen in a ppViewer. The
    user can hit a button at the top of the ppViewer to export the report
    using a number of different formats ie. XLS, PDF etc.

    The labels in the header are displayed in white. When exporting to
    XLS I have code in the BeforePrint to change the labels from white to
    black. However I need to somehow change them back to white again in the
    ppViewer after the report has been exported to XLS.

    So as you can see I am only exporting a single report once to XLS in
    this situation.

    David.


    David.

  • edited June 2012
    Hi David,

    I now see what is happening. You are using a custom viewer rather than
    the built-in previewer. The screen device is still connected when you
    export so when you generate to XLS, the viewer is also updating.

    In this case, you are going to want to disconnect the screen device from
    the viewer before exporting the report to XLS. This is similar to the
    code inside the TppViewer.Print routine (which is called from the
    previewer).

    Viewer.ScreenDevice.Publisher := nil;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2012
    Hi Nico,

    I set the publisher to nil in the OnBeforePrint event and then change
    the color of the labels.

    On the OnAfterPrint I re-attach the publisher.

    However after the report has printed and I go to the next page in the
    ppViewer by click the next page button the text is black.

    David.

  • edited June 2012
    Hi David,

    At what point are you changing the text color back to white? Are you
    certain this code is firing?

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.