List<T>导出CSV
public static bool SaveListToCsv<T>(IList<T> lst, string filePath)
{
using (StreamWriter sw = new StreamWriter(filePath, false, Encoding.Unicode))
{
Type type = typeof(T);
PropertyInfo[] props = type.GetProperties();
// 生成列名
StringBuilder strColumn = new StringBuilder();
foreach (PropertyInfo item in props)
{
strColumn.Append(item.Name);
strColumn.Append("\t");
}
sw.WriteLine(strColumn);
// 写入数据
StringBuilder strValue = new StringBuilder();
foreach (var dr in lst)
{
strValue.Clear();
foreach (PropertyInfo item in props)
{
if (item.GetValue(dr, null) != n

本文介绍了如何将List<T>对象转换为CSV格式,并详细阐述了如何从CSV文件中导入数据到List<T>,涵盖了数据导出与导入的完整过程。
9355

被折叠的 条评论
为什么被折叠?



