Пример #1
0
        public byte[] Export(Tin[] records, ReportOptions options)
        {
            using var package = options.Template == null
                ? new ExcelPackage()
                : new ExcelPackage(new MemoryStream(options.Template));

            var columns = GetColumns();

            var chunkCount = records.Length / options.PageSize + 1;

            for (var i = 0; i < chunkCount; i++)
            {
                var chunk = records
                            .Skip(i * options.PageSize)
                            .Take(options.PageSize)
                            .ToArray();

                var ws = GetWorkSheet(
                    package.Workbook,
                    GetWorkSheetName(i, options.PageSize, chunk.Length),
                    columns,
                    options);

                for (var j = 0; j < records.Length; j++)
                {
                    var record = records[j];
                    for (var k = 0; k < columns.Length; k++)
                    {
                        var column = columns[k];
                        ws.Cells[j + 1 + options.StartFrom, k + 1].Value =
                            record.GetValue(column);
                    }
                }
            }

            return(package.GetAsByteArray());
        }