Exporting Crystal 10 directly to excel file

Posted on 2006-05-09
Last Modified: 2010-08-05
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.
Question by:t1clausen
    LVL 7

    Expert Comment

    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?

    LVL 42

    Accepted Solution

    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.

    LVL 2

    Author Comment


    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    760 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

    10 Experts available now in Live!

    Get 1:1 Help Now