[英]Excel and Macro using C#
抱歉,這是一個愚蠢的問題,但我沒有在Google上找到任何幫助。
我正在尋找幫助
請幫我解決回...
可從此處https://msdn.microsoft.com/zh-cn/library/office/bb448854.aspx獲得Microsoft Open XML API。 這個.net庫允許您在C#中打開任何基於OpenXML的Office文檔,進行編輯並保存。
您甚至不需要安裝Excel副本即可使用它。
我找到了解決方案...
using Excel = Microsoft.Office.Interop.Excel;
添加using Excel = Microsoft.Office.Interop.Excel;
到您的代碼,然后單擊“添加引用”,在COM下,您會找到“ Microsoft Excel 16.0 Object Library”。我正在使用Office 2016,因此根據Office版本的不同可能會有所不同。
這里是打開excel的代碼。
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
Excel.Workbook xlWorkBooks;
xlWorkBooks = xlApp.Workbooks.Open(@"F:\Book1.xlsm", true , false);//This is added to avoid the opening in ReadOnly mode
xlApp.Run("'" + @"F:\Book1.xlsm"+ "'!" + "Macro1");//The middle part is excel location and the last part is macro name in that excel file
希望你們能得到幫助...謝謝投票...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.