How to open excel workbook file with C#

2 Answers

0 votes
/*
Create: Visual C# - Console Application Project
Right click on: References 
Select: Add references...
Select: com
Select: Microsoft Office 12.0/15.0/16.0 Object Library
In References list you will see: Microsoft.Office.Interop.Excel
*/

using System;
using Excel = Microsoft.Office.Interop.Excel;

namespace WorkWithExcel
{
	class ExcelClass
	{
		static void Main(string[] args)
		{
			Excel.Application excelApp = new Excel.Application();  
			excelApp.Visible = true;  
			
			string WorkbookFilePath = "e:/test.xlsx";  

            Excel.Workbook excelWorkbook = null;

            try
            {
                   excelWorkbook = excelApp.Workbooks.Open(WorkbookFilePath, 0,
                                      false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", 
                                      true, false, 0, true, false, false);
            }
            catch
            {
                Console.WriteLine("Error open: " + WorkbookFilePath);
            }
		}
	}
}

 



answered Nov 27, 2015 by avibootz
0 votes
using System;
using Excel = Microsoft.Office.Interop.Excel;

namespace WorkWithExcel
{
	class ExcelClass
	{
		static void Main(string[] args)
		{
			Excel.Application excelApp = new Excel.Application();  
			excelApp.Visible = true;  
			
			string WorkbookFilePath = "e:/test.xlsx";

            Excel.Workbook excelWorkbook = null;

            try
            {
                 excelWorkbook = excelApp.Workbooks.Open(WorkbookFilePath);
            }
            catch
            {
                Console.WriteLine("Error open: " + WorkbookFilePath);
            }
		}
	}
}

 



answered Nov 27, 2015 by avibootz

Related questions

1 answer 270 views
1 answer 233 views
2 answers 510 views
2 answers 313 views
1 answer 196 views
1 answer 212 views
212 views asked Aug 10, 2018 by avibootz
1 answer 183 views
...