Took an example from the website and trying to create a loop that would tag certain cells based on their cell content which would be identified through the FindText Method from the Gembox component
My goal is:
- find cell with a partial match of the keyword
- going to the last column of that row
- changing the color of that row to a specific color
- keep going down document repeating previous commands
- stopping once the document has ended
The search works in a sense of finding the query then doing what I instructed it to do, but it stops after the 1st search result.
Is there a way to loop the search using this method or can I use it and another method to test a cell to see if it has a partial piece of what I'm searching for?
This is the link that I'm basing my knowledge on:
https://www.gemboxsoftware.com/spreadsheet/examples/excel-search/109
Thanks again guys.
Below is me working out how the system works on a 1 query basis I'd like to do this for the whole document
using System;
using System.Drawing;
using System.Text;
using System.IO;
using GemBox.Spreadsheet;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace autoexcel2
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//IF USING PRO PUT YOUR SERIAL BELOW
SpreadsheetInfo.SetLicense("FREE-lIMITED-KEY");
ExcelFile ef = ExcelFile.Load("sample.xlsx");
string searchText = "pharma";
var ws = ef.Worksheets[0];
StringBuilder sb = new StringBuilder();
int row;
int col;
ws.Cells.FindText(searchText, false, false, out row, out col);;
if (row == -1 || col == -1)
{
sb.AppendLine("cant find nada");
Console.WriteLine(sb.ToString());
}
else
{
ws.Cells[row,5].Style.FillPattern.SetSolid(Color.Aqua);
}
ef.Save("done.xlsx");
}
}
}