Top

Tags


Roadkill .NET Wiki

Google ads

Recommended reading


Search

Monday
Oct122009

Excel exporting in C# 

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();

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Inside The System.IO Namespace Part 1 | Main | LDAP/Active directory tree in C# »