.net WebApi Excel导入接口

/// <summary>
/// 去除不必要的标题
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public DataTable GetExcelTable(DataTable table)
{
foreach (DataRow row in table.Rows)
{
if (!(row[0].ToString()).Equals("小区名称"))
{
row.Delete();
}
else
{
break;
}
}
table.AcceptChanges();
if (table.Rows.Count > 0)
{
for (int i = 0; i < table.Columns.Count; i++)
{
table.Columns[i].ColumnName = table.Rows[0][i].ToString();
}
table.Rows[0].Delete();
table.AcceptChanges();
}
//table = table.GetChanges(DataRowState.Unchanged);
return table;
}

 

/// <summary>
/// 去除不必要的标题
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public DataTable GetExcelTable(DataTable table)
{
foreach (DataRow row in table.Rows)
{
if (!(row[0].ToString()).Equals("小区名称"))
{
row.Delete();
}
else
{
break;
}
}
table.AcceptChanges();
if (table.Rows.Count > 0)
{
for (int i = 0; i < table.Columns.Count; i++)
{
table.Columns[i].ColumnName = table.Rows[0][i].ToString();
}
table.Rows[0].Delete();
table.AcceptChanges();
}
//table = table.GetChanges(DataRowState.Unchanged);
return table;
}

public static void ExcuteSQL(string sql)
{
using (SqlConnection conn = new SqlConnection(strConn))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}

posted on 2019-01-14 09:27  *tfe*  阅读(305)  评论(0编辑  收藏  举报

导航