C# 如何读取资源文件中的Excel文件?
大师兄你好 2017-03-29 11:18:48 目标:读取资源文件添加的execl文件各个sheet中的数据。
注意:不是固定路径下的excel文件。
是否可以使用oledb的方式?Resourse中的excel路径怎么定?
如果使用其他方式如何操作呢?
再次先谢谢各位了~~
下面这段代码会提示找不到Sheet1$:
static ResourceManager rm =
new ResourceManager("Resources.computers.xls", Assembly.GetExecutingAssembly());
Setting mset = Setting.Instance;
public static DataTable ReadXLS(string xlsDir)
{
DataSet ds;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + xlsDir;
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$]";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
ds = new DataSet();
myCommand.Fill(ds);
myConn.Close();
return ds.Tables[0];
}
//DataTable dt=ComputerDLL.Computer_DLL.ReadXLS(Application.StartupPath + "\\File\\computers.xls");
DataTable dt2 = ReadXLS(Application.StartupPath + "\\"+rm.BaseName);