Changing code to export print data.

Posted on 2005-04-25
Last Modified: 2010-04-04

To start I understand barely anything regarding delphi.  I have some experience programming in
C++ and of course html so I can understand what parts do what.  What I need to be able to do
is setup an export button to export the same data that the print button prints.

The following code is currenlty being used:

procedure TfrmJobListing.sbtprintClick(Sender: TObject);
  if tnbJobMast.ActivePage='Job List' then
  if tnbJobMast.ActivePage='Job Cost' then


This code above is used to print certain data to a "print screen".
This data above is the data that I need to be able to export.

procedure TfrmJobListing.sbtexportClick(Sender: TObject);
    if tnbJobMast.ActivePage='Job List' then

    if tnbJobMast.ActivePage='Job Cost' then
       dgrJobCost.ExportOptions.FileName:= dm.tblUsers.fieldbyname('exp_path').AsString+'\JobCost.xls';

This code above currently exports the data in the main table to an excel spreadsheet.  I do not need the data
in the table but rather the same data that the print code generates.

I have tried replacing the dgrJobCost with the ppReport1 with nothing but errors.  I figure for some delphi
guru out there this will be a breeze.

I appreciate the help,

Question by:c230kochi
    LVL 15

    Expert Comment

    Is ppReport some thrid party reporting component you are using to display data?
    How are you passing the data you want to display to the reports?
    LVL 1

    Author Comment

    I have no idea, I didn't originally write this code.  The last administrator developed all of their
    programs using delphi, when I replaced him they assumed that all network admins new how
    to program in delphi (that was a good chuckle).  I couldn't find much info on the ppReport
    function other than its type being TppReport, and these procedures.  I don't understand the
    code enough to know how ppReport generates its data.  

    procedure ppReport2PreviewFormCreate(Sender: TObject);

    procedure ppReport1PreviewFormCreate(Sender: TObject);

    procedure TfrmJobListing.ppReport2PreviewFormCreate(Sender: TObject);
      ppReport2.PreviewForm.WindowState := wsMaximized;

    LVL 15

    Expert Comment

    >> when I replaced him they assumed that all network admins new how to program in delphi<<
    Best line Ive heard in ages c230kochi. Has it just been dumped in your lap then?

    It sounds like this is a third party component to me for the reporting purposes.
    It might be an idea to find out where the data is getting passed from to the report.
    Maybe there is a query result set being passed to the report that we can tap into.

    Is there any code within the report unit under the OnCreate, OnShow, OnActivate that might start our search off for your dataset?

    LVL 15

    Expert Comment

    This dgrJobCost, can you find out where it is declared, and what type it is declared as.
    Im guessing the ExportOptions.Save has some code behind it to possibly detect what file type you are trying to save to, in your case excel, and perform the specific task. Maybe this component only saves to excel and nothing else.
    LVL 1

    Author Comment

    Yeah its all been pretty much dumped in my lap, this is one of about 4 things they want changed/added.
    I love this field, you say, "I'm microsoft and cisco certified, I have experience with wan/lan technologies
    in microsoft environments including exchange, and I specialize in security."  They hear I do stuff with
    computers and I know how to fix them and anything else that has to do with a computer, which includes
    but isn't limited too, custom software, programming, unix, linux, macintosh, and whatever else comes up.
    LOL, but oh well I like my job, I just have to learn delphi.  BTW, any suggestions on where I can take
    QUALITY courses on delphi programming.  Seeing as I will be here for the next 5 years or so, I should
    probably learn it.

    okay, to the problem at hand.  The ppreport is a third party program called ReportBuilder.  Looking through ReportBuilder
    I could not find a "save as" or "export" feature, it would only let me manipulate the table

    Below is some more code, don't know if its useful.

      object ppReport2: TppReport
        AutoStop = False
        DataPipeline = ppBDEPipeline2
        PrinterSetup.BinName = 'Default'
        PrinterSetup.DocumentName = 'Report1'
        PrinterSetup.Orientation = poLandscape
        PrinterSetup.PaperName = 'Letter (8 1/2" x 11")'
        PrinterSetup.PrinterName = 'Default'
        PrinterSetup.mmMarginBottom = 6350
        PrinterSetup.mmMarginLeft = 6350
        PrinterSetup.mmMarginRight = 6350
        PrinterSetup.mmMarginTop = 6350
        PrinterSetup.mmPaperHeight = 215900
        PrinterSetup.mmPaperWidth = 279401
        PrinterSetup.PaperSize = 1
        DeviceType = 'Screen'
        OnPreviewFormCreate = ppReport2PreviewFormCreate
        TextFileName = 'c:\joblist.xls'
        Left = 143
        Top = 435
        Version = '6.03'
        mmColumnWidth = 0
        DataPipelineName = 'ppBDEPipeline2'
        object ppHeaderBand2: TppHeaderBand
          mmBottomOffset = 0
          mmHeight = 13229
          mmPrintPosition = 0
          object ppLabel12: TppLabel
            UserName = 'Label101'
            Caption = 'Job Status Report'
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clBlack
            Font.Name = 'Arial'
            Font.Size = 12
            Font.Style = [fsBold, fsUnderline]
            Transparent = True
            mmHeight = 5027
            mmLeft = 82550
            mmTop = 1323
            mmWidth = 36513
            BandType = 0

    Something to do with the existing export function

     object tnbJobMast: TTabbedNotebook
        Left = 1
        Top = 70
        Width = 770
        Height = 359
        TabFont.Charset = ANSI_CHARSET
        TabFont.Color = clBtnText
        TabFont.Height = -12
        TabFont.Name = 'Tahoma'
        TabFont.Style = [fsBold]
        TabOrder = 4
        OnChange = tnbJobMastChange
        object TTabPage
          Left = 4
          Top = 24
          Caption = 'Job List'
          object dgrJob: TwwDBGrid
            Left = 1
            Top = 1
            Width = 759
            Height = 325
            Selected.Strings = (
              'jobno'#9'8'#9'Job #'#9'F'
              'contr_date'#9'7'#9'Contract Date'#9'F'
              'contr_no'#9'10'#9'Contract #'#9'F'
              'contrt_amt'#9'12'#9'Contract Amt'
            IniAttributes.Delimiter = ';;'
            ExportOptions.ExportType = wwgetHTML
            TitleColor = clBtnFace
            FixedCols = 0
            ShowHorzScrollBar = True
            BiDiMode = bdLeftToRight
            ParentBiDiMode = False
            Ctl3D = True
            Font.Charset = ANSI_CHARSET
            Font.Color = clWindowText
            Font.Height = -12
            Font.Name = 'Tahoma'
            Font.Style = []
            Options = [dgAlwaysShowEditor, dgTitles, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgWordWrap]
            ParentCtl3D = False
            ParentFont = False
            TabOrder = 0
            TitleAlignment = taLeftJustify
            TitleFont.Charset = DEFAULT_CHARSET
            TitleFont.Color = clWindowText
            TitleFont.Height = -11
            TitleFont.Name = 'MS Sans Serif'
            TitleFont.Style = []
            TitleLines = 1
            TitleButtons = False
            UseTFields = False
            PaintOptions.AlternatingRowColor = 8453888
            PaintOptions.ActiveRecordColor = clNavy
    LVL 1

    Author Comment

    dgrJobCost is declared as a TwwDBGrid

    It was originally set to save as a .htm file but I wanted excel so the users can alter the cells.
    LVL 15

    Accepted Solution

    the components with ww in the name are call Woll to Woll components widely used through the delphi environment (except for me that is ... dont like databound stuff too much). Some more info on how to use them can be found at
    You might even find a tutorial on exporting data here which could be of use.

    Ive heard of reportbuilder before but not used or seen it myself. You might get lucky doing a search here on it with some helpful hints.
    Its just a bit hard not knowing all the interal methods you might have available to save your report data, or I might be able to suggest something a bit more conclusive for you.

    I went on a delphi external course a while back now with a company called Dunstan and Thomas which were pretty good, and they can tailor the courses to your needs/skill level fairly well. Depends how much of the basic concepts you already know from your other programming.
    Also with the .NET architecture now out, you will have to decide whether you need to look into this as well unless you can do that through another language.

    Let me have another think tonight on the subject and maybe I can find some more information for you.
    Im sure others here have used these components before, and hopefully they might spot this question and leave some more useful advice than mine.
    LVL 1

    Author Comment

    I since have solved this issue.

    Please close.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now