We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cells.Find doesn't work with Regex

Hi,

I am unable to get Aspose.Cells to find cells that match a regex. This example code (in VB) is intended to find all cells within the first 21 rows having a value that is an alphanumeric string wrapped in square brackets, that might also contain an underscore. Examples: [hello], [list3], [another_example]. However, no cells are ever returned by the Find method. If a literal value is entered for the search key eg. "[hello]", the matching cells are found. The problem is easily reproduced by using a new workbook with the value "[hello]" in the first cell. The following code will not find that cell.

Dim wb As New Workbook(strPath)
Dim ws As Worksheet = wb.Worksheets(0)
Dim cArea As CellArea
Dim optFind As FindOptions
Dim oCell As Cell

cArea.StartColumn = 0
cArea.StartRow = 0
cArea.EndColumn = ws.Cells.MaxDataColumn
cArea.EndRow = 20

optFind = New FindOptions

optFind.CaseSensitive = False
optFind.SetRange(cArea)
optFind.SeachOrderByRows = True
optFind.RegexKey = True
optFind.SearchNext = True

oCell = ws.Cells.Find("\[[a-zA-Z0-9_]+]", Nothing, optFind)

I must be doing something wrong, as no-one else seems to have reported this problem. I hope you can help.

Many thanks, Glynn

Hi Glynn,

Thanks for your posting and using Aspose.Cells.

We have tested this issue with the following code using the sample Excel file attached with this post with a latest version: Aspose.Cells for .NET (Latest Version) and found Aspose.Cells is not searching cells with regular expression.

The regular expression you provided works fine with .NET RegEx API however.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-43041=.

C#

string filePath = @“F:\Shak-Data-RW\Downloads\sample.xlsx”;

string testStr = “[hello], [list3], [another_example]. However”;


string regEx = “\[[a-zA-Z0-9_]+]”;


Regex reg = new Regex(regEx);

MatchCollection v = reg.Matches(testStr);


//regEx works fine and finds 3 matches

foreach(Match m in v)

{

Debug.WriteLine(m.ToString());

}



Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


FindOptions options = new FindOptions();

options.RegexKey = true;

options.LookInType = LookInType.Values;

options.LookAtType = LookAtType.Contains;


//Cells.Find method does not find any cell with regEx

Cell found = null;


do

{

found = worksheet.Cells.Find(regEx, found, options);


} while (found != null);

Debug Output:
[hello]
[list3]
[another_example]

Hi,

Please try our latest fix/version: Aspose.Cells for .NET v8.2.1.3 (attached).

We have fixed your issue now.

Let us know your feedback.

Thank you.

That’s fixed the problem, thanks Amjad. Will the same fix be applied to the .NET 3.5 version of the component too?

Hi,


Thanks for your feedback.

Good to know that if fixes your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

For your information, the fix would work fine any normal .NET framework version >=2 (i.e, 2.0, 3.0, 3.5, 4.x etc), so you may use it for your .NET framework 3.5 version without any problem.

Thank you.

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


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.