title: How to add colour to particular excel columns based on conditions using openxml?
body: <p>I'm generating an excel sheet and I want to color the excel columns based on conditions. Now my all excel columns get red colors. I want to color only particular column names.</p>
  
  <p>I'm using open XML for generating excel, is there any way to find the cells to apply color</p>
  
  <pre><code> using (SpreadsheetDocument document = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook))
              {
                  WorkbookPart workbookPart = document.AddWorkbookPart();
                  workbookPart.Workbook = new Workbook();
  
                  WorksheetPart worksheetPart = workbookPart.AddNewPart&lt;WorksheetPart&gt;();
                  worksheetPart.Worksheet = new Worksheet();
  
                  Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
  
                  Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Template" };
  
                  sheets.Append(sheet);
  
                  var stylesheet = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } };
                  stylesheet.AddNamespaceDeclaration("mc", "http: //schemas.openxmlformats.org/markup-compatibility/2006");
                  stylesheet.AddNamespaceDeclaration("x14ac", "http: //schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  
                  var fills = new Fills() { Count = 5U };
                  var fonts = new Fonts() { Count = 1U, KnownFonts = true };
                 // var cellFormats = new CellFormats();
                  Font font = new Font();
                  font.Append(new Color() { Rgb = "ff0000" });
                  fonts.Append(font);
  
                 // cellFormats.AppendChild(new CellFormat() { FontId = 0U });
                  stylesheet.Append(fonts);
                  stylesheet.Append(fills);
                  //stylesheet.Append(cellFormats);
                  //stylesheet.Append(fill);                 
                  var stylePart = workbookPart.AddNewPart&lt;WorkbookStylesPart&gt;();
                  stylePart.Stylesheet = stylesheet;
                  stylePart.Stylesheet.Save();
  
                  workbookPart.Workbook.Save();
  
                  SheetData sheetData = worksheetPart.Worksheet.AppendChild(new SheetData());
  
                  // Constructing header
                  Row row = new Row();
  
                  foreach (DataExchangeDefinition a in importColList)
                  {
                      defnExist = true;
                      if (a.MustFieldYN == true)
                      {
                          row.Append(
                          ConstructCell(a.FieldCaption, CellValues.String));
                      }
                      else
                      {
                          row.Append(
                          ConstructCell(a.FieldCaption, CellValues.String));
                      }
                  }
  
                  if (defnExist == false)
                  {
                      row.Append(
                      ConstructCell("Excel Template Definition Missing", CellValues.String));
                  }
                  // Insert the header row to the Sheet Data
                  sheetData.AppendChild(row);
  
                  // Inserting each employee
  
                  worksheetPart.Worksheet.Save();
              }
  </code></pre>
  
  <p>Here is construct cell method</p>
  
  <pre><code> private Cell ConstructCell(string value, CellValues dataType)
      {
          Cell c = new Cell()
          {
              CellValue = new CellValue(value),
              DataType = new EnumValue&lt;CellValues&gt;(dataType)
              //StyleIndex=0U                
          };
          return c;
      }
  </code></pre>
  
  <p>Is there any way to solve this?</p>