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

Easiest way of supressing formatting when printing to file?

edited February 2002 in General
I have a given report with currency fields with display format set to
",0.00;(,0.00);0"

When printing to a text file, the commas cause problems if imported into
Excel. What is the easiest way to supress this formatting for this purpose?
Note that I am using the standard preview form and the print to file is
occuring from there.


John

Comments

  • edited February 2002
    Check the device type when printing, and set the display format accordingly.
    If you check the device type in the Report.BeforePrint event, you'll notice
    that the report's device type is never changed, even though you've selected
    a different device type in the print dialog. This is done, so that the next
    time you print, the device type will be what it originally was. You'll need
    to reference the Report.PrintDialog.DeviceType property to compare it to
    dtTextFile.


    if ppReport1.PrintDialog.DeviceType <> dtTextFile then
    ppDBText1.DisplayFormat := '$#,0.00;($#,0.00)'
    else
    ppDBText1.DisplayFormat := '0.00;-0.00';


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2002
    "Jim Bennett (Digital Metaphors)" wrote in
  • edited February 2002
    I've tested this code on a simple case - my upfront concern is subreports.
    Will this code address subreports, or do I have to figure that one out on my
    own?

    Thanks,

    -------------------------

    procedure ToggleCurrencyFormatsForTextExport(const aReport : TppReport);

    procedure ToggleBand(const aBand : TppBand; const aMask : string);
    var
    i: Integer;
    localDBText : TppDBText;
    begin
    for i := 0 to aBand.ObjectCount - 1 do
    begin
    if (aBand.Objects[i] is TppDBText) then
    begin
    localDBText := TppDBText(aBand.Objects[i]);
    if
    localDBText.DataPipeline.GetFieldDataType(localDBText.DataField) =
    dtCurrency then
    begin
    localDBText.DisplayFormat := aMask;
    end;
    end;
    end;
    end;

    const
    STR_TEXTEXPORT = '0.00;-0.00;0';
    STR_STDFORMAT = ',0.00;-,0.00;0';
    var
    localBand : TppBand;
    localIsPrintingToText : boolean;
    localMask : string;
    i: Integer;
    begin
    localIsPrintingToText := (aReport.PrintDialog.DeviceType = dtTextFile);
    if localIsPrintingToText then
    localMask := STR_TEXTEXPORT
    else
    localMask := STR_STDFORMAT;

    for i := 0 to aReport.BandCount - 1 do
    begin
    ToggleBand(aReport.Bands[i], localMask);
    end;
    end;
  • edited February 2002
    If you are looping through a report looking for dbTexts, then you can also
    look for TppSubreport, then call the ToogleCurrency() passing
    Subreport.Report as the parameter.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2002
    Thanks - that's what I thought.


    John

  • edited February 2002
    "Jim Bennett (Digital Metaphors)" wrote in
  • edited February 2002
    The print dialog is created when the report is printed to the printer. The
    BeforePrint event will fire both when the report is previewed to the screen,
    and when the report is printed. Checking for nil is always a good thing.


    Cheers,

    Jim Bennett
    Digital Metaphors Corp



This discussion has been closed.