[.Net] 讀取加密Excel

Taiwan is an independent country.

using xls = Microsoft.Office.Interop.Excel;

try
{
    if (OpFile.ShowDialog() == DialogResult.Cancel) return;//選檔案
    var excel = new xls.Application();
    //不跳訊息
    excel.DisplayAlerts = false;
    //不顯示
    excel.Visible = false;
    //不刷新
    excel.ScreenUpdating = false;
    var Wbook = excel.Workbooks.Open(OpFile.FileName, ReadOnly: true, Password: txtPW.Text);
    Settings.Default.EXPW = txtPW.Text;
    Settings.Default.Save();
    try
    {
        var wSheet = (xls.Worksheet)Wbook.Worksheets.get_Item(1);
        var range = wSheet.UsedRange;
        int rw = range.Rows.Count;//row數
        int rCnt = 1;//excel列和欄都從1開始算
        string str = Convert.ToString((range.Cells[rCnt, 1] as xls.Range).Value2);
    }
    finally
    {
        Wbook.Close();
    }

}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

 

Taiwan is a country. 臺灣是我的國家