InitializingExcelMLStyles

This event will be only raised when exporting with ExportFormat.ExcelML

You can define a Style when InitializingExcelMLStyles event is raised. For example:

Example 1: Define a style:

ExcelMLStyle style = new ExcelMLStyle("0"); 
style.Alignment.Horizontal = ExcelMLHorizontalAlignment.Automatic; 
e.Styles.Add(style); 
You can find a list of the properties that could be set for ExcelMLStyle:

Alignment:

  • Horizontal - you can choose a specific alignment through ExcelMLHorizontalAlignment enumeration.
  • Vertical - you can choose a specific alignment through ExcelMLVerticalAlignment enumeration.
  • Indent
  • Rotate
  • ShrinkToFit
  • VerticalText
  • WrapText

Font:

  • Bold
  • Color
  • FontName
  • Italic
  • Outline (only for Mac)
  • Size
  • StrikeThrough
  • Underline - you can choose a specific underline through ExcelMLUnderline

Interior:

  • Color - You must also set Pattern in order to be applied Interior.Color
  • Pattern - you can choose a specific pattern through ExcelMLPattern
  • PatternColor - You must also set Pattern in order to be applied Interior.PatternColor

NumberFormat:

  • Format

Example 7: Apply a style before exporting:

private void clubsGrid_InitializingExcelMLStyles_1(object sender, ExcelMLStylesEventArgs e) 
{ 
    ExcelMLStyle style = new ExcelMLStyle("0"); 
 
    // Alignment 
    style.Alignment.Horizontal = ExcelMLHorizontalAlignment.Automatic; 
    style.Alignment.Vertical = ExcelMLVerticalAlignment.Top; 
    style.Alignment.Indent = 5; 
    style.Alignment.Rotate = 0; 
    style.Alignment.ShrinkToFit = true; 
    style.Alignment.VerticalText = true; 
    style.Alignment.WrapText = true; 
 
    // Font 
    style.Font.Bold = true; 
    style.Font.Color = "Beige"; 
    style.Font.FontName = "Calibri"; 
    style.Font.Italic = true; 
    style.Font.Outline = true; 
    style.Font.Shadow = true; 
    style.Font.Size = 10; 
    style.Font.StrikeThrough = true; 
    style.Font.Underline = ExcelMLUnderline.Double; 
 
    // Interior 
    style.Interior.Color = "Green"; 
    style.Interior.Pattern = ExcelMLPattern.Solid; 
    style.Interior.PatternColor = "#FF0000"; 
 
    // NumberFormat 
    style.NumberFormat.Format = "00.00"; 
 
    e.Styles.Add(style); 
} 

See Also

In this article
Not finding the help you need? Improve this article