Showing posts with label Excell. Show all posts
Showing posts with label Excell. Show all posts
Reading Excel files from .NET/C#
First you must declare using namespace
using Microsoft.Office.Interop.Excel;
Microsoft has changed the design of Office Primary Interop Assemblies in Office 2003. So if you want to read Excel files from a system with Office 2002 or before, you must use:
Excel.Application excel = new Excel.Application();
Excel.Workbook theWorkbook = excel.Workbooks.Open(
FileName,,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
in Office 2003, Excel is just a namespace and everything has a Class postfix:
ApplicationClass excel=new ApplicationClass();
Workbook theWorkbook = excel.Workbooks.Open(
FileName,,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
After you open the workbook, you can use the following codes to get data into your memory:
ws=(Worksheet)wb.Sheets[1];
r=ws.get_Range("B3","K100");
values=(object[,])r.Value2;
v=values[8,1].ToString();
Source : http://blog.jumbosoft.com/alvincho/PermaLink,guid,77f86a28-206f-4474-b12b-1fcc6160a286.aspx
Subscribe to:
Posts (Atom)