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

Export to Excel from TppViewer

edited February 2012 in Devices
Hi,

Report Builder ver. 14.02 - Delphi 2007.

If I execute the code below, it runs correctly and generates the Excel file:
with ppReport1 do begin
DeviceType := 'XLSReport';
TextFileName := 'c:\temp\report.xls';
ShowPrintDialog := False;
XLSSettings.OpenXLSFile := True;
Print;
end;

If I introduce a TForm with a TppViewer, it does not work and raises an
exception:
Form2.ppViewer1.Report := ppReport1;
with Form2.ppViewer1.Report do begin
DeviceType := 'XLSReport';
TextFileName := 'c:\temp\report.xls';
ShowPrintDialog := False;
XLSSettings.OpenXLSFile := True;
Print;
end;

It generates the Excel file, but it seems, after this, it tries to generate
again the file.
Report Builder ver. 14.01 does not show this problem.
This problem does not allow you to use a custom preview form.
Is there a solution?

Thanks.

Franco

Comments

  • edited February 2012
    Look at TppViewer.Print and TppViewer.WalkieTalkieEventNotifyEvent.
    This is a very good example how to make correct export from preview.

  • edited February 2012
    Hello Dima,

    thank you for the answer.

    I examined the two methods and I noticed that before the launch printing, in
    the method TppViewer.Print, it clears FScreenDevice.Producer.
    I added the line (before Print)
    Form2.ppViewer1.ScreenDevice.Producer: = nil;
    and the problem seems solved.
    The code I have used up to now had been created with Delphi 6 and Report
    Builder ver. 5 back in 2001; it has always worked well until recently with
    Delphi 2007 and Report Builder 14.01.
    Question: why now, with Report Builder ver. 14.02 (it's the same with the
    ver. 14.03), I have to clear ppViewer.ScreenDevice.Producer? Should not it
    be automatic, since the code works with TppReport (Form2.ppViewer1.Report)
    and not with TppViewer?

    Best regards.

    Franco






    "Dima" ha scritto nel messaggio
  • edited February 2012
    Cannot reproduce your bug.
    How you refresh Viewer?
    What is the value of ppViewer.SinglePageOnly property?
    Can you show (attach) a simple project for reproduce this bug?

    In any case, it's a very good practice to clear
    ppViewer1.ScreenDevice.Producer
    before print on other device.
    Report.Print method calls PrintToDevices.
    As result, report reprints on all connected devices (on ScreenDevice also).
    And when ppViewer.SinglePageOnly = False - all cache pages will be
    regenerated.

  • edited February 2012
    Hi Dima,

    Perhaps you can not reproduce the bug because Excel does not open the file.
    I have tried to exclude Excel and the bug does not show.
    The problem is that Print creates the file twice: if Excel opens the file
    (XLSSettings.OpenXLSFile: = True), the second time the file is busy.

    The code that I reported was generated and tried to replicate the problem;
    of course the use of TppViewer in this code makes no sense except to show
    the problem; in fact, in my application, I show the form of preview and from
    that you can start printing.

    Attached a small project that can replicate the problem.

    Best regards.

    Franco







    "Dima" ha scritto nel messaggio
  • edited February 2012
    RB 14.3, Delphi XE - cannot reproduce this bug.
    Your project worked correct.

    Don't have Delphi 2007.
    I am try to test with RB 14.2 Delphi XE some more later.

  • edited February 2012
    OK, Dima.

    I do not have Delphi XE.
    The solution to clean the ppViewer1.ScreenDevice.Producer seems to eliminate
    the problem, so I will use that (and may be useful for those who read this
    post).

    Thank you for the time you spent.

    Franco


    "Dima" ha scritto nel messaggio
  • edited February 2012
    Hi Franco,

    For future reference, please send all attachments to
    support@digital-metaphors.com.

    I tested your app with Delphi 2007 and RB 14.03 and it functions
    correctly without error. I would first suggest upgrading to RB 14.03
    and testing with that.

    Best Regards,

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