Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
        }