Search string format ("*-*")

As per the 3.3.0.1 patch and with the follwoing code i can able to search for a hardcoded string.

1) Can i able to search for a format of string like Excel provides us?
Dim currentCell as Cell = cells.FindString("-", previousCell, area)

2) Can i able to pass range as a parameter instead of cellarea in the findstring()
Dim currentCell as Cell = cells.FindString("-", previousCell, range)

This is a kind of important feature in out migration…pls help!!!


Code already received for reference
-------------------------------------

’ Search string in range from B2 to F11
Dim cells as Cells = ExcelObj.Worksheets(0).Cells
Dim area as CellArea
area.StartRow = 1
area.EndRow = 10
area.StartColumn = 1
area.EndColumn = 5

Dim previousCell as Cell = null
Dim currentCell as Cell = cells.FindString(“apples”, previousCell, area)

While Not currentCell Is Nothing
previousCell = currentCell
With currentCell.Style.Font
.Color = Color.Red
.IsBold = True
End With
currentCell = cells.FindString(“apples”, previousCell, area)
End While

-Thanks
Balaji RJ

  1. I don’t understand your need clearly. Could you please give me an example to show it?

    2. I can provide a new property to allow you to get CellArea from Range.

Lets say, i want to search for a particular string which has “-” in that from a particular range of cells.

Ex strings : “08P13-S9A-100”
“08P20-S9A-120"

MS Excel provides option to search thru all the values with has “-” in it using

sheetRange = Excel.Range.Find(-" , , Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, searchDirection, False, , )

- -> Search format.

Please let me know the equalant with Aspose.

-Balaji RJ

Currently you can use FindStringContains method to search such a string in a worksheet. I will provide a new method to enable you search it in a range.

@rjbalaji79,
Aspose.Cells has replaced Aspose.Excel that is no more continued and discarded now. You can search data in cells with a variety of options like searching in values, formulas, comments etc containing, starting or ending with a particular string. Here is an example that demonstrates this feature where particular string is searched in a range of cells.

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].Value = "A1 Data";
worksheet.Cells["A2"].Value = "-A2 Data";
worksheet.Cells["A3"].Value = "HEP-001";
worksheet.Cells["A4"].Value = "A4 Data-";
worksheet.Cells["A5"].Value = "GEIO-98";
worksheet.Cells["A6"].Value = "A6 Data";


FindOptions options = new FindOptions();
options.LookInType = LookInType.;
options.LookAtType = LookAtType.Contains;

//Find value in first column
options.SetRange(GetCellAreaForColumn(worksheet.Cells, 0));
Cell found = null;
do
{
    found = worksheet.Cells.Find("-", found, options);
    if (found != null)
        Console.WriteLine(found.Value);
} while (found != null);
private static CellArea GetCellAreaForColumn(Cells cells, short ColumnNo)
{
    return new CellArea() { StartColumn = ColumnNo, EndColumn = ColumnNo, StartRow = 0, EndRow = cells.EndCellInColumn(ColumnNo).Row };
}

Here is the program output:

-A2 Data
HEP-001
A4 Data-
GEIO-98

For more details, refer to the following article:
Find or Search Data

Get a free trial version here to test this product:
Aspose.Cells for .NET (Latest Version)

A comprehensive project is available here which contains hundreds of ready-to-run examples for testing different features of this product.