示例#1
0
        private void Write(IEnumerable source, ICsvReportConfiguration config, TypeAccessor.TypeAccessor accessor)
        {
            var configuration = GetConfiguration();

            using (var writer = new CsvHelper.CsvWriter(TextWriter, configuration))
            {
                WriteHeader(config, writer);

                WriteRecords(source, config, accessor, writer);
            }
        }
示例#2
0
        private void Write(IEnumerable source, IExcelReportConfiguration config, TypeAccessor.TypeAccessor accessor)
        {
            if (config.Options.IsSetHeaderStyle)
            {
                var headerCells = GetHeaderRange(Worksheet, config, Cursor);
                ExcelStyleApplier.ApplyStyle(config.Options.HeaderStyleName, config.Options.HeaderStyle, headerCells);
            }

            WriteHeader(config);

            WriteRecords(source, config, accessor);
        }
示例#3
0
        public void Write(IEnumerable source, ICsvReportConfiguration config)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var accessor = new TypeAccessor.TypeAccessor();

            Write(source, config, accessor);
        }
示例#4
0
        protected virtual void WriteRecords(IEnumerable source, ICsvReportConfiguration config, TypeAccessor.TypeAccessor accessor, CsvHelper.CsvWriter writer)
        {
            foreach (var row in source)
            {
                var memberOptions = config.MemberConfigurations.GetActiveOrderlyOptions();
                foreach (var column in memberOptions)
                {
                    var    value          = accessor.GetValue(row, column.MemberName);
                    string formattedValue = value.ToString();
                    if (column.Formatter != null)
                    {
                        formattedValue = column.Formatter.Format(value);
                    }
                    else if (column.FormatterExpression != null)
                    {
                        formattedValue = ReportHelper.ReportHelper.CreateFormatFunc(value, column.FormatterExpression)(value);
                    }

                    writer.WriteField(formattedValue);
                }
                writer.NextRecord();
            }
        }
示例#5
0
        protected virtual void WriteRecords(IEnumerable source, IExcelReportConfiguration config, TypeAccessor.TypeAccessor accessor)
        {
            var memberOptions = config.MemberConfigurations.GetActiveOrderlyOptions().ToList();

            int countRows = CountRows(source);
            var cacheFormatterExpression = new Dictionary <string, Func <object, string> >();

            int excelRowsCount    = memberOptions.Max(r => r.RowSpan) * countRows;
            int excelColSpanCount = memberOptions.Sum(r => r.ColSpan);
            var data = new object[excelRowsCount, excelColSpanCount];

            var insertedRowFromSource = -1;

            foreach (var row in source)
            {
                insertedRowFromSource++;
                var columnIndex = -1;
                foreach (var options in memberOptions)
                {
                    object value = accessor.GetValue(row, options.MemberName);

                    if (!options.IsStyleSet && config.Options.IsSetDefaultStyle)
                    {
                        options.IsStyleSet = config.Options.IsSetDefaultStyle;
                        options.StyleName  = config.Options.DefaultStyleName;
                    }

                    string formattedValue = null;
                    if (options.Formatter != null)
                    {
                        formattedValue = options.Formatter.Format(value);
                    }
                    else if (options.FormatterExpression != null)
                    {
                        if (!cacheFormatterExpression.ContainsKey(options.MemberName))
                        {
                            cacheFormatterExpression[options.MemberName] =
                                ReportHelper.ReportHelper.CreateFormatFunc(value, options.FormatterExpression);
                        }

                        formattedValue =
                            cacheFormatterExpression[options.MemberName](value);
                    }

                    for (var rowIndex = 0; rowIndex < options.RowSpan; rowIndex++)
                    {
                        for (var colIndex = 0; colIndex < options.ColSpan; colIndex++)
                        {
                            columnIndex++;
                            data[insertedRowFromSource + rowIndex, columnIndex] = formattedValue ?? value;
                        }
                    }
                }
            }

            var prevCursor = (Cursor)Cursor.Clone();

            WriteData(data);
            ApplyStyleForWrittenData(prevCursor, config, memberOptions, data);
        }