繁体   English   中英

使用OpenXML如何在Excel电子表格中获取现有样式的StyleIndex

[英]With OpenXML how do I get the StyleIndex of an existing style in an excel spreadsheet

我正在编辑一个现有的excel电子表格,其中包含一个名为“ myFavouriteStyle ”的现有单元格样式。

使用OpenXML SDK V2 c#,如何找到该样式的StyleIndex ,以便可以将其应用于添加到电子表格中的新单元格。

谢谢。

如果您可以获得对引用了应用了“ myFavouriteStyle”的单元格的引用,则可以:

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

  return cellStyleIndex;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM