0

我正在从头开始创建一个 Google DataTable Net Wrapper DataTable。但我不知道如何向数据表添加行。我已经进展到如下代码

Google.DataTable.Net.Wrapper.DataTable GDt = new Google.DataTable.Net.Wrapper.DataTable();
for (int i = 0; i < dtReports.Columns.Count; i++)
{
    Google.DataTable.Net.Wrapper.Column gc = new Google.DataTable.Net.Wrapper.Column();
    gc.Id = dtReports.Columns[i].Caption.Substring(0, dtReports.Columns[i].Caption.IndexOf("~"));
    gc.Label = dtReports.Columns[i].Caption.Substring(dtReports.Columns[i].Caption.IndexOf("~"), dtReports.Columns[i].Caption.Length);
    GDt.AddColumn(gc);

    for (int j = 0; j < dtReports.Rows.Count; j++)
    {
        Google.DataTable.Net.Wrapper.Row gr = GDt.NewRow();

        // Code to add datatable current column and row value to Google Row
    }
}

无法找到将值添加到行和特定列的代码。帮助表示赞赏。

4

1 回答 1

1

这是一种适合您现有代码的方法:

for (int j = 0; j < dtReports.Rows.Count; j++)
{
    // Code to add datatable current column and row value to Google Row
    Google.DataTable.Net.Wrapper.Row gr = i == 0 ? GDt.NewRow() : GDt.Rows.ElementAt(j);
    gr.AddCell(new Cell(dtReports.Rows[j][i]));
    if (i == 0) GDt.AddRow(gr);
}
于 2018-09-25T15:28:05.347 回答