3.读取excel文件。public static string[] getexcelsheetnames(string filepath)
{
string constring = "provider=microsoft.ace.oledb.12.0;data source=" + filepath + ";extended properties="excel 12.0;hdr=yes"";
oledbconnection con = new oledbconnection(constring);
con.open();
datatable dt = con.getoledbschematable(oledbschemaguid.tables, null);
con.close();
if (dt == null)
{
return null;
}
string[] excelsheetnames = new string[dt.rows.count];
int i = 0;
foreach (datarow dr in dt.rows)
{
excelsheetnames[i++] = dr["table_name"].tostring();
}
return excelsheetnames;
}
4.将数据写入excel文件。public static datatable readexcel(string filepath, string constr)
{
string constring = "provider=microsoft.ace.oledb.12.0;data source=" + filepath + ";extended properties="excel 12.0;hdr=yes"";
oledbconnection con = new oledbconnection(constring);
oledbdataadapter oda = new oledbdataadapter(constr, con);
datatable dt = new datatable();
con.open();
oda.fill(dt);
con.close();
return dt;
}
public static void writeexcel(string filepath, datatable dt)
{
if (file.exists(filepath))
{
file.delete(filepath);
}
else
{
string constring = "provider=microsoft.ace.oledb.12.0;data source=" + filepath + ";extended properties="excel 12.0;hdr=yes"";
oledbconnection con = new oledbconnection(constring);
string createsql = "create table sheet1 (";
foreach (datacolumn dc in dt.columns)
{
createsql += dc.columnname + " varchar,";
}
createsql = createsql.substring(0, createsql.length - 1) + ")";
oledbcommand cmd = new oledbcommand(createsql, con);
con.open();
cmd.executenonquery();
foreach (datarow dr in dt.rows)
{
string insertsql = "insert into sheet1 values(";
foreach (datacolumn dc in dt.columns)
{
insertsql += "'" + dr[dc].tostring() + "',";
}
insertsql = insertsql.substring(0, insertsql.length - 1) + ")";
cmd = new oledbcommand(insertsql, con);
cmd.executenonquery();
}
con.close();
}
}
电神魔傀2街机免费版 官方版v1.2.1
下载三国战纪2手游腾讯渠道服 安卓版v2.41.0.0
下载三国战纪2手游抖音渠道服 安卓版v2.41.0.0
下载三国战纪2折扣服 安卓版v2.41.0.0
下载叫我大掌柜小米版 安卓版v7.4.4
叫我大掌柜小米版是这款模拟经营类手游的渠道服版本,在此版本中
cooking fever正版 安卓最新版v23.0.2
cooking fever正版是一款非常好玩的模拟经营类手游
咖啡厅的生活故事 最新版v1.7
咖啡厅的生活故事是一款模拟经营游戏,玩家们在游戏中可以经营一
迅猛龙模拟器金币不减反增版 v1.1.8
迅猛龙模拟器无限金币版是一款动物模拟类游戏,玩家们将在游戏中
泽塔奥特曼升华器免广告版 v1.4
泽塔奥特曼升华器去广告版是游戏的破解版本,在该版本中为玩家去