private (int Row, int Column) WriteBody(IEnumerable <object> dataset, WorksheetBlockBase block, ref ExcelWorksheet worksheet) { var currentRow = block.StartRow; var currentColumn = 0; var propertyLocations = new List <PropertyLocation>(); foreach (var data in dataset) { currentRow++; for (int index = 0; index < block.Rules.Count; index++) { currentColumn = block.StartColumn + index; var rule = block.Rules[index]; var cellRange = worksheet.Cells[currentRow, currentColumn]; cellRange.Value = rule.GetValue(data); rule.AutoFit?.Invoke(cellRange); rule.ApplyStyle(WorksheetSection.Cell, ref cellRange); rule.ApplyStyle(WorksheetSection.EachCell, ref cellRange); rule.Options?.Invoke(cellRange); propertyLocations.Add(new PropertyLocation(PropertyLocation.PropertyLocationSectionType.Body, rule.GetHashCode(), currentRow, currentColumn)); } var bodyRange = worksheet.Cells[block.StartRow, block.StartColumn, currentRow, currentColumn]; block.ApplyStyle(WorksheetSection.Body, ref bodyRange); } BlockPropertyLocation.AddRange(block.Id, propertyLocations); return(currentRow, currentColumn); }
private (int Row, int Column) WriteHeader(WorksheetBlockBase block, ref ExcelWorksheet worksheet) { var propertyLocations = new List <PropertyLocation>(); //Write title var lastColumnHeaderPos = block.StartColumn + block.Rules.Count - 1; if (!string.IsNullOrWhiteSpace(block.Title?.Value)) { var titleRow = block.StartRow; worksheet.Cells[titleRow, block.StartColumn].Value = block.Title.Value; var cellRange = worksheet.Cells[titleRow, block.StartColumn, titleRow, lastColumnHeaderPos]; cellRange.Merge = true; block.ApplyStyle(WorksheetSection.Title, ref cellRange); block.ApplyStyle(WorksheetSection.EachCell, ref cellRange); block.StartRow++; } //Write headers for (int index = 0; index < block.Rules.Count; index++) { var rule = block.Rules[index]; var column = block.StartColumn + index; var cellRange = worksheet.Cells[block.StartRow, column]; cellRange.Value = rule.Caption?.Value ?? rule.Expression.GetMember().Name; rule.AutoFit?.Invoke(cellRange); rule.ApplyStyle(WorksheetSection.Caption, ref cellRange); block.ApplyStyle(WorksheetSection.EachCell, ref cellRange); propertyLocations.Add(new PropertyLocation(PropertyLocation.PropertyLocationSectionType.Header, rule.GetHashCode(), block.StartRow, column)); } var header = worksheet.Cells[block.StartRow, block.StartColumn, block.StartRow, lastColumnHeaderPos]; block.ApplyStyle(WorksheetSection.Header, ref header); BlockPropertyLocation.AddRange(block.Id, propertyLocations); return(block.StartRow, lastColumnHeaderPos); }