ASP.NET - EXPORTAR REPORTES DESDE UNA APLICACIÓN WEB AL USUA

 
Vista:

EXPORTAR REPORTES DESDE UNA APLICACIÓN WEB AL USUA

Publicado por OSCAR (1 intervención) el 02/06/2005 23:02:11
TENGO UNA APLICACIÓN WEB ASPX QUE PRESENTA REPORTES DE CRYSTAL REPORTS, NECESITO EXPORTARLOS EN DIFERENTES FORMATOS (.DOC, .XLS, .PDF) Y AL HACERLO ME LO EXPORTA AL SERVIDOR PERO NO AL EQUIPO DE LOS USUARIOS.

ESTOY TRABAJANDO CON VISUAL.NET 2002.
EL CÓDIGO ES:

Sub ExportReport()
' This subroutine uses a case statement to determine the selected export format from the dropdownlist
' menu and then sets the appropriate export options for the selected export format. The report is
' exported to a subdirectory called "Exported".

' ********************************
'Check to see if the application directory has a subdirectory called "Exported".
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.

ExportPath = "C:\Exported\"
If Directory.Exists(ExportPath) = False Then
Directory.CreateDirectory("C:\Exported\")
End If
' ********************************

' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = crReportDocument.ExportOptions

'Find the export type specified in the dropdownlist and export the report. The possible export format
'types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
'HTML 3.2 (HTML) and HTML 4.0 (HTML)
'
'Though not used in this sample application, there are options that can be specified for various format types.
'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
'first page, last page or page range to be exported.
'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
'the column width etc.

Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.

'Case "Rich Text (RTF)"
' 'Export to RTF.

' 'append a filename to the export path and set this file as the filename property for
' 'the DestinationOptions class
' crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf"

' 'set the required report ExportOptions properties
' With NALMES.ExportOptions
' .ExportDestinationType = ExportDestinationType.DiskFile
' .ExportFormatType = ExportFormatType.RichText
' .DestinationOptions = crDiskFileDestinationOptions
' End With

Case "Portable Document (PDF)"
'Export to PDF

'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf"

'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With

Case "MS Word (DOC)"
'Exportar a Word
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class

crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With

Case "MS Excel (XLS)"
'Export to Excel
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls"

'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With

'Case "Crystal Report (RPT)"
' 'Export to Crystal reports:
' 'append a filename to the export path and set this file as the filename property for
' 'the DestinationOptions class
' crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt"

' 'set the required report ExportOptions properties
' With NALMES.ExportOptions
' .ExportDestinationType = ExportDestinationType.DiskFile
' .ExportFormatType = ExportFormatType.CrystalReport
' .DestinationOptions = crDiskFileDestinationOptions
' End With

'Case "HTML 3.2 (HTML)"
' 'Export to HTML32:

' Dim HTML32Formatopts As New HTMLFormatOptions()

' With crExportOptions
' .ExportDestinationType = ExportDestinationType.DiskFile
' .ExportFormatType = ExportFormatType.HTML32
' End With

' With HTML32Formatopts
' .HTMLBaseFolderName = ExportPath + "Html32Folder" 'Foldername to place HTML files
' .HTMLFileName = "HTML32.html"
' .HTMLEnableSeparatedPages = False
' .HTMLHasPageNavigator = False
' End With

' crExportOptions.FormatOptions = HTML32Formatopts

'Case "HTML 4.0 (HTML)"
' 'Export to Html 4.0:

' Dim HTML40Formatopts As New HTMLFormatOptions()

' With crExportOptions
' .ExportDestinationType = ExportDestinationType.DiskFile
' .ExportFormatType = ExportFormatType.HTML40
' End With

' With HTML40Formatopts
' .HTMLBaseFolderName = ExportPath + "Html40Folder" ' Foldername to place HTML files
' .HTMLFileName = "HTML40.html"
' .HTMLEnableSeparatedPages = True
' .HTMLHasPageNavigator = True
' .FirstPageNumber = 1
' .LastPageNumber = 3
' End With

' crExportOptions.FormatOptions = HTML40Formatopts

End Select 'export format

'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder