Example #1
0
        /// <summary>
        /// 填充数据
        /// </summary>
        public override void Fill()
        {
            if (Data != null && Data.Rows.Count > 0)
            {
                //导入初始行  0 位第一行标题
                var start = 1;
                // 表格值
                string colsValue = null;
                ICellStyle cellStyle = null;
                foreach (DataRow dr in Data.Rows)
                {
                    IRow _row = SheetThis.CreateRow(start);
                    for (int i = 0; i < this.Columns.Length; i++)
                    {
                        var cell = _row.CreateCell(i);
                        // get cell value
                        colsValue = dr[this.Columns[i].ColName] + "";

                        // format cell value
                        this.Columns[i].FormattedValue(cell, dr, start, ref colsValue);

                        // 获取单元格样式 默认从字典中读取
                        cellStyle = GetCellStyle(this.Columns[i].DataType);
                        // 设置单元格数据
                        this.Columns[i].DataType.SetCellValue(cell, colsValue, cellStyle);
                    }
                    start++;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 创建标题
        /// </summary>
        public virtual void CreateTitle()
        {
            IRow row = SheetThis.CreateRow(0);
            var  i   = 0;

            if (Columns == null || Columns.Length == 0)
            {
                this.InitDefaultColumns();
            }
            if (Columns != null)
            {
                foreach (var col in Columns)
                {
                    ICell cell = row.CreateCell(i++);
                    cell.SetCellValue(col.ColTitleName);
                    cell.CellStyle = GetTitleStyle(WorkBook);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 填充数据
        /// </summary>
        public override void Fill()
        {
            if (Data != null && Data.Count > 0)
            {
                // 导入初始行  0 位第一行标题
                var start = 1;
                // 表格值
                string     colsValue = null;
                ICellStyle cellStyle = null;
                var        clazz     = GetClazz();
                foreach (T t in Data)
                {
                    IRow _row = SheetThis.CreateRow(start);
                    for (int i = 0; i < this.Columns.Length; i++)
                    {
                        var cell = _row.CreateCell(i);
                        // get cell value
                        try
                        {
                            colsValue = clazz.GetProperty(this.Columns[i].ColName).GetValue(t) + "";
                        }
                        catch (Exception)
                        {
                            //未找到该属性
                        }

                        // format cell value
                        this.Columns[i].FormattedValue(cell, t, start, ref colsValue);

                        // 获取单元格样式 默认从字典中读取
                        cellStyle = GetCellStyle(this.Columns[i].DataType);
                        // 设置单元格数据
                        this.Columns[i].DataType.SetCellValue(cell, colsValue, cellStyle);
                    }
                    start++;
                }
            }
        }