Chris's coding blog

Export to Excel in C#

October 12, 2009

This is a very simple snippet showing how to use the Microsoft.Office.Interop.Excel assembly (version 12 for this example).

var app = new ApplicationClass();
var book = app.Workbooks.Open(@"C:\test.xlsx", false, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
var sheet = (Worksheet) book.Worksheets[1];
var range = sheet.get_Range("D7", "D127");
var cell = (Range) range.Cells[1, 1]; // all indexes are 1 based. This gets the first row, column
string val = cell.Value2.ToString();
view raw gistfile1.cs hosted with ❤ by GitHub

csharp

I'm Chris Small, a software engineer working in London. This is my tech blog. Find out more about me via GithubStackoverflowResume