我正在尝试创建一个Datatable并用给定的代码替换单元格值但是当我返回表时,不考虑替换的单元格值并返回原始表。如何保留替换的单元格值?
public static DataTable GetDataTable(IList<string> headerList, IList<IList<string>> rows)
{
var table = new DataTable();
foreach (string header in headerList)
{
table.Columns.Add(header);
}
foreach (var row in rows)
{
table.Rows.Add(row.ToArray());
foreach (DataRow r in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++)
{
string celltext = r[i].ToString();
if (celltext == "-")
{
celltext.Replace("-", "");
}
}
}
}
return table;
}