我把代码调整了下
Private Function P_Exportword() As Integer
Dim intsuc As Integer = - 2
Try
Dim strFileName As String = System.Environment.CurrentDirectory + "\report\dz_bgd.rdlx"
Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(new system.io.FileInfo(strFileName))
AddHandler report.Document.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件,进行事件加载
Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
Dim outputDirectory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\myword")
outputDirectory.Create()
Dim wordSetting As GrapeCity.ActiveReports.Export.Word.Page.Settings = New GrapeCity.ActiveReports.Export.Word.Page.Settings()
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML
Dim wordRenderingExtension As GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension = New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
outputProvider.OverwriteOutputFile = True
reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)
intsuc = 1
Catch ex As Exception
MsgBox(ex.Message, , "错误")
End Try
Return intsuc
End Function
Private Sub OnLocateDataSource(ByVal sender As Object, ByVal args As GrapeCity.ActiveReports.LocateDataSourceEventArgs)
' If args.DataSourceName = "binbin" Then
' Dim vConnection As New GrapeCity.ActiveReports.PageReportModel.ConnectionProperties
' vConnection.ConnectString = _nConnection1
' If args.DataSetName = "DataSet1" Then
' args.Data = _nMainDataSource1
' End If
' End If
if P_ReturnReportData.Tables.Count>0 then
_nDataSource1=P_ReturnReportData.Copy()
End If
If _nDataSource1.Tables.Count = 1 Then
If LCase(Convert.ToString(args.DataSetName)) = "master" Then
args.Data = _nDataSource1.Tables(0)
End If
If LCase(Convert.ToString(args.DataSetName)) = "detail" Then
args.Data = _nDataSource1.Tables(1)
End If
ElseIf _nDataSource1.Tables.Count = 2 Then
If LCase(Convert.ToString(args.DataSetName)) = "master" Then
args.Data = _nDataSource1.Tables(0)
End If
If LCase(Convert.ToString(args.DataSetName)) = "detail" Then'Detail
args.Data = _nDataSource1.Tables(1)
End If
End If
End Sub
不过导出报表,提示无法加载数据源。
我把报表的数据源改为dataset provider
最后提示,无法加载数据源。 |