Esempio n. 1
0
        public void SetValue(object value, ExcelCellType type)
        {
            string text = Convert.ToString(value, CultureInfo.InvariantCulture);

            if (String.IsNullOrEmpty(text))
            {
                return;
            }
            switch (type)
            {
            case ExcelCellType.String:
                cell.CellValue = new CellValue(text);
                cell.DataType  = new EnumValue <CellValues>(CellValues.String);
                break;

            case ExcelCellType.SharedString:
                int index = row.sheet.document.InsertSharedStringItem(text);
                cell.CellValue = new CellValue(index.ToString());
                cell.DataType  = new EnumValue <CellValues>(CellValues.SharedString);
                break;

            case ExcelCellType.Number:
                cell.CellValue = new CellValue(text.Replace(',', '.'));
                cell.DataType  = new EnumValue <CellValues>(CellValues.Number);
                break;

            case ExcelCellType.Date:
                text            = Convert.ToDateTime(value).ToOADate().ToString(CultureInfo.InvariantCulture);
                cell.CellValue  = new CellValue(text);
                cell.DataType   = CellValues.Number;
                cell.StyleIndex = ExcelDocument.DateTypeIndex;
                break;

            case ExcelCellType.Boolean:
                text           = Convert.ToInt32(value, CultureInfo.InvariantCulture).ToString();
                cell.CellValue = new CellValue(text);
                cell.DataType  = new EnumValue <CellValues>(CellValues.Boolean);
                break;
            }
        }
Esempio n. 2
0
 public void SetValue(object value, ExcelCellType type)
 {
     string text = Convert.ToString(value, CultureInfo.InvariantCulture);
     if (String.IsNullOrEmpty(text)) return;
     switch (type)
     {
         case ExcelCellType.String:
             cell.CellValue = new CellValue(text);
             cell.DataType = new EnumValue<CellValues>(CellValues.String);
             break;
         case ExcelCellType.SharedString:
             int index = row.sheet.document.InsertSharedStringItem(text);
             cell.CellValue = new CellValue(index.ToString());
             cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
             break;
         case ExcelCellType.Number:
             cell.CellValue = new CellValue(text.Replace(',', '.'));
             cell.DataType = new EnumValue<CellValues>(CellValues.Number);
             break;
         case ExcelCellType.Date:
             text = Convert.ToDateTime(value).ToOADate().ToString(CultureInfo.InvariantCulture);
             cell.CellValue = new CellValue(text);
             cell.DataType = CellValues.Number;
             cell.StyleIndex = ExcelDocument.DateTypeIndex;
             break;
         case ExcelCellType.Boolean:
             text = Convert.ToInt32(value, CultureInfo.InvariantCulture).ToString();
             cell.CellValue = new CellValue(text);
             cell.DataType = new EnumValue<CellValues>(CellValues.Boolean);
             break;
     }
 }
Esempio n. 3
0
 public ExcelCell(object val, ExcelCellType type = ExcelCellType.String, int?styleIndex = null)
 {
     Value = val; ValueType = type; StyleIndex = styleIndex;
 }
Esempio n. 4
0
 public void SetValue(object val, ExcelCellType type = ExcelCellType.String)
 {
     Value = val; ValueType = type;
 }
Esempio n. 5
0
        /// <summary>
        /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="headerName">Name of the header.</param>
        /// <param name="valueFunction">The value function.</param>
        /// <param name="cellType">Type of the cell.</param>
        /// <param name="updateHeader">if set to <c>true</c> [update header].</param>
        /// <param name="formatCode">The format code.</param>
        public void Add(string columnName, string headerName, Expression <Func <T, object> > valueFunction, ExcelCellType cellType = ExcelCellType.General, bool updateHeader = false, string formatCode = null)
        {
            ColumnInfo <T> item = new ColumnInfo <T>(columnName, headerName, valueFunction)
            {
                UpdateHeader = updateHeader,
                CellType     = cellType,
                FormatCode   = formatCode
            };

            this.Add(item);
        }