WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Export Data crom Crystal Reports to Excel


I use Crystal Reports 9 Professional Edition and I am not sure if that makes a difference. My full script is below(I have removed the database name etc.). This has run every day since September 2004 and has never failed. What more can we ask of a script!

; This script reads data from an ini file (number of reports to do and names of reports)
; and updates the Alpha codes and winLims numbers contained in a series of Excel spreadsheets.
; Designed for Crystal Reports 9 Professional Edition
; written by G W Payne September 2004.

;get directory we start in and add ini file name
ThisDir=DirGet()
IniFile=StrCat(ThisDir,"AlphasUpdate.ini")
;read number of reports to do
NumReports=IniReadPvt("Report Info","NumReports","",IniFile)
;fire up crystal
cra = objectopen("CrystalRuntime.Application")
;log on to database
cra.LogOnServer("PDSODBC.DLL","","","","")
;loop for number of reports
for i=1 to NumReports
   ;create header first one is "Report1"
   IniReportHead=StrCat("Report",i)
   ;go read file name for Report from ini file
   Report=IniReadPvt("Reports",IniReportHead,"",IniFile)
   ;create header for Export name first one is "Output1"
   IniExportHead=StrCat("Output",i)
   ;go read export file name from ini file
   ExportName=IniReadPvt("Outputs",IniExportHead,"",IniFile)
   ;open report
   crr = cra.OpenReport(Report)
   ;discard old data
   crr.DiscardSavedData()
   ;get data
   crr.ReadRecords()
   ;set export option - create link
   cre = crr.ExportOptions
   ;output is a diskfile
   cre.DestinationType = 1 ;diskfile
   ;formattype 30 is Excel8 data only
   cre.FormatType = 30 ; Excel8 data only
   ;set export file name
   cre.DiskFileName = ExportName
   ;make sure we export all data
   cre.ExcelExportAllPages
   ;close export options
   objectclose(cre)
   ;go export without asking for options
   crr.Export(BOOL:@false)
   ;close report
   objectclose(crr)
next
;close crystal application
objectclose(cra)
Exit 

Article ID:   W17194
File Created: 2007:07:03:14:28:42
Last Updated: 2007:07:03:14:28:42