Example #1
0
        /// <summary>
        /// Agrega informacion a la Sheet que este en memoria
        /// </summary>
        private void AddInformation()
        {
            var cont = _rowInicial;

            foreach (var item in _informacion)
            {
                var row  = _currentsheet.GetRow(cont) ?? _currentsheet.CreateRow(cont);
                var cell = 0;

                foreach (var prop in item.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
                {
                    var celda = row.GetCell(cell) ?? row.CreateCell(cell);

                    var style = _currentsheet.GetColumnStyle(cell);
                    if (prop.PropertyType == typeof(DateTime))
                    {
                        var date = (DateTime)prop.GetValue(item, null);
                        celda.SetCellValue(date.Date);
                        style.DataFormat = _excel.CreateDataFormat().GetFormat("MM/dd/yyyy");
                    }
                    else if (prop.PropertyType == typeof(decimal))
                    {
                        var money = (decimal)prop.GetValue(item, null);
                        celda.SetCellValue(Convert.ToDouble(money));
                        style.DataFormat = _excel.CreateDataFormat().GetFormat("[$$-409]#,##0.00");

                        celda.SetCellType(CellType.Numeric);
                    }
                    else
                    {
                        celda.SetCellValue(prop.GetValue(item, null).ToString());
                    }


                    celda.CellStyle = style;
                    cell++;
                }
                cont++;
            }
        }
Example #2
0
 public ICellStyle GetColumnStyle(int column)
 {
     return(_sh.GetColumnStyle(column));
 }