hi there,
i have a excel file which have purchase order information. the file contains of the information of the user and the the items that he ordered with the order item quantity and the price but there may be any amount of items in the excel sheet. the thing is how can i get all the items details from the excel sheet while there is no item details. something like a for loop(how can i get the nuber of rows in the excel sheet for the order items)
the code i need to edit is below:
Microsoft.Office.Interop.Excel.ApplicationClass tt = new Microsoft.Office.Interop.Excel.ApplicationClass();
tt.Workbooks.Open("C:\\Documents and Settings\\awaduge\\Desktop\\Purchase _Order1.xls",
0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
String name = tt.get_Range("b8", "b8").Text.ToString();
String OrderDate = tt.get_Range("h8", "h8").Text.ToString();
txtName.Text = name;
txtDate.Text = OrderDate;
[B] for (int r = 0; r < 5; r++)
{[/B]
int quantity = Convert.ToInt32(tt.get_Range("g12", "g12").Text);
double pricePerUnit = Convert.ToDouble(tt.get_Range("h12", "h12").Text);
dgvOrderDetails.Rows[r].Cells[0].Value = tt.get_Range("a12", "a12").Text.ToString();
dgvOrderDetails.Rows[r].Cells[1].Value = tt.get_Range("b12", "b12").Text.ToString();
dgvOrderDetails.Rows[r].Cells[2].Value = tt.get_Range("g12", "g12").Text.ToString();
dgvOrderDetails.Rows[r].Cells[3].Value = tt.get_Range("h12", "h12").Text.ToString();
dgvOrderDetails.Rows[r].Cells[4].Value = (quantity * pricePerUnit).ToString();
[B] }
[/B]
tt.Workbooks.Close();
i have attached the sample excel file
it is in txt format delete the txt format and use the excel file
thanxxxxxxx