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

Free Support Forum - aspose.com

Apply style to particular cells

Hi Team,

I would like to apply style to a row where-ever a particular word is repeating. It can repeat n number of times in a worksheet. I want to find all the occurences of that word i want to apply left alighnment and bold style to the complete row where the word is present. Could you please guide me through it ?

Best,
Ishi

@dewan.ishi,

Thanks for your query.

Well, you should build your own logic and write your own code to accomplish the task for your requirements. Your should first find your particular word/string using Find/Search options provided by Aspose.Cells APIs and then apply formatting to the row. I have written a sample code to accomplish your task a bit for your reference. Please run the following code with the template file (attached), you will see that the string “test” when it is repeated in the cells of any row, the particular row will be formatted accordingly:
e.g
Sample code:

    Workbook workbook = new Workbook(@"e:\test2\Bk_applystyles1.xlsx");
    Worksheet worksheet = workbook.Worksheets[0];

    Style style1 = workbook.CreateStyle();
    style1.Font.IsBold = true;
    style1.HorizontalAlignment = TextAlignmentType.Left;
    StyleFlag flag1 = new StyleFlag();
    flag1.FontBold = true;
    flag1.HorizontalAlignment = true;

    Aspose.Cells.Cell foundCell = null;
    Aspose.Cells.Cell prevCell = null;
    int cnt = 0;
    int row = -1;

    FindOptions findOptions = new FindOptions();
    findOptions.CaseSensitive = false;
    findOptions.LookInType = LookInType.Values;
    findOptions.SeachOrderByRows = true;


    do
    {
        foundCell = worksheet.Cells.Find("test", prevCell, findOptions);
        if (foundCell == null)
            break;

        if (foundCell.Row == row)
        {
            worksheet.Cells.ApplyRowStyle(row, style1, flag1);
            row = foundCell.Row + 2;
            prevCell = worksheet.Cells["A" + row];
            continue;

        }

        MessageBox.Show(foundCell.Name);
        //cnt++;
        prevCell = foundCell;
        row = foundCell.Row;
        

    } while (foundCell != null);


    workbook.Save("e:\\test2\\out1.xlsx"); 

Please refer to the code segment and write your own code accordingly for your custom needs.

Hope, this helps a bit.
files1.zip (5.9 KB)