0

I need to display just 10 first rows from my excel sheet, i can only display all the excel data using "@Foreach". please find the controller and the view below. this is how i extract data from excel:

string path2 = "D:/Project/SesameIncident.xlsx";

        Excel.Application application2 = new Excel.Application();
        Excel.Workbook workbook2 = application2.Workbooks.Open(path2);
        Excel.Worksheet worksheet2 = workbook2.ActiveSheet;
        Excel.Range range2 = worksheet2.UsedRange;
        List<SesameIn> ListSesame = new List<SesameIn>();
        for (int row = 2; row <= range2.Rows.Count; row++)

        {
            SesameIn Se = new SesameIn();
            Se.AssignedGroup= (((Excel.Range)range2.Cells[row, 1]).Text);
            Se.Open = (((Excel.Range)range2.Cells[row, 2]).Text);
            Se.Assigned = (((Excel.Range)range2.Cells[row, 3]).Text);
            Se.PendingCustomer = (((Excel.Range)range2.Cells[row, 4]).Text);
            Se.ClosedComplete = (((Excel.Range)range2.Cells[row, 5]).Text);
            Se.Resolved = (((Excel.Range)range2.Cells[row, 6]).Text);
            Se.Total = (((Excel.Range)range2.Cells[row, 7]).Text);



            ListSesame.Add(Se);

        }

        ViewBag.ListSesames = ListSesame;

and this is the view code :

 <div class="item">
        <h1><img src="~/Web/PendingCustomer.png" /> Sesame Pending Tickets </h1>
        <table class="table table-striped">
            <thead>
            <th>Number</th>
            <th>Assigned To</th>
            <th>Opened</th>
            <th>Priortity</th>
            <th>Assigned Group</th>


            </thead>
            <tbody>

@foreach (var In in ViewBag.ListSesameIncidents) {

    <tr>
        @if (@In.Status == "Pending Customer")
        {

            <td>@In.Number</td>
            <td>@In.AssignedTo</td>
            <td>@In.Opened</td>
            <td>@In.Priority </td>
            <td>@In.Status</td>
            <td>@In.AssignedGroup</td>

        }



    </tr>



}



            </tbody>

        </table>
        <br />

        <div class="carousel-caption">


        </div>
    </div>
Aymen Rahal
  • 53
  • 1
  • 7

2 Answers2

0

You can use linq .Take(10) to show the first 10 items.

0

I would suggest use Linq extension methods and filter the Data.

ViewBag.ListSesames = ListSesam
                        .Where(x=>x.Status == "Pending Customer")   // Look for pending customers
                        .Take(10);                                  // Take top 10   
Hari Prasad
  • 16,716
  • 4
  • 21
  • 35