使用Telerik导出到Excel(XLSX)时如何解释集合?

Ele*_*ios 15 .net c# vb.net excel telerik

情景


我正在使用Telerik UI For Windows表单.

我有一个RadGridView,我在其上代表一个名为的自定义类型MarketInfo:

Public NotInheritable Class MarketInfo

    ...
    Public ReadOnly Property Participants As ReadOnlyCollection(Of ParticipantInfo)
        Get
            Return Me.GetParticipants()
        End Get
    End Property
    ...

End Class
Run Code Online (Sandbox Code Playgroud)

它只包含text和booleans属性,以及Participants返回另一个自定义类型集合的属性:

Private Function GetParticipants(ByVal market As XElement) As ReadOnlyCollection(Of ParticipantInfo)
    Dim participantInfoList As New List(Of ParticipantInfo)
    For Each participantNode As XElement In market...<participant>
        participantInfoList.Add(New ParticipantInfo(participantNode))
    Next
    Return New ReadOnlyCollection(Of ParticipantInfo)(participantInfoList)
End Function
Run Code Online (Sandbox Code Playgroud)

这是完整的ParticipantInfo课程:

Public NotInheritable Class ParticipantInfo

    Private ReadOnly participantElement As XElement

    Public ReadOnly Property Name As String
        Get
            Return participantElement.@name
        End Get
    End Property

    Public ReadOnly Property Id As String
        Get
            Return participantElement.@id
        End Get
    End Property

    Public ReadOnly Property Odds As String
        Get
            Return participantElement.@odds
        End Get
    End Property

    Public ReadOnly Property OddsDecimal As String
        Get
            Return participantElement.@oddsDecimal
        End Get
    End Property

    Public ReadOnly Property LastUpdateDate As String
        Get
            Return participantElement.@lastUpdateDate
        End Get
    End Property

    Public ReadOnly Property LastUpdateTime As String
        Get
            Return participantElement.@lastUpdateTime
        End Get
    End Property

    Public ReadOnly Property Handicap As String
        Get
            Return participantElement.@handicap
        End Get
    End Property

    Public Sub New(ByVal participantElement As XElement)
        Me.participantElement = participantElement
    End Sub

    Private Sub New()
    End Sub

End Class
Run Code Online (Sandbox Code Playgroud)

所以基本上我需要导出一个ParticipantInfo类型的集合,它应该可以在Excel中表示.

好吧,所以在RadGridView我隐藏的列,Participants因为它不能代表它(因为它是一个集合),然后我将该集合作为数据源加载到另一个RadGridView.

为了更好地理解它,结果如下:

在此输入图像描述

问题


我的问题是我不知道如何在excel文件(XLSX)中解释这个.

这是我试图导出MarketInfo网格内容的代码:

Dim exporter As New ExportToExcelML(rdg)
With exporter
    .HiddenColumnOption = HiddenOption.ExportAlways
    .HiddenRowOption = HiddenOption.ExportAlways
    .ExportVisualSettings = True
    .SheetMaxRows = ExcelMaxRows._65536
    .SheetName = "xxxxxxxx"
    .SummariesExportOption = SummariesOption.ExportAll
    .PagingExportOption = PagingExportOption.AllPages
    .FileExtension = ".xlsx"
    .RadGridViewToExport = rdg
    .ChildViewExportMode = ChildViewExportMode.ExportAllViews

End With

exporter.RunExport(fileName)
Run Code Online (Sandbox Code Playgroud)

但是,生成的文件只包含参与者的类型名称:

...
<Data ss:Type="String">System.Collections.ObjectModel.ReadOnlyCollection`1[WilliamHillLeecher.Leecher.Types.ParticipantInfo]</Data></Cell></Row>
...
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我希望每个人都能看到一个Excel页面,其中MarketInfo包含缺少的属性.

我不熟悉Excel用法和Excel术语,我不确定一个人如何在一个页面中代表一个集合,我想通过创建一个新的工作表页面并将其"链接"到相应的单元格.

我只是想在我的应用程序中表示的Excel文件中表示相同的信息.


如何通过Telerik导出相关库来实现这一目标?

如果不可能使用Telerik库,那我怎么能用其他第三方免费库来做呢?

(有了这个,我只是说我对其他建议持开放态度,但请记住,我知道更集中的Excel库,但无论如何我仍然不明白如何做到这一点使用任何lib ...可能是由于误解了如何使用Excel UI添加/表示集合的相同任务.)

Jer*_*son 3

  1. 使用层次结构填充内存中的新 RadGridView并像其他人一样导出: http://www.telerik.com/forums/radgrid-hierarchy-export-to-excel-showing-exporting-master-table-rows-但详细信息行是空白行

  2. 您可以使用 XML 控制创建的 Excel XML 内容,与OpenXML相比, ClosedXML确实很容易使用。

  3. 还有很多其他选择

  4. 使用 Telerik 打开支持请求可能是确认GridViewExportOptions中的“每个详细信息表”页面是否有任何选项的最快方法。