C#导入Excel的操作,最近一批文件 后缀都是XLS,并不是xls,每次导入 报错不是预期格式,请问怎么解决
publicDataSetExcelToDS(stringPath,stringSheetName){stringstrConn="Provider=Microsoft....
public DataSet ExcelToDS(string Path,string SheetName)
{
string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + Path + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter("Select * from ["+SheetName+"]", conn);
DataSet ds = new DataSet();
adp.Fill(ds);--------------------------这里报错
return ds;
} 展开
{
string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + Path + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter("Select * from ["+SheetName+"]", conn);
DataSet ds = new DataSet();
adp.Fill(ds);--------------------------这里报错
return ds;
} 展开
2个回答
展开全部
把SheetName两边的[]去掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询