【问题标题】:WinRT with Syncfusion.XlsIO - Filling a SfDataGrid with content of .xls file, not showing the last rowWinRT with Syncfusion.XlsIO - 用 .xls 文件的内容填充 SfDataGrid,不显示最后一行
【发布时间】:2014-10-14 16:39:12
【问题描述】:

我正在尝试用 XLS 文件的内容填充 SfDataGrid。到目前为止,我有这个:

using (var engine = new ExcelEngine())
{
    var excel = engine.Excel;

    using (var stream = await file.OpenStreamForReadAsync())
    {
        var workbook = await excel.Workbooks.OpenAsync(stream);
        var worksheet = workbook.Worksheets[0];

        var rows = new List<object>();
        foreach (var row in worksheet.Rows)
            rows.Add(new
            {
                A = row.Cells[0].Text,
                B = row.Cells[1].Text,
                C = row.Cells[2].Text,
                D = row.Cells[3].Text,
                E = row.Cells[4].Text,
                F = row.Cells[5].Text,
                G = row.Cells[6].Text,
                H = row.Cells[7].Text,
                I = row.Cells[8].Text,
                J = row.Cells[9].Text,
            });

        var dataGrid = new SfDataGrid
        {
            ItemsSource = rows,
            ColumnSizer = GridLengthUnitType.SizeToCells
        };

        contentGrid.SetValue(Grid.RowProperty, 1);
        //contentGrid.Margin = new Thickness(220, 0, 0, 150);
        contentGrid.Children.Add(dataGrid);
    }
}

我的 XLS 文件如下所示:

我的问题是这段代码填了前3个rows,没有填最后一个。当我在ItemsSource = rows 使用断点时,它会在rows 变量上显示。

知道可能出了什么问题吗?

【问题讨论】:

    标签: c# excel syncfusion


    【解决方案1】:

    看来我应该使用

    A = row.Cells[0].Value,
    B = row.Cells[1].Value,
    C = row.Cells[2].Value,
    D = row.Cells[3].Value,
    E = row.Cells[4].Value,
    F = row.Cells[5].Value,
    G = row.Cells[6].Value,
    H = row.Cells[7].Value,
    I = row.Cells[8].Value,
    J = row.Cells[9].Value,
    

    而不是.Text

    【讨论】:

      猜你喜欢
      • 2021-02-17
      • 1970-01-01
      • 2017-04-12
      • 2013-01-14
      • 2014-07-26
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多