Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
470
Infragistics.Documents.Excel - wrong number of rows
posted

I have attached a very simple excel file. When I read it with WB = Workbook.Load(io) the wrong number of rows are returned. This document contains 32 rows but your component, on the Rows property, returns 28. Now, there are 5 blank rows in the document which is probably the cause for this and you could think that these blank rows have been removed in Rows but there are blank rows in it so there is no way for me to read the last 4 rows.

test.zip
Parents
No Data
Reply
  • 29045
    Offline posted

    Hello Henrik,

    Thank you for contacting Infragistics. As our documentation states, the rows in the worksheet.Rows collection are lazily created (they are only created and added to the collection when they are accessed). If this collection is enumerated, it only enumerates the rows which were already accessed.

    With that said you can still iterate through the number of rows based on the worksheet.Rows.Count and obtain all the cell values.

    string _settings = Application.StartupPath + @"\test.xls";
    Workbook wrkbook = Workbook.Load(_settings);
    Infragistics.Documents.Excel.Worksheet worksheet = wrkbook.Worksheets["serialsh03_9"];

    StringBuilder sb = new StringBuilder();
    int numRows = worksheet.Rows[((ICollection<WorksheetRow>)worksheet.Rows).Count - 1].Index + 1;
    MessageBox.Show("Rows: " + numRows.ToString());

    for (int i = 0; i < numRows + 1; i++)

    {
    sb.AppendLine(String.Format("{0} \t\t {1}",
    worksheet.Rows[i].Cells[0].GetText(),
    worksheet.Rows[i].Cells[0].GetText()));

    MessageBox
    .Show(sb.ToString());

    }

    Let me know if you have any questions regarding this matter.

Children