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


C# ICell.SetCellValue方法代码示例

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


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

示例1: SetCellValue

        /// <summary>
        /// Sets a cell value
        /// </summary>
        /// <param name="cell">The cell</param>
        /// <param name="value">The value to be assigned to the cell</param>
        public static void SetCellValue(ICell cell, object value)
        {
            if (value == null)
                cell.SetCellValue(null as string);

            else if (value is string ||
                     value is String)
                cell.SetCellValue(value as string);

            else if (value is bool ||
                     value is Boolean)
                cell.SetCellValue((bool) value);

            else if (value is DateTime) {
                //It works
                var wb = cell.Sheet.Workbook;
                var cellStyle = wb.CreateCellStyle();
                cellStyle.DataFormat = cell.Sheet.Workbook.GetCreationHelper().CreateDataFormat().GetFormat("dd/mm/yyyy" );
                cell.CellStyle = cellStyle;                
                cell.SetCellValue((DateTime) value);
            }

            else
                cell.SetCellValue(Convert.ToDouble(value));
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:30,代码来源:NPOIUtils.cs

示例2: SetCellValue

        private static void SetCellValue(HSSFWorkbook workbook, ICell workCell, Type type, dynamic row, Cell cell)
        {
            var value = type.GetProperty(cell.Field).GetValue(row);
            if (value == null)
            {
                return;
            }

            if (value is DateTime)
            {
                workCell.SetCellValue((DateTime)value);
            }
            else if (value is int)
            {
                workCell.SetCellValue((int)value);
            }
            else if (value is double)
            {
                workCell.SetCellValue((double)value);
            }
            else
            {
                workCell.SetCellValue(value.ToString());
            }

            if (!string.IsNullOrWhiteSpace(cell.Format))
            {
                var cellStyle = workbook.CreateCellStyle();
                var format = workbook.CreateDataFormat();
                cellStyle.DataFormat = format.GetFormat(cell.Format);
                workCell.CellStyle = cellStyle;
            }
        }
开发者ID:ErikXu,项目名称:CommonLibrary,代码行数:33,代码来源:ExcelUtil.cs

示例3: SetValueAndFormat

 static void SetValueAndFormat(IWorkbook workbook, ICell cell, double value, short formatId)
 {
     cell.SetCellValue(value);
     ICellStyle cellStyle = workbook.CreateCellStyle();
     cellStyle.DataFormat = formatId;
     cell.CellStyle = cellStyle;
 }
开发者ID:ctddjyds,项目名称:npoi,代码行数:7,代码来源:Program.cs

示例4: SetCellValue

        public static void SetCellValue( ICell cell, object value )
        {
            if( value == null )
                cell.SetCellValue( null as string );

            if( value is string || value is String )
                cell.SetCellValue( value as string );

            if( value is bool || value is Boolean )
                cell.SetCellValue( (bool)value );

            if( value is DateTime )
                cell.SetCellValue( (DateTime)value );

            cell.SetCellValue( Convert.ToDouble( value ) );
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:16,代码来源:NPOIUtils.cs

示例5: GetFormattedValue

        //
        // Get formatted value as string from the specified cell
        //
        protected string GetFormattedValue(ICell cell)
        {
            string returnValue = string.Empty;
            if (cell != null)
            {
                try
                {
                    // Get evaluated and formatted cell value
                    returnValue = this.dataFormatter.FormatCellValue(cell, this.formulaEvaluator);
                }
                catch
                {
                    // When failed in evaluating the formula, use stored values instead...
                    // and set cell value for reference from formulae in other cells...
                    if (cell.CellType == CellType.Formula)
                    {
                        switch (cell.CachedFormulaResultType)
                        {
                            case CellType.String:
                                returnValue = cell.StringCellValue;
                                cell.SetCellValue(cell.StringCellValue);
                                break;
                            case CellType.Numeric:
                                returnValue = dataFormatter.FormatRawCellContents
                                (cell.NumericCellValue, 0, cell.CellStyle.GetDataFormatString());
                                cell.SetCellValue(cell.NumericCellValue);
                                break;
                            case CellType.Boolean:
                                returnValue = cell.BooleanCellValue.ToString();
                                cell.SetCellValue(cell.BooleanCellValue);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            return (returnValue ?? string.Empty).Trim();
        }
开发者ID:SolemmaLLC,项目名称:ArchsimLibraryData,代码行数:43,代码来源:ExcelFileReader.cs

示例6: CellPadding

 public static void CellPadding(string value, ICell cell, Tk5FieldInfoEx fieldInfo)
 {
     Tk5ExtensionConfig exConfig = fieldInfo.Extension;
     if (exConfig != null && exConfig.Format != null)
     {
         string strformat = string.Format(ObjectUtil.SysCulture, "{{0:{0}}}", exConfig.Format);
         string result = string.Format(ObjectUtil.SysCulture, strformat, value);
         cell.SetCellValue(result);
     }
     else
     {
         switch (fieldInfo.DataType)
         {
             case TkDataType.Long:
             case TkDataType.Int:
             case TkDataType.Short:
             case TkDataType.Byte:
             case TkDataType.Double:
             case TkDataType.Decimal:
             case TkDataType.Money:
                 double number = value.Value<double>();
                 cell.SetCellValue(number);
                 break;
             case TkDataType.String:
             case TkDataType.Text:
             case TkDataType.Guid:
             case TkDataType.Xml:
                 cell.SetCellValue(value);
                 break;
             case TkDataType.DateTime:
             case TkDataType.Date:
                 DateTime dt = value.Value<DateTime>();
                 cell.SetCellValue(dt);
                 break;
         }
     }
 }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:37,代码来源:ExcelUtil.cs

示例7: SetCellValue

 /// <summary>
 /// set the cell value 
 /// </summary>
 /// <param name="cell">the cell which will be assigned value</param>
 /// <param name="type">the type of assigning value</param>
 /// <param name="value">the assigning value</param>
 private static void SetCellValue(ICell cell,Type type,object value)
 {
     switch (type.ToString())
      {
         case "System.String":
               cell.SetCellValue(value.ToString());
               break;
         case "System.DateTime":
               cell.SetCellValue((DateTime)value);
               break;
         case "System.Boolean":
               cell.SetCellValue((bool)value);
               break;
         case "System.Int16"://Numeric
         case "System.Int32":
         case "System.Int64":
         case "System.Byte":
         case "System.Decimal":
         case "System.Double":
               cell.SetCellValue(Convert.ToDouble(value));
               break;
         case "System.DBNull":
               break;
     }
 }
开发者ID:junyong-tsui,项目名称:csharpexamples,代码行数:31,代码来源:ExcelHelper.cs

示例8: SetCellValue

        /* package */
        static void SetCellValue(ICell cell, String text)
        {
            cell.SetCellValue(text);

        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:6,代码来源:BaseTestDataValidation.cs

示例9: SetCellValue

 public virtual void SetCellValue(ICell cell, JToken token)
 {
     if (token == null)
     {
         cell.SetCellValue((string)null);
         return;
     }
     try
     {
         switch (token.Type)
         {
             case JTokenType.None:
             case JTokenType.Null:
             case JTokenType.Undefined:
                 cell.SetCellValue((string)null);
                 break;
             case JTokenType.Integer:
             case JTokenType.Float:
                 cell.SetCellValue((double)token);
                 break;
             case JTokenType.Date:
                 cell.SetCellValue((DateTime)token);
                 break;
             case JTokenType.String:
             case JTokenType.Guid:
             case JTokenType.Uri:
                 cell.SetCellValue((string)token);
                 break;
             case JTokenType.Boolean:
                 cell.SetCellValue((bool)token);
                 break;
         }
     }
     catch (Exception ex) {
         var ms = ex.Message;
     }
 }
开发者ID:alittletired,项目名称:mysoft,代码行数:37,代码来源:ExcelMetaData.cs

示例10: SetCellValue

 /// <summary>
 /// 根据数据类型设置单元格内容
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="obj"></param>
 /// <param name="dc"></param>
 private static void SetCellValue(ICell cell, object obj, DataColumn dc)
 {
     if (dc.DataType == typeof(bool))
     {
         cell.SetCellValue((bool)obj);
     }
     else if (dc.DataType == typeof(int))
     {
         cell.SetCellValue((Int32)obj);
     }
     else if (dc.DataType == typeof(decimal))
     {
         cell.SetCellValue(Convert.ToDouble(obj));
     }
     else
     {
         cell.SetCellValue(obj.ToString());
     }
 }
开发者ID:NickQi,项目名称:TianheDemo,代码行数:25,代码来源:ExportHelper.cs

示例11: 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

示例12: SetCellTypedValue

        private bool SetCellTypedValue(ICell excelCell, COBieCell cell)
        {
            bool processed = false;

            try
            {
                if (String.IsNullOrEmpty(cell.CellValue) || cell.CellValue == Constants.DEFAULT_STRING)
                {
                    return false;
                }

                // We need to set the value in the most appropriate overload of SetCellValue, so the parsing/formatting is correct
                switch (cell.COBieColumn.AllowedType)
                {
                    case COBieAllowedType.ISODateTime:
                    case COBieAllowedType.ISODate:
                        DateTime date;
                        if (DateTime.TryParse(cell.CellValue, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out date))
                        {
                            excelCell.SetCellValue(date);
                            processed = true;
                        }
                        break;

                    case COBieAllowedType.Numeric:
                        Double val;
                        if (Double.TryParse(cell.CellValue, out val))
                        {
                            excelCell.SetCellValue(val);
                            processed = true;
                        }
                        break;

                    default:
                        break;
                }
            }
            catch (SystemException)
            { /* Carry on */ }

            return processed;
        }
开发者ID:McLeanBH,项目名称:XbimExchange,代码行数:42,代码来源:COBieXLSXSerialiser.cs

示例13: setCellText

 private static void setCellText(ICell cell, String text)
 {
     cell.SetCellValue(new HSSFRichTextString(text));
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:4,代码来源:TestBugs.cs

示例14: 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

示例15: SetCellValue

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


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