Foros del Web » Programación para mayores de 30 ;) » .NET »

Exportar desde Crystal Reports .NET a PDF

Estas en el tema de Exportar desde Crystal Reports .NET a PDF en el foro de .NET en Foros del Web. Tengo un problema, necesito exportar un informe a PDF, aunque en el sitio de Crystal Decisions encontré el siguiente código, necesito que el usuario sea ...
  #1 (permalink)  
Antiguo 17/09/2003, 11:09
 
Fecha de Ingreso: marzo-2003
Ubicación: -
Mensajes: 8
Antigüedad: 21 años, 2 meses
Puntos: 0
Información Exportar desde Crystal Reports .NET a PDF

Tengo un problema, necesito exportar un informe a PDF, aunque en el sitio de Crystal Decisions encontré el siguiente código, necesito que el usuario sea el que decida que nombre ponerle al archivo y dónde guardarlo en su computador, tiene alguien alguna sugerencia?

Código:

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.
Dim ExportPath As String
ExportPath = Request.PhysicalApplicationPath + "Exported\"
If Directory.Exists(ExportPath) = False Then
Directory.CreateDirectory(Request.PhysicalApplicat ionPath + "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 crReportDocument.ExportOptions.DestinationOptions
.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)"
'Export to 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 crReportDocument.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


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Clicking on the "Export Report" button will run the ExportReport subroutine and export the report based on the
'selected format from the dropdownlist.
ExportReport()
End Sub
  #2 (permalink)  
Antiguo 12/04/2004, 13:21
 
Fecha de Ingreso: abril-2004
Mensajes: 16
Antigüedad: 20 años, 1 mes
Puntos: 0
Podrias utilizar un FileDialog para preguntar al usuario sobre la ruta en donde se va a guardar el archivo a exportar y asignar la ruta y nombre elegidos por el usuario como se muestra en la siguiente linea

crDiskFileDestinationOptions.DiskFileName = FileDialog.FileName

Nota: Debes Agregar el componente de Microsoft CommonDialogs a tu proyecto e incrustar este en el formulario en donde estas exportando y para mostrar el cuadro de dialogo guardar como tecleas la siguiente linea

FileDialog.ShowSave
  #3 (permalink)  
Antiguo 12/04/2004, 13:36
 
Fecha de Ingreso: abril-2004
Mensajes: 43
Antigüedad: 20 años, 1 mes
Puntos: 0
esto es lo que uso pero en c#

CrystalDecisions.CrystalReports.Engine.ReportDocum ent Reporte = new CrystalDecisions.CrystalReports.Engine.ReportDocum ent();



cuando el reporte esta listo:
Reporte.Export();


Esta debe ser la opcion que te hace falta
Response.Redirect("Temporal/" + Session.SessionID.ToString() + ".pdf");
System.IO.File.Delete(NombreArchivo);
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:20.