目前有c#可以讀取沒有受密碼保護的excel,但現在有密碼保護的excel要怎麼讀取阿~
這是沒有密碼保護的程式碼:
static public DataSet ExcelToDataSet(string filename)
{
DataSet ds;
string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", filename);
OleDbConnection myConn = new OleDbConnection(strConn);
string strCom = " SELECT * FROM [sheet$]";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
ds = new DataSet();
myCommand.Fill(ds);
myConn.Close();
return ds;
}