Wrox Programmer Forums
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 19th, 2005, 07:53 AM
Authorized User
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dotnetprogrammer
Default Reading excel files


I am using following code to read excel files.

int NumRowsInFileOne;
Ex.Application objExcel = new Ex.Application();
Ex.Workbook workbook = objExcel.Workbooks.Open(filePath,0,true,5,"","",tr ue,Ex.XlPlatform.xlWindows,"\t",false,false,0,true ,0,0);
Ex.Sheets sheets = workbook.Worksheets;
Ex.Worksheet worksheet = (Ex.Worksheet)sheets.get_Item(1);
Ex.Range range = worksheet.get_Range("A1", Type.Missing);
range = range.get_End(Ex.XlDirection.xlToRight);
range = range.get_End(Ex.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, Ex.XlReferenceStyle.xlA1,Type.Missing, Type.Missing);
range = worksheet.get_Range("A1", downAddress);
object[,] values = (object[,])range.Value2;

NumRowsInFileOne = values.GetLength(0);

for (int i = 1; i <= values.GetLength(0); i++)
    for (int j = 1; j <= values.GetLength(1); j++)

Now the problem is that there may be empty cells ( or empty rows) in the
excel sheet. Now if in first row and first column have only one record ,
then above code will give wrong info about the number of columns
and number of rows that are there in the excel sheet.

Any clue??????????
I am really stuck in this.
I need to read all the rows and all the columns of the excel sheet. There
may be any number of columns and any number of rows in my excel

Any kind of help will be greatly appreciated.



Old June 29th, 2005, 07:01 AM
Friend of Wrox
Join Date: Sep 2004
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts

u can use oledb and directly read excel file ...

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading from Excel Files interrupt Javascript How-To 8 September 28th, 2006 09:31 AM
Reading excel and text files using VB6... CJ35 VB How-To 5 October 8th, 2004 03:56 AM
Reading from Binary Files jschmi J2EE 0 October 5th, 2004 01:09 AM
Reading/Creating/Writing Excel FIles p_nut33 C# 1 September 2nd, 2003 12:17 PM
reading files nightsurfer JSP Basics 0 August 10th, 2003 04:34 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.