C# to Open Existing Excel Workbook
How would I open an existing Excel Workbook using C#? I have tried several guides I have seen on the internet, but none of them work succesfully for me :(
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 30, 2013, 6:50 AM EDT
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.open(v=office.11).aspx
CSharp Noob5 reputationPosted Apr 30, 2013, 7:20 AM EDT
string mySheet = @"(F:\\Workspace\\Reports\\Excel\\Dailymenu.xls)";
var excelApp = new Excel.Application();
excelApp.Visible = true;
Excel.Workbooks books = excelApp.Workbooks;
Excel.Workbook sheet = books.Open(mySheet);
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 30, 2013, 7:53 AM EDT
CSharp Noob5 reputationPosted Apr 30, 2013, 7:57 AM EDT
It shouldn't be a permission issue...it is a file saved locally on my desktop. I am running Win 7 and Excel 2007.
umer ali40 reputationPosted Nov 26, 2014, 9:12 PM EST
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices;
//add these assembly refrences ;
try
{
excel.Application ex = new excel.Application();
ex.DisplayAlerts = true;
ex.ShowStartupDialog = true;
ex.Visible = true;
excel.Workbook newwork = ex.Workbooks.Add();// create a new excel file OR
string workbookPath = "Path.xls";
excel.Workbook excelWorkbook = ex.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
excel.Sheets excelSheets = excelWorkbook.Worksheets;
excel.Worksheet excelWorksheet = (excel.Worksheet)excelSheets.get_Item("Sheet1");
excel.Range excelCell = (excel.Range)excelWorksheet.get_Range("A1", "A10");
}
catch{}
you can open an existing exelfile or you can add new excel workbook;
please reply if this was helpful