Hi,
How to retrieve data of a particular cell from excel sheet
Thanks
Abhigna
How to read data of a cell in excel
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to read data of a cell in excel
Hi,
have a look at following blog entry which will guide you thru Excel Test Automation with Ranorex:
Excel Test Automation Plug-In for Ranorex
Kind regards,
Tobias
Support Team
have a look at following blog entry which will guide you thru Excel Test Automation with Ranorex:
Excel Test Automation Plug-In for Ranorex
Kind regards,
Tobias
Support Team
-
- Posts: 49
- Joined: Thu Feb 03, 2011 3:15 pm
Re: How to read data of a cell in excel
Hi,
I am using below code
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("C:/TestData.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
here str gives complete data of one rows with column values seperated by commas
how can I get a value of single cell.
Thanks
Abhigna
I am using below code
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("C:/TestData.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
here str gives complete data of one rows with column values seperated by commas
how can I get a value of single cell.
Thanks
Abhigna
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to read data of a cell in excel
Hi,
with altering the code above you get the value of cell(5,5):
Tobias
Support Team
with altering the code above you get the value of cell(5,5):
... rCnt = 5; cCnt = 5; str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; ...instead of
... for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++) { for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++) { str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } } ...Regards,
Tobias
Support Team
-
- Posts: 49
- Joined: Thu Feb 03, 2011 3:15 pm
Re: How to read data of a cell in excel
Thanks.
I solved the issue You can clos the ticket
I solved the issue You can clos the ticket