#Include "inkey.ch"
Function Main()
Local nInitialCust, nFinalCust
nInitialCust := 1
nFinalCust := 9999
CLS
@1,1 SAY "First Customer .:" GET nInitialCust PICTURE "9999"
@2,1 SAY "Final Customer :" GET nFinalCust PICTURE "9999" VALID nInitialCust <= nFinalCust
READ
IF LastKey() != K_ESC
USE customers NEW
SET PRINTER ON
SET DEVICE TO PRINTER
WHILE !EOF()
IF field->code >= nInitialCust .and. field->code <= nFinalCust
? field->code,field->name
ENDIF
dbskip(1)
END
EJECT
SET DEVICE TO SCREEN
SET PRINTER OFF
dbCloseArea()
ENDIF
RETURN NIL
The result ? If everything was fine, some text printed on a dot matrix printer. But then things started to change. First, GDI printers only. It was impossible for Clipper to print to that. Then customers start asking to output to pdf files, email, word....
These days ? Well, i'm using harbour, and the need for printing to diferent options is still the same. The code base is the same, only the output mechanism as changed.
#Include "inkey.ch"
Function Main()
Local nInitialCust, nFinalCust, oReport
nInitialCust := 1
nFinalCust := 9999
CLS
@1,1 SAY "First Customer .:" GET nInitialCust PICTURE "9999"
@2,1 SAY "Final Customer :" GET nFinalCust PICTURE "9999" VALID nInitialCust <= nFinalCust
READ
IF LastKey() != K_ESC
oReport := TOleAuto():New("ReportMan.ReportManX")
oReport:Filename := "customer.rpt"
oReport:Preview = .T.
oReport:Title := "Customers List"
oReport:SetParamValue("nInitial",nInitialCust )
oReport:SetParamValue("nFinal",nFinalCust )
oReport:Execute()
ENDIF
RETURN NIL
The output ? The following window.
From there, the user as several choices : print, save as pdf, excel, html and others, and attach it to a email message.
How ? Using a very nice report designer called Report Manager. Its free and as many nice features that make it rival with comercial packages like crystal reports.
A quick step by step guide for making it work with our sample code follows up.
First, get it from is web page : Reportman Homepage. Download the full package and install it on your computer.
Next, if like me, you still are using dbfs for small projects, get a oledb driver, like visual foxpro oledb driver or the one from ads. This drivers will allow report manager to connect to your dbfs via dao.
The steps :
- Open the Designer XP from your programs and start a new report.
- From the report menu, choose the second option to setup data access.
- Choose "Microsoft DAO" and click the add button and name the new connection "custConn".
- Click the "Search" button and choose "Microsoft oledb for visual foxpro"
- Click the "Next" button and choose the path where your dbfs are (make sure you select the option that says "free table directory")
- Choose the "report tables" separator add a table to the report, naming it customers.
- On the right box, write select * from customers where code between :nInitial and :nFinal
- Click the "Parameters" button and add two integer parameters, naming them nInitial and nFinal. Dont forget to associate them with the table customers. Set the first to default value of one and the other to 9999.
- Close the parameters window and click the "show data" just to check that there are no mistakes so far. Click the "Ok" button, to close the data setup part of our report.
- Choose the data separator and expand the customers entry. There you should find all the fields from the customers table.
- Drag the fields you want to the detail line.
- Again from the report menu, add a header/footer group.
- Add headers to the fields you choosed (click the "A" button and click&drag the mouse on the header section. Set the label text to the value you want.)
- Test your report, choosing the preview option.
And that is all. Save the report to same location of your dbf and prg, naming it report.rpt
If you save the above sample as test.prg, with harbour you can test it using hbmk2 test.prg -lhbwinOf course dont forget that you need a customers.dbf with some sample data.
Since the above sample uses OLE, its a windows only solution. Both Harbour and Reportmanager are Linux capable tools. On the next post, i will present a more portable way of interfacing Reportmanager with Harbour.
Hello Nelson,
ResponderEliminarThis is very like Crystal Reports as you mentioned.
Thanks for sharing it.
I will wait to see the portable solution that works on Windows and in Linux.
Regards
Qatan