Q:

Search of an input string in spreadsheet

I am using the Open XML SDK to open an Excel file (xlsx) and I want to find a specific string or integer passed from outside to check for duplicates of the value in the spreadsheet. 
How can I search for the input string in all the cells of spreadsheet? 

A:

Here:
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
using System. IO;
using DocumentFormat. OpenXml;
using DocumentFormat. OpenXml. Packaging;
using DocumentFormat. OpenXml. Spreadsheet;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SpreadsheetDocument document = SpreadsheetDocument. Open(@"C:\Users\user\Desktop\Book1.xlsx", true))
            {
                Sheet sheet = document. WorkbookPart. Workbook. Descendants<Sheet>().First<Sheet>();
                Worksheet worksheet = ((WorksheetPart)document. WorkbookPart. GetPartById(sheet. Id)).Worksheet;
                IEnumerable<Row> allRows = worksheet. GetFirstChild<SheetData>().Descendants<Row>();
                foreach (Row currentRow in allRows)
                {
                    IEnumerable<Cell> allCells = currentRow. Descendants<Cell>();
                    foreach (Cell currentCell in allCells)
                    {
                        CellValue currentCellValue = currentCell. GetFirstChild<CellValue>();
                        string data = null;
                        if (currentCell. DataType ! = null)
                        {
                            if (currentCell. DataType == CellValues. SharedString) // cell has a cell value that is a string, thus, stored else where
                            {
                                data = document. WorkbookPart. GetPartsOfType<SharedStringTablePart>().FirstOrDefault().SharedStringTable. ElementAt(int. Parse(currentCellValue. Text)).InnerText;
                            }
                        }
                        else
                        {
                            data = currentCellValue. Text;
                        }
                        Console. WriteLine(data);

                        /* 
                            your code here

                                if(data.contains("myText"))
                                    doSomething();

                        */

                    }
                }
            }           
        }
    }
}

