当前位置: 首页>>代码示例>>C#>>正文


C# IWorkbook.GetCellStyleAt方法代码示例

本文整理汇总了C#中IWorkbook.GetCellStyleAt方法的典型用法代码示例。如果您正苦于以下问题:C# IWorkbook.GetCellStyleAt方法的具体用法?C# IWorkbook.GetCellStyleAt怎么用?C# IWorkbook.GetCellStyleAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWorkbook的用法示例。


在下文中一共展示了IWorkbook.GetCellStyleAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetCellStyleProperty

        /**
         * This method attempt to find an already existing CellStyle that matches what you want the
         * style to be. If it does not find the style, then it creates a new one. If it does create a
         * new one, then it applies the propertyName and propertyValue to the style. This is necessary
         * because Excel has an upper limit on the number of Styles that it supports.
         *
         *@param workbook The workbook that is being worked with.
         *@param propertyName The name of the property that is to be changed.
         *@param propertyValue The value of the property that is to be changed.
         *@param cell The cell that needs it's style changes
         */
        public static void SetCellStyleProperty(ICell cell, IWorkbook workbook, String propertyName,
                Object propertyValue)
        {
            ICellStyle originalStyle = cell.CellStyle;
            ICellStyle newStyle = null;
            Dictionary<String, Object> values = GetFormatProperties(originalStyle);
            if (values.ContainsKey(propertyName))
                values[propertyName] = propertyValue;
            else
                values.Add(propertyName, propertyValue);

            // index seems like what index the cellstyle is in the list of styles for a workbook.
            // not good to compare on!
            short numberCellStyles = workbook.NumCellStyles;

            for (short i = 0; i < numberCellStyles; i++)
            {
                ICellStyle wbStyle = workbook.GetCellStyleAt(i);

                Dictionary<String, Object> wbStyleMap = GetFormatProperties(wbStyle);

                if (wbStyleMap.Equals(values))
                {
                    newStyle = wbStyle;
                    break;
                }
            }

            if (newStyle == null)
            {
                newStyle = workbook.CreateCellStyle();
                SetFormatProperties(newStyle, workbook, values);
            }

            cell.CellStyle=(newStyle);
        }
开发者ID:missxiaohuang,项目名称:Weekly,代码行数:47,代码来源:CellUtil.cs


注:本文中的IWorkbook.GetCellStyleAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。