Free Support Forum - aspose.com

Find Underlying Value of Cell

I’m trying to find a cell by its actual value and not by its display value.

For example,

I have a row of cells that have an underlying value of 0 but its displayed value is a hyphen (-).

Running the following code returns a value of null when it should return an actual cell.

var workbook = new Workbook();
workbook.Open(“test.xls”);
var worksheet = workbook.Worksheets[0];
var area = new CellArea {StartRow = 8, StartColumn = 2, EndRow = 17, EndColumn = 13};
var cell = worksheet.Cells.FindStringContains(“0”, null, false, area);
Console.WriteLine(cell == null);

How can i actually find by a cells underlying value within a given Cell Area?

I have attached an Excel workbook the above code runs against.

Harry

Hi Harry,

Thank you for considering Aspose.

Please use Cells.FindNumber method as per your requirement. Please see the following updated code in this regard:

var workbook = new Workbook();

workbook.Open("test.xls");

var worksheet = workbook.Worksheets[0];

var cell = worksheet.Cells.FindNumber(0, null);

Console.WriteLine(cell == null);

Thank You & Best Regards,

Thanks for the quick response. The problem is that I could be searching for any type of value. It won’t be known at runtime the type of data searched for. It could be a string, an integer, a decimal. Also, the FindNumber doesn’t have the option to specify a CellArea which is a requirement.

Isn’t there something similar to the Excel VBA Find method where it takes a variant data type and searches the underlying value of a cell within a given range?

Hi,

Thank you for considering Aspose.

We will provide a new method as per your requirement soon. Your requirement has been registered into our issue tracking system with issue id CELLSNET-12550.

Thank You & Best Regards,

Thanks, that would be great.

Just to confirm, what is this new method exactly going to do?

Hi,

Thank you for considering Aspose.

Please try the attached latest fix with following sample code:

Cells cells = wb.Worksheets[0].Cells;

FindOptions findOptions = new FindOptions();

CellArea ca = new CellArea();

ca.StartRow = 8;

ca.StartColumn = 2;

ca.EndRow = 17;

ca.EndColumn = 13;

findOptions.SetRange(ca);

Cell cell = cells.Find(0, null, findOptions);

findOptions.SearchNext = true;

findOptions.SeachOrderByRows = true;

//findOptions.LookInType = LookInType.Values;

// findOptions.LookAtType = LookAtType.EndWith;

Cell cell = cells.Find(0, null, findOptions);

Thank You & Best Regards,

The fix works.

Thank you very much.

The quick response is appreciated.

Harry


The issues you have found earlier (filed as 12550) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.