C# 如何读取资源文件里面的Excel文件
C# 如何读取资源文件里面的Excel文件呢?图片就很好读取,但是Excel文件不知如何操作,因为Excel文件不能让用户看见里面的内容(如果加密的话又不能通过程序连接),所以想到把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);