行转列
public System.Data.DataTable RowToCol(System.Data.DataTable dataSource)
{
var tblPivot = new System.Data.DataTable();
var firstColumnName = dataSource.Columns[0].ColumnName;
tblPivot.Columns.Add(firstColumnName);
for (int i = 1; i < dataSource.Rows.Count; i++)
{
tblPivot.Columns.Add(Convert.ToString(i));
}
for (int col = 0; col < dataSource.Columns.Count; col++)
{
var r = tblPivot.NewRow();
r[0] = dataSource.Columns[col].ToString();
for (int j = 1; j < dataSource.Rows.Count; j++)
r[j] = dataSource.Rows[j][col];
tblPivot.Rows.Add(r);
}
tblPivot.Columns.Remove(firstColumnName);
return tblPivot;
}