更新时间:2023-01-30 16:55:31
下面的函数将实现您想要的功能,您需要对其稍作调整(必须翻译一些变量)和一些东西可能不需要您(设置参数/重新连接),但我确定您可以根据需要进行调整.
The function below will do what you want, you''ll need to adjust it a bit tho (had to translate some variables) and some things might not be needed for you (setting params / reconnecting ) but I''m sure you''ll be able to adjust it to your needs.
Public Shared Sub PrintToPDF(ByVal Reportname As String, ByVal params As List(Of ReportParameters), Optional ByVal path As String = "")
Try
Dim rpt As New ReportDocument
If Reportnaam.EndsWith(".rpt") Then Reportnaam = Reportnaam.Replace(".rpt", "")
Dim file As String = 'path to the report file
If IO.File.Exists(file) = False Then
'report could not be found
Exit Sub
End If
rpt.Load(file)
rpt = reconnectreport(rpt)
If params IsNot Nothing AndAlso params.Count > 0 Then
For Each c As ReportParameters In params
rpt.SetParameterValue(c.ParamNaam, c.ParamValue)
Next
End If
If String.IsNullOrEmpty(path) Then
Dim ofd As New SaveFileDialog
ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
ofd.Filter = ".pdf|PDF"
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim path As String = ofd.FileName
If path.EndsWith(".pdf") = False Then path &= ".pdf"
pad = path
End If
End If
If Not String.IsNullOrEmpty(pad) Then
'exports the report to pdf
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, pad)
End If
'rpt.Dispose()
'rpt = Nothing
Catch ex As Exception
JoroLogging.AddLog(ex, GetCurrentMethod.DeclaringType.Name, GetCurrentMethod.Name)
End Try
End Sub