C#開啟已存在的Excel檔案

來源:互聯網
上載者:User
 1 Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); 2 excelApp.Visible = true; 3 //得到WorkBook對象,開啟已有的檔案 4 Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks._Open(@"e:\excel.xls"); 5 //指定要操作的Sheet 6 Microsoft.Office.Interop.Excel.Worksheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelApp.ActiveSheet; 7  8 //這裡可以加一些對於檔案的操作 9 10 excelSheet = null;11 excelBook = null; 12 excelSheet =null;   13 excelBook =null;14  //這一句是非常重要的,否則Excel對象不能從記憶體中釋15 //如果只是實現開啟檔案,等待使用者操作Excel檔案,可以去掉,讓使用者自己關閉檔案時自動釋放Excel對象記憶體16 excelBook .Quit();17 excelBook =null;

參考資料:C# Excel操作(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.