Example #1
0
        public void Write <T>(ExcelWorksheet excelWorksheet, DataWriterModel dataWriterModel, IEnumerable <T> records)
        {
            if (!records.Any())
            {
                return;
            }

            var properties = typeof(T).GetProperties();

            WriteHeaders(excelWorksheet, properties, dataWriterModel);

            WriteRecords(records, excelWorksheet, properties, dataWriterModel);
        }
Example #2
0
        public void Write(ExcelWorksheet excelWorksheet, DataWriterModel dataWriterModel, IEnumerable <object> records)
        {
            if (!records.Any())
            {
                return;
            }

            var properties = records.First().GetType().GetProperties();

            WriteHeaders(excelWorksheet, properties, dataWriterModel);

            WriteRecords(records, excelWorksheet, properties, dataWriterModel);
        }
Example #3
0
        private static void WriteRecords(IEnumerable records, ExcelWorksheet excelWorksheet, IEnumerable <PropertyInfo> properties, DataWriterModel dataWriterModel)
        {
            foreach (var record in records)
            {
                foreach (var propertyInfo in properties)
                {
                    excelWorksheet.Cells[dataWriterModel.CurrentRow, dataWriterModel.CurrentColumn].Value = propertyInfo.GetValue(record, null);

                    dataWriterModel.NextColumn();
                }

                dataWriterModel.NextRow();
                dataWriterModel.RestartColumns();
            }
        }
Example #4
0
        private static void WriteHeaders(ExcelWorksheet excelWorksheet, IEnumerable <PropertyInfo> properties, DataWriterModel dataWriterModel)
        {
            foreach (var propertyInfo in properties)
            {
                excelWorksheet.Cells[dataWriterModel.CurrentRow, dataWriterModel.CurrentColumn].Value = propertyInfo.Name;

                dataWriterModel.NextColumn();
            }

            dataWriterModel.NextRow();
            dataWriterModel.RestartColumns();
        }