saurabh_helloaish
April 19th, 2005, 07:52 AM
Hi,
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,"","",true,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++)
{
MessageBox.Show(values[i,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
sheet.
Any kind of help will be greatly appreciated.
Regards
Saurabh
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,"","",true,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++)
{
MessageBox.Show(values[i,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
sheet.
Any kind of help will be greatly appreciated.
Regards
Saurabh