# Search Data

A tutorial showing how to search for strings in SpreadJS with code

## Content

You can search for a string in the widget and specify various search options, such as case, exact matches, wildcards, cell ranges, and the order of the search. The [search](/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#search) method and the [SearchCondition](/spreadjs/api/classes/GC.Spread.Sheets.Search.SearchCondition) class allows you to check cell text, cell tags, comments, values, or formulas.
Additionally, the `SearchFoundFlags` enumeration determines the target of the search which specifies where the search should be performed. It also includes several flag options for searching within cell values, formulas, tags, or comments.

> Note-
>
> * The rules defined by `SearchFlags` and `SearchOrder` are followed while searching a condition.
> * When using the code to search in comments, the text within the comment is the target of the search.
> * In SpreadJS, both the comments text and the username are considered while searching.

The code below depicts how to search a string where the search target is cell comments. You can change the value of the search target according to the search criteria.

```javascript
var sheet = spread.getSheet(0);
sheet.getCell(2,3).value("user");

// Add a comment
var comment = new GC.Spread.Sheets.Comments.Comment();
comment.text("user comment!");
sheet.getCell(3, 3).comment(comment);

// Search the comment
var searchCondition = new GC.Spread.Sheets.Search.SearchCondition();
searchCondition.searchString = "user";
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
searchCondition.searchOrder = GC.Spread.Sheets.Search.SearchOrder.nOrder;

// searchTarget is cell comment
searchCondition.searchTarget = GC.Spread.Sheets.Search.SearchFoundFlags.cellComment;

// searchTarget is a text in cell 
// searchCondition.searchTarget = GC.Spread.Sheets.Search.SearchFoundFlags.CellText; 

searchCondition.searchFlags = GC.Spread.Sheets.Search.SearchFlags.ignoreCase | GC.Spread.Sheets.Search.SearchFlags.useWildCards;
var searchresult = spread.search(searchCondition);
var str = "[searchFoundFlag:" + searchresult.searchFoundFlag + ",\r\n foundSheetIndex:" + searchresult.foundSheetIndex + ",foundRowIndex:" +
searchresult.foundRowIndex + ", foundColumnIndex:" + searchresult.foundColumnIndex + ", foundComment:" + searchresult.foundString + "]";
console.log(str);
```

## Using Designer

The Spread Designer enables you to search a string with values, cell tags, formulas, and cell comments using the **Find and Replace** dialog box by using the following steps:

1. Click on the **Find** button in the **HOME** tab.
    The **Find and Replace** Dialog box will appear.
2. Click on the **Option<<** button in the dialog box.
3. Click on the **Look in** dropdown and choose any option depending upon the search criteria as per your requirement.

The image below displays the **Find and Replace** dialog box with various options where a search can be performed:

![find_replace_dialog](https://cdn.mescius.io/document-site-files/images/7719ad0a-f083-46d7-aff6-f63e2e187c15/find_replace_dialog.c69d81.png)