Git Product home page Git Product logo

Comments (2)

jeanluc162 avatar jeanluc162 commented on May 25, 2024 2

Thank you very much, it works now.

from npoi.

Bykiev avatar Bykiev commented on May 25, 2024

Hi, the correct way is to create a new XSSFRichTextString, apply the font and then set it as a cell value. Here is a modified sample:

var redBoldFont = workbook.CreateFont();
redBoldFont.Color = HSSFColor.Red.Index;
redBoldFont.IsBold = true;

for(int i = Convert.ToInt32(numericUpDownSkipRows.Value); i <= workSheet.LastRowNum; i++)
{
    var row = workSheet.GetRow(i);
    if (row == null)
        continue;

    var cellHighlight = row.GetCell(indexHighlight);
    var cellSearch = row.GetCell(indexSearch);

    if (cellHighlight == null || cellSearch == null)
        continue;

    var richTextString = new XSSFRichTextString(cellHighlight.StringCellValue);

    var toSearch = cellSearch.StringCellValue;
    if (String.IsNullOrWhiteSpace(toSearch))
        continue;
    Int32 start = 0;
    while ((start = cellHighlight.StringCellValue.IndexOf(toSearch, start, StringComparison.InvariantCultureIgnoreCase)) != -1)
    {
        var end = start + toSearch.Length;
        richTextString.ApplyFont(start, end, redBoldFont)
        cellHighlight.SetCellValue(richTextString);
        start = end;
    }
}

Doc reference: https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFRichTextString.html

from npoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.