Esempio n. 1
0
        internal CellRead TryReadColumnInfo(int index)
        {
            var cell = ActiveWorksheet.Cell(CurrentRowIndex, index);

            return(new CellRead()
            {
                Type = cell.DataType,
                Value = cell.Value ?? null
            });
        }
Esempio n. 2
0
        private void CreateTable()
        {
            if (TableStyle == null)
            {
                return;
            }

            var table = ActiveWorksheet.Range(1, 1, Data.Count + 1, Columns.Count).CreateTable();

            table.Theme = TableStyle;
        }
Esempio n. 3
0
        private void WriteHeaders()
        {
            foreach (var column in Columns)
            {
                var cell = ActiveWorksheet.Cell(CurrentRowIndex, column.Index);
                cell.DataType = XLDataType.Text;
                cell.Value    = column.Label;

                SetCellBackgroundColor(column.Index, column.HeaderBackgroundColor);
            }

            CurrentRowIndex++;
        }
Esempio n. 4
0
        private void WriteContentLines()
        {
            foreach (var rowData in DataToExport)
            {
                foreach (var column in Columns)
                {
                    rowData.TryGetValue(column.Label, out var value);
                    var cell = ActiveWorksheet.Cell(CurrentRowIndex, column.Index);
                    cell.Value = value.Value;
                }
                CurrentRowIndex++;
            }

            foreach (var column in Columns)
            {
                ActiveWorksheet.Column(column.Index).AdjustToContents();
            }
        }
Esempio n. 5
0
        private void FormatColumn(ColumnInfo <T> column)
        {
            var range = ActiveWorksheet.Range(2, column.Index, Data.Count + 1, column.Index);

            if (!string.IsNullOrEmpty(column.Mask))
            {
                range.Style.NumberFormat.SetFormat(column.Mask);
            }

            if (column.Type == TypesEnum.String)
            {
                range.DataType = XLDataType.Text;
            }

            if (column.Type == TypesEnum.Bool || column.Type == TypesEnum.NullableBool)
            {
                range.DataType = XLDataType.Boolean;
            }

            if (column.Type == TypesEnum.Int || column.Type == TypesEnum.NullableInt)
            {
                range.DataType = XLDataType.Number;
            }

            if (column.Type == TypesEnum.Long || column.Type == TypesEnum.NullableLong)
            {
                range.DataType = XLDataType.Number;
            }

            if (column.Type == TypesEnum.Decimal || column.Type == TypesEnum.NullableDecimal)
            {
                range.DataType = XLDataType.Number;
            }

            if (column.Type == TypesEnum.DateTime || column.Type == TypesEnum.NullableDateTime)
            {
                range.DataType = XLDataType.DateTime;
            }
        }
Esempio n. 6
0
 private bool IsLastRow()
 {
     return(ActiveWorksheet.LastRowUsed().RowNumber() - CurrentRowIndex == 0);
 }
Esempio n. 7
0
        private void SetCellBackgroundColor(int columnIndex, Color color)
        {
            var cell = ActiveWorksheet.Cell(CurrentRowIndex, columnIndex);

            cell.Style.Fill.BackgroundColor = XLColor.FromColor(color);
        }