0

I am editing an existing excel spreadsheet with an existing cell Style in it called "myFavouriteStyle".

Using OpenXML SDK V2 c# how do I find the StyleIndex of that style so I can apply it to new cell(s) I add to the spreadsheet.

Thanks.

David
  • 560
  • 4
  • 13

1 Answers1

1

If you can get a reference to a Cell with the "myFavouriteStyle" applied to it you could:

public static int GetCellStyleIndex(Cell theCell)
{ 
  int cellStyleIndex;
  if (theCell.StyleIndex == null) 
  {                               
    cellStyleIndex = 0;           
  }                              
  else
  {
    cellStyleIndex = (int)theCell.StyleIndex.Value;
  }     

  return cellStyleIndex;
}
Erwin
  • 3,060
  • 26
  • 24
  • Thanks for that, I had already thought of that 1, just reluctant to go that way as a user may change or remove that format from the cell in question. – David Mar 21 '13 at 15:21
  • Is it an option to make a protected sheet containing a cell for each style you want to use in your code? – Erwin Mar 22 '13 at 06:57