Imprimir report viewer direto para PDF

.NET

26/07/2020

Bom dia. Estou tentando usar o exemplo para gerar relatório direto para PDF conforme o artigo “Como podemos exportar relatórios do Report Viewer?”, disponível em http://www.andrealveslima.com.br/blog/index.php/2016/05/04/como-podemos-exportar-relatorios-do-report-viewer/. Mas está gerando um erro “ApplicationException: A definição do relatório 'RelatorioFuncionarios' não foi especificada”, conforme abaixo. Copiei os códigos do site. Segue abaixo o código também. O que pode estar acontecendo.

Obrigado.


em GerarPDF.frmGerarPDF.GerarPDF_Click(Object sender, EventArgs e) em C:\Projetos VST19\Testes\PDF\GerarPDF\frmGerarPDF.vb:linha 24
em System.Windows.Forms.Control.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.ButtonBase.WndProc(Message& m)
em System.Windows.Forms.Button.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
em GerarPDF.My.MyApplication.Main(String[] Args) em :linha 81

Esta exceção foi gerada originalmente nesta pilha de chamadas:
[Código Externo]

Exceção interna 1:
ApplicationException: A definição do relatório 'RelatorioFuncionarios' não foi especificada

Exceção interna 2:
NullReferenceException: Referência de objeto não definida para uma instância de um objeto.


Segue o código

Public Class frmGerarPDF

Private Report As Microsoft.Reporting.WinForms.LocalReport

Private Sub frmGerarPDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Report = New Microsoft.Reporting.WinForms.LocalReport()
'Report.ReportEmbeddedResource = "ReportViewerExport.VB.RelatorioFuncionarios.rdlc"
Report.ReportEmbeddedResource = "C:\Projetos VST19\Testes\PDF\GerarPDF\RelatorioFuncionarios.rdlc"

Dim Funcionarios As New List(Of Funcionario)
Funcionarios.Add(New Funcionario() With {.Nome = "André", .Sobrenome = "Lima", .DataNascimento = New DateTime(1984, 1, 1), .Cargo = "Programador", .DataAdmissao = New DateTime(2008, 2, 1)})
Funcionarios.Add(New Funcionario() With {.Nome = "Fulano", .Sobrenome = "de Tal", .DataNascimento = New DateTime(1973, 4, 15), .Cargo = "Gerente", .DataAdmissao = New DateTime(1998, 4, 1)})
Funcionarios.Add(New Funcionario() With {.Nome = "Beltrano", .Sobrenome = "Silva", .DataNascimento = New DateTime(1959, 2, 23), .Cargo = "Diretor", .DataAdmissao = New DateTime(1993, 1, 1)})
Funcionarios.Add(New Funcionario() With {.Nome = "João", .Sobrenome = "Souza", .DataNascimento = New DateTime(1989, 8, 14), .Cargo = "Estagiário", .DataAdmissao = New DateTime(2010, 6, 1), .DataDemissao = New DateTime(2012, 12, 31)})

Dim dataSource As New Microsoft.Reporting.WinForms.ReportDataSource("DataSetFuncionario", Funcionarios)
Report.DataSources.Add(dataSource)

Report.Refresh()

End Sub

Private Sub GerarPDF_Click(sender As Object, e As EventArgs) Handles GerarPDF.Click
ExportarRelatorio("PDF", "relatorio2.pdf")
End Sub

Private Sub GerarDOCX_Click(sender As Object, e As EventArgs) Handles GerarDOCX.Click
ExportarRelatorio("WORDOPENXML", "relatorio2.docx")
End Sub

Private Sub ExportarRelatorio(Formato As String, NomeArquivo As String)
Dim Bytes = Report.Render(Formato)
System.IO.File.WriteAllBytes(NomeArquivo, Bytes)
End Sub

Private Sub GerarReport_Click(sender As Object, e As EventArgs) Handles GerarReport.Click
Dim form As New frmRelatorio
form.ShowDialog()
End Sub
End Class
Carlos Oliveira

Carlos Oliveira

Curtidas 0

Respostas

Carlos Oliveira

Carlos Oliveira

26/07/2020

Alguém pode me ajudar?
GOSTEI 0
POSTAR