
就是写文件啊,循环list string str = Guid.NewGuid().ToString()string strPath = "C:\\Program Files\\" + str + ".xls"FileStream fs = File.Create(strPath)StreamWriter sw = new StreamWriter(fs, Encoding.Unicode)string strLine = ""// 写入列标题 for (int i = 0i <colNames.Lengthi++) { string[] col = colNames[i].Split('=')strLine = strLine + col[1].ToString() + Convert.ToChar(9)} sw.WriteLine(strLine)strLine = ""// 写入报表数据 for (int i = 0i <dt.Rows.Counti++) { // for (int j = 0j <colNames.Lengthj++) { string[] col = colNames[j].Split('=')strLine = strLine + dt.Rows[i][col[0]].ToString() + Convert.ToChar(9)} sw.WriteLine(strLine)strLine = ""} sw.Close()fs.Close()先声明一个
你要添加的表实体类
public class student
{
public int id{getset}
public string name{getset}
}
List<student>st=new List<student>()
foreach(var item in st)
{
Model.student st=new Model.student()
st.id=item.id
st.name=itemt.name
this.Insert(st)
}
//根据实体添加数据库
public string Insert(Model.student student)
{
.... *** 作数据库
}
评论列表(0条)