[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Exporting Crystal 10 directly to excel file

Ok I have this working on one PC in a sub folder. When I move the code to another folder it won't work any more.  I've got the files now under my main web folder and the permissions all look right. It runs the script and redirects me, but never creates the xls file. The text file that comes with this example makes reference to ReportCacheVirtualDirectory and resetting it, but they don't have it set in thier example. HELP!!!

Here is the file....


' CONCEPT                                                            
'  ALWAYS REQUIRED STEPS (contained in AlwaysRequiredSteps.asp)
'   - create the application object                                
'   - create the report object                                    
'   - open the report                                              
'   - set a variable to reference the ExportOptions Object of the report
'   - set the ExportOptions for the report including the export destination and export type
'   - redirect the user to the newly exported file so they are prompted to download or view
'     the file

' This line creates a string variable called reportname that we will use to pass
' the Crystal Report filename (.rpt file) to the OpenReport method contained in
' the AlwaysRequiredSteps.asp.

reportname = "reports/SimpleReportExport.rpt"

' ALWAYS REQUIRED STEPS - Version for Exporting (does not create report or
' application objects in session)
' Include the file AlwaysRequiredStepsExport.asp which contains the code    
' for steps:
'   - create the application object
'   - create the report object
'   - open the report
<!-- #include file="AlwaysRequiredStepsExport.asp" -->                      


Set CrystalExportOptions = oRpt.ExportOptions

'This line of code set a variable to reference the ExportOptions Object.

'The variables below (ExportFileName, ExportDirectory, ReportCacheVirtualDirectory,
'and ExportType) are used as follows:
'  - ExportFileName is the actual file name that should be created by the export process
'  - ExportDirectory is the physical directory where the ExportFileName will be placed
'  - ExportType is a number that specifies the type of file that the export process should
'    create.  For a list of these numbers, please refer to the Crystal Reports Report Design Component
'    help file (crrdc.hlp) in the "ExportOptions Object for the Object Model" section.  Scroll down to
'    the ExportType property.  To change the type of file that the export process should be creating, change
'    the value in the ExportType variable, and change the last portion of the ExportFileName
'    variable.  The example here exports a .doc file, which is a Word file, which is the
'    ExportType "14".
'    Some export types have other properties in the ExportOptions object that require values
'    to be set.  For example exporting to HTML.  This type will require that you will also
'    set the HTMLFileName property.  For detailed information on which properties to set,
'    refer to the "ExportOptions Object" topic in the help file (crrdc.hlp)

ExportFileName = "ExportedReport.xls"

Path = Request.ServerVariables("PATH_TRANSLATED")                    
While (Right(Path, 1) <> "\" And Len(Path) <> 0)                      
iLen = Len(Path) - 1                                                  
Path = Left(Path, iLen)                                              
'The While/Wend loop is used to determine the physical location
'of the SimpleReportExport.asp so that we can save the
'ExportedReport.doc in the same location.                                                                  

ExportDirectory = Path
ExportType = "38"

CrystalExportOptions.DiskFileName = ExportDirectory & ExportFileName
'This line of code specifies the physical location and file name to give
'the export result.

CrystalExportOptions.FormatType = CInt(ExportType)
'This line of code specifies the export format (in this case MS Word).

CrystalExportOptions.DestinationType = CInt(1)
'This line of code specifies that the export destinatin is to be disk.

oRpt.Export False                    
'This line of code turns of any prompting when exporting.

Response.Redirect ("ExportedReport.xls")
'This line of code redirects the URL to the newly exported file.
'It is important to remember that the exporting is taking place on the web server
'so we need to redirect the user to the newly exported file or they will never
'have access to that file.
1 Solution
Shouldn't the export type be set to a number?  The example above is setting it to a string...ExportType = "38", I think should be,  ExportType = 38

Have you tried replacing the variables (ExportDirectory, ReportCacheVirtualDirectory,and ExportType) with hard-coded values to see if that at least works?

Is the file being exported anywhere?  You might want to search to see if it's being exported but perhaps not where you think it is.  You said permissions look correct so I assume you've granted 'write' access to the folder for whatever user context this application is running under?  You also need to insure that you have 'read' access to the folder containing the Crystal export dll's.

If you can't figure out where the problem is you might want to use the FILEMON utility to see if there is an 'access denied' error taking place anywhere in the process.

t1clausenAuthor Commented:

Had to set the write permissions and it created the file but it was a 0 byte file. Clicked the link above and found the way around that. Thanks!

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now