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


C# ICell.SetCellType方法代码示例

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


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

示例1: Confirm

        private void Confirm(IWorkbook wb)
        {
            ISheet sheet = wb.CreateSheet("new sheet");
            cell11 = sheet.CreateRow(0).CreateCell(0);
            cell11.SetCellType(CellType.Formula);

            Confirm("PROPER(\"hi there\")", "Hi There");
            Confirm("PROPER(\"what's up\")", "What'S Up");
            Confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!");
            Confirm("PROPER(\"dr\u00dcb\u00f6'\u00e4 \u00e9lo\u015f|\u00eb\u00e8 \")", "Dr\u00fcb\u00f6'\u00c4 \u00c9lo\u015f|\u00cb\u00e8 ");
            Confirm("PROPER(\"hi123 the123re\")", "Hi123 The123Re");
            Confirm("PROPER(\"-\")", "-");
            Confirm("PROPER(\"!\u00a7$\")", "!\u00a7$");
            Confirm("PROPER(\"/&%\")", "/&%");

            // also test longer string
            StringBuilder builder = new StringBuilder("A");
            StringBuilder expected = new StringBuilder("A");
            for (int i = 1; i < 254; i++)
            {
                builder.Append((char)(65 + (i % 26)));
                expected.Append((char)(97 + (i % 26)));
            }
            Confirm("PROPER(\"" + builder.ToString() + "\")", expected.ToString());
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:25,代码来源:TestProper.cs

示例2: SetUp

 public void SetUp()
 {
     HSSFWorkbook wb = new HSSFWorkbook();
     ISheet sheet = wb.CreateSheet("new sheet");
     cell11 = sheet.CreateRow(0).CreateCell(0);
     cell11.SetCellType(CellType.FORMULA);
     Evaluator = new HSSFFormulaEvaluator(wb);
 }
开发者ID:hanwangkun,项目名称:npoi,代码行数:8,代码来源:TestDate.cs

示例3: SetUp

 public void SetUp()
 {
     System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
     HSSFWorkbook wb = new HSSFWorkbook();
     ISheet sheet = wb.CreateSheet("new sheet");
     cell11 = sheet.CreateRow(0).CreateCell(0);
     cell11.SetCellType(CellType.FORMULA);
     Evaluator = new HSSFFormulaEvaluator(wb);
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:9,代码来源:TestCalendarFieldFunction.cs

示例4: CopyValue

 public void CopyValue(ICell destCell)
 {
     switch (_cellType)
     {
         case CellType.BLANK: destCell.SetCellType(CellType.BLANK); return;
         case CellType.NUMERIC: destCell.SetCellValue(_numberValue); return;
         case CellType.BOOLEAN: destCell.SetCellValue(_boolValue); return;
         case CellType.STRING: destCell.SetCellValue(_stringValue); return;
         case CellType.ERROR: destCell.SetCellErrorValue((byte)_errorValue); return;
     }
     throw new InvalidOperationException("Unexpected data type (" + _cellType + ")");
 }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:12,代码来源:ForkedEvaluationCell.cs

示例5: SetCellType

 private static void SetCellType(ICell cell, CellValue cv)
 {
     CellType cellType = cv.CellType;
     switch (cellType)
     {
         case CellType.BOOLEAN:
         case CellType.ERROR:
         case CellType.NUMERIC:
         case CellType.STRING:
             cell.SetCellType(cellType);
             return;
         case CellType.BLANK:
         // never happens - blanks eventually Get translated to zero
         case CellType.FORMULA:
         // this will never happen, we have already Evaluated the formula
             break;
     }
     throw new InvalidOperationException("Unexpected cell value type (" + cellType + ")");
 }
开发者ID:xiepeixing,项目名称:npoi,代码行数:19,代码来源:XSSFFormulaEvaluator.cs

示例6: WriteCell

        /// <summary>
        /// 写入数据到单元格
        /// </summary>
        /// <param name="cell">要写入数据的单元格实例</param>
        /// <param name="value">要写入的数据</param>
        /// <param name="dataType">要写入数据的类型</param>
        public void WriteCell(ICell cell, object value, CellDataType dataType)
        {
            if (dataType == CellDataType.None || dataType == CellDataType.Null || value == null || value == DBNull.Value)
            {
                cell.SetCellType(CellType.Blank);
                return;
            }

            if (value is DateTime)
            {
                cell.SetCellValue((DateTime)value);
            }
            else if (value is int)
            {
                cell.SetCellValue((int)value);
            }
            else if (value is double)
            {
                cell.SetCellValue((double)value);
            }
            else if (value is decimal)
            {
                cell.SetCellValue(Convert.ToDouble(value));
            }
            else
            {
                cell.SetCellValue(value.ToString());
            }

            if (dataType != CellDataType.None)
            {
                switch (dataType)
                {
                    case CellDataType.Date:
                        cell.CellStyle = cellStyleDictionary["date"];
                        break;
                    case CellDataType.DateTime:
                        cell.CellStyle = cellStyleDictionary["datetime"];
                        break;
                    case CellDataType.Double:
                        cell.CellStyle = cellStyleDictionary["double"];
                        break;
                    default:
                        cell.CellStyle = cellStyleDictionary["text"];
                        break;
                }
            }
        }
开发者ID:bosima,项目名称:FireflySoft.Excel,代码行数:54,代码来源:NPOIOperator.cs

示例7: SetCellType

 private static void SetCellType(ICell cell, CellValue cv)
 {
     CellType cellType = cv.CellType;
     switch (cellType)
     {
         case CellType.Boolean:
         case CellType.Error:
         case CellType.Numeric:
         case CellType.String:
             cell.SetCellType(cellType);
             return;
         case CellType.Blank:
         // never happens - blanks eventually Get translated to zero
         case CellType.Formula:
         // this will never happen, we have already Evaluated the formula
             break;
     }
     throw new InvalidOperationException("Unexpected cell value type (" + cellType + ")");
 }
开发者ID:89sos98,项目名称:npoi,代码行数:19,代码来源:XSSFFormulaEvaluator.cs

示例8: SetCell

        internal void SetCell(ICell excelCell, IVisualValue visualValue )
        {
            if (visualValue.AttentionStyle == VisualAttentionStyle.None)
                excelCell.CellStyle = _neutral;
            switch (visualValue.AttentionStyle)
            {
                case VisualAttentionStyle.Amber:
                    excelCell.CellStyle = _orange;
                    break;
                case VisualAttentionStyle.Green:
                    excelCell.CellStyle = _green;
                    break;
                case VisualAttentionStyle.Red:
                    excelCell.CellStyle = _red;
                    break;
            }

            var attribute = visualValue.VisualValue;
            if (attribute is StringAttributeValue)
            {
                excelCell.SetCellType(CellType.String);
                excelCell.SetCellValue(((StringAttributeValue) (attribute)).Value);
                // todo: can we set here ? cellStyle.Alignment = HorizontalAlignment.Fill;
            }
            else if (attribute is IntegerAttributeValue)
            {
                excelCell.SetCellType(CellType.Numeric);
                var v = ((IntegerAttributeValue) (attribute)).Value;
                if (v.HasValue)
                {
                    // ReSharper disable once RedundantCast
                    excelCell.SetCellValue((double) v.Value);
                }
            }
            else if (attribute is DecimalAttributeValue)
            {
                excelCell.SetCellType(CellType.Numeric);
                var v = ((DecimalAttributeValue) (attribute)).Value;
                if (v.HasValue)
                {
                    // ReSharper disable once RedundantCast
                    excelCell.SetCellValue((double) v.Value);
                }
            }
            else if (attribute is BooleanAttributeValue)
            {
                excelCell.SetCellType(CellType.Boolean);
                var v = ((BooleanAttributeValue) (attribute)).Value;
                if (v.HasValue)
                {
                    excelCell.SetCellValue(v.Value);
                }
            }
            else if (attribute is DateTimeAttributeValue)
            {
                
                // var dataFormatStyle = excelCell.Sheet.Workbook.CreateDataFormat();
                excelCell.CellStyle.DataFormat = 0x16; //  dataFormatStyle.GetFormat("yyyy/MM/dd HH:mm:ss");
                var v = ((DateTimeAttributeValue)(attribute)).Value;
                if (!v.HasValue) 
                    return;
                // dataformats from: https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html
                excelCell.CellStyle.DataFormat = 0x16;
                excelCell.SetCellValue(v.Value);
            }
            
        }
开发者ID:McLeanBH,项目名称:XbimExchange,代码行数:67,代码来源:ExcelCellVisualValue.cs

示例9: SetCell

 /// <summary>
 /// 设置单元格
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="property"></param>
 /// <param name="obj"></param>
 private static void SetCell(ICell cell, PropertyInfo property, object obj)
 {
     //如果该属性为null,设置单元格为空格
     if (property.GetValue(obj, null) == null)
     {
         cell.SetCellType(CellType.Blank);
         return;
     }
     //判断属性类型
     switch (property.PropertyType.Name.ToLower())
     {
         case "char":
         case "string":
             cell.SetCellValue(Convert.ToString(property.GetValue(obj, null)));
             break;
         case "double":
         case "single":
         case "int32":
             cell.SetCellValue(Convert.ToDouble(property.GetValue(obj, null)));
             break;
         case "boolean":
             cell.SetCellValue(Convert.ToBoolean(property.GetValue(obj, null)));
             break;
         case "datetime":
             cell.SetCellValue(Convert.ToDateTime(property.GetValue(obj, null)));
             cell.CellStyle = _dateStyle;
             break;
         default:
             cell.SetCellValue(property.GetValue(property, null).ToString());
             break;
     }
 }
开发者ID:v5bep7,项目名称:Utility,代码行数:38,代码来源:ExcelHelper.cs

示例10: CopyValue

 public void CopyValue(ICell destCell)
 {
     switch (_cellType)
     {
         case CellType.Blank: destCell.SetCellType(CellType.Blank); return;
         case CellType.Numeric: destCell.SetCellValue(_numberValue); return;
         case CellType.Boolean: destCell.SetCellValue(_boolValue); return;
         case CellType.String: destCell.SetCellValue(_stringValue); return;
         case CellType.Error: destCell.SetCellErrorValue((byte)_errorValue); return;
     }
     throw new InvalidOperationException("Unexpected data type (" + _cellType + ")");
 }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:12,代码来源:ForkedEvaluationCell.cs

示例11: SetCellValue

        public static void SetCellValue(this IWorkbook workbook, ICell cell, object cellValue)
        {
            var colType = cellValue != null ? cellValue.GetType() : null;

            if (colType == null || cellValue is DBNull) return;

            if (_numericTypes.Contains(colType))
            {
                cell.SetCellType(CellType.NUMERIC);
                cell.SetCellValue(Convert.ToDouble(cellValue));
            }
            else if (_stringConvertableTypes.Contains(colType))
            {
                cell.SetCellValue(cellValue.ToString());
            }
            else if (colType == typeof(DateTime))
            {
                var style = workbook.CreateCellStyle();
                var format = workbook.CreateDataFormat();
                const string dateFormat = "dd MMM yyyy hh:mm:ss";

                cell.SetCellValue(((DateTime)cellValue).ToString(dateFormat));
                style.DataFormat = format.GetFormat(dateFormat);
                cell.SetCellType(CellType.STRING);
                cell.CellStyle = style;
            }
            else
            {
                var toStringMethod = colType.GetMethod("ToString", BindingFlags.Public);

                if (toStringMethod != null && toStringMethod.DeclaringType != typeof(object))
                {
                    // Has custom ToString method
                    cell.SetCellValue(cellValue.ToString());
                }
            }
        }
开发者ID:kirkpabk,项目名称:higgs,代码行数:37,代码来源:ExcelHelper.cs


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