搜索并找到以下解决方案 Here 用户放弃了对它的投票,但它为我抛出了一个例外。
MultiFileExportToExcel无法将“DevExpress.XtraGrid.Views.Grid.GridView”类型的对象强制转换为“DevExpress.XtraPrinting.IPrintable”。 无法将类型为'DevExpress.XtraGrid.Views.Grid.GridView'的对象强制转换为'DevExpress.XtraPrinting.IPrintable'。
完整代码在这里:
Public Sub MultiFileExportToExcel()
Using saveDialog = New SaveFileDialog()
saveDialog.Filter = "Excel (.xlsx)|*.xlsx"
If saveDialog.ShowDialog() = DialogResult.OK Then
Dim printingSystem = New PrintingSystemBase()
Dim compositeLink = New CompositeLinkBase()
compositeLink.PrintingSystemBase = printingSystem
Dim link1 = New PrintableComponentLinkBase()
link1.Component = CType(GridView1, IPrintable)
Dim link2 = New PrintableComponentLinkBase()
link2.Component = CType(GridView2, IPrintable)
compositeLink.Links.Add(link1)
compositeLink.Links.Add(link2)
Dim options = New XlsxExportOptions()
options.ExportMode = XlsxExportMode.SingleFilePageByPage
compositeLink.CreatePageForEachLink()
compositeLink.ExportToXlsx(saveDialog.FileName, options)
End If
End Using
End Sub
提前感谢..