Mine is C# console application. I am trying to get the count of rows which are having data of an excel sheet programmatically, using C# with the reference of EPPlus Library. I want to read all the records of an excel spreadsheet using for loop. So I need to specify the upper limit of that loop.
code i used:-
FileInfo existingFile = new FileInfo(FilePath);
using (ExcelPackage package = new ExcelPackage(existingFile))
{
// get the second worksheet in the workbook
ExcelWorksheet worksheet = package.Workbook.Worksheets[2];
// output the data in column 2
StringBuilder sb = new StringBuilder();
for (int row = 2; row < 7; row++)
{
sb.Append("<tr>");
for (int col = 2; col < 11; col++)
{
if (col == 7)
sb.Append("<td valign='top' border='1'><a href='https://na7.salesforce.com/'" + worksheet.Cells[row, col].Value + ">" + "https://na7.salesforce.com/" + worksheet.Cells[row, col].Value + "</td>");
else
sb.Append("<td valign='top' border='1'>" + worksheet.Cells[row, col].Value + "</td>");
}
sb.Append("</tr>");
}
}
Now am statically mentioning that the code must retrieve 7 rows [for (int row = 2; row < 7; row++)]. Here the 7 must be calculated dynamically (during the run-time).
Kindly popup your points here to work it out. Thanks in advance.
EPPLUS
:) – Siddharth Rout