We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Comparable functions/process for IRange to interop Range?

Trying to refactor a com interop console app to use Syncfusion XlsIO. The application is doing a cell-by-cell comparison of values in two different worksheets. The former process was to get the usedRange.Value2 as an object[,] for each sheet, then loop through the arrays.  For XlsIO, though, the Value2, Value, and Text properties on the used range are all null. Is this by design? Is there another means to create a 2D container (so easy to log location of non-matching data) with the values from cells in a worksheet?



1 Reply

SR Sridhar Syncfusion Team September 6, 2013 12:16 PM UTC

Hi Eric Strehl,

Thank you for using Syncfusion products.

We do not have any custom method to export the Excel sheet data to an 2D array. So we have created an workaround to loop through the rows and column of an sheet data and export into an 2D array.

Please make use of the below code for the same.

Code Snippet [C#]:

IWorksheet worksheet = workbook.Worksheets[0];
IRange range = worksheet.UsedRange;

int lastRow = range.LastRow;
int lastColumn = range.LastColumn;

// Instantiate a new two-dimensional string array.
string[,] dataArray = new string[lastRow, lastColumn];

for (int i = 1; i <= lastRow; i++)
  for (int j = 1; j <= lastColumn; j++)
    //Exporting the data to an 2D array     
     dataArray[i - 1, j - 1] = worksheet.Range[i, j].DisplayText;

Please try the above code snippet and let us know if these helps you.

As mentioned in your last post, if you are still facing an issue with Value,Value2 and Text properties are null for the used range is null then could you please get back to us with the simple sample (The excel file and the source code used to read excel cells) which reproduces this issue so that we are able to proceed further on this..

Please let us know if need any further assistance.


Live Chat Icon For mobile
Up arrow icon