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>
8
  • Try this... ViewBag.ListTsesames = ListTSesame.Take(5); Commented Jul 5, 2016 at 3:48
  • as u see in the view i have to test if the status its "Pending Customer" or not, so in the excel sheet u will find rows with different status. Commented Jul 5, 2016 at 5:02
  • i tried with ViewBag.ListTsesames = ListTSesame.Take(10); it display the first 10 rows with the Status different to "Pending Customer" Commented Jul 5, 2016 at 5:14
  • 1
    Then do this, ViewBag.ListSesames = ListSesam.Where(x=>x.Status == "Pending Customer").Take(10); Commented Jul 5, 2016 at 5:22
  • 1
    The Office interop libraries are not supported from in IIS, it is highly reccomended you switch to the Open XML SDK to read excel files on a server. Commented Jul 5, 2016 at 5:23

2 Answers 2

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   
Sign up to request clarification or add additional context in comments.

7 Comments

how can i close the question ?
Post new question with the new title saying I want to execute logic for every 5 minutes.
i tried to create another question but i can't "It looks like you might need a break - take a breather and come back soon! "
Ohh looks like you don't have enough reputations to post one more question. You have to wait for 2 days it seems.
but u can help me if u want Haris da
|
0

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

1 Comment

as u see in the view i want only to select the rows where the status its "Pending Customer "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.