private static Row GetPreparedRow(Row row, Cell.BorderPositionEnum borderPosition, IEnumerable <BorderInformation.BorderStyleEnum> borderStyles) { foreach (var column in row.Columns) { if (!column.Borders.ContainsKey(borderPosition)) { column.Borders.Add(borderPosition, new BorderInformation { BorderStyle = BorderInformation.BorderStyleEnum.None }); } if (!borderStyles.Contains(column.Borders[borderPosition].BorderStyle)) { column.Borders[borderPosition].BorderStyle = BorderInformation.BorderStyleEnum.None; } } return(row); }
protected Dictionary <string, BorderInformation.BorderStyleEnum> GetRuleRangesFromTo(Row row, Cell.BorderPositionEnum borderPosition) { var borderIsSet = GetBorderSet(row, borderPosition); var columnCount = row.Columns.Count; Dictionary <string, BorderInformation.BorderStyleEnum> ranges = new Dictionary <string, BorderInformation.BorderStyleEnum>(); if (borderIsSet.Count == 1) { ranges.Add(borderIsSet.First().Key + "-" + columnCount, borderIsSet.First().Value); return(ranges); } for (int i = 0; i < borderIsSet.Count; i++) { if (borderIsSet.ElementAt(i).Value != BorderInformation.BorderStyleEnum.None) { if (i + 1 < borderIsSet.Count) { ranges.Add(borderIsSet.ElementAt(i).Key + "-" + (borderIsSet.ElementAt(i + 1).Key - 1), borderIsSet.ElementAt(i).Value); } else { ranges.Add(borderIsSet.ElementAt(i).Key + "-" + columnCount, borderIsSet.ElementAt(i).Value); } } } return(ranges); }
private static bool LastBorderDiffersFromActualBorder(Cell cell, Cell.BorderPositionEnum borderPosition, Dictionary <int, BorderInformation.BorderStyleEnum> borderIsSet) { return(cell.Borders[borderPosition].BorderStyle != BorderInformation.BorderStyleEnum.None && borderIsSet.Last().Value != cell.Borders[borderPosition].BorderStyle); }
private static bool BorderIsSetAndEmptyLastCellBorder(Cell cell, Cell.BorderPositionEnum borderPosition, Dictionary <int, BorderInformation.BorderStyleEnum> borderIsSet) { return(cell.Borders[borderPosition].BorderStyle != BorderInformation.BorderStyleEnum.None && borderIsSet.Last().Value == BorderInformation.BorderStyleEnum.None); }
private static bool BorderIsSetAndNoRangeAdded(Cell cell, Cell.BorderPositionEnum borderPosition, Dictionary <int, BorderInformation.BorderStyleEnum> borderIsSet) { return(cell.Borders[borderPosition].BorderStyle != BorderInformation.BorderStyleEnum.None && borderIsSet.Count == 0); }
private Dictionary <int, BorderInformation.BorderStyleEnum> GetBorderSet(Row row, Cell.BorderPositionEnum borderPosition) { Dictionary <int, BorderInformation.BorderStyleEnum> borderIsSet = new Dictionary <int, BorderInformation.BorderStyleEnum>(); int i = 1; foreach (var cell in row.Columns) { if (BorderIsSetAndNoRangeAdded(cell, borderPosition, borderIsSet) || BorderNotSetAndAndNonEmptyLastCellBorder(cell, borderPosition, borderIsSet) || BorderIsSetAndEmptyLastCellBorder(cell, borderPosition, borderIsSet) || LastBorderDiffersFromActualBorder(cell, borderPosition, borderIsSet)) { borderIsSet.Add(i, cell.Borders[borderPosition].BorderStyle); } i++; } return(borderIsSet); }
private string GetHorizontalRule(Row row, Cell.BorderPositionEnum borderPosition) { return(GetRuleCommand(GetRuleRangesFromTo(row, borderPosition))); }
private static bool ContainsBorderStyle(IEnumerable <Cell> columns, Cell.BorderPositionEnum borderPosition, IEnumerable <BorderInformation.BorderStyleEnum> borderStyles) { return(columns.Any(x => borderStyles.Contains(x.Borders[borderPosition].BorderStyle))); }
private static Dictionary <Row, HorizontalRuleStyler> GetHorizontalRuleStyler(Row row, Cell.BorderPositionEnum borderPosition) { if (row.Columns.Count > 0) { var ruleStylers = new Dictionary <Row, HorizontalRuleStyler>(); var dottedStyles = new[] { BorderInformation.BorderStyleEnum.Dotted }; var dottedPreparedRow = GetPreparedRow(row.Clone(), borderPosition, dottedStyles); if (ContainsBorderStyle(dottedPreparedRow.Columns, borderPosition, dottedStyles)) { ruleStylers.Add(dottedPreparedRow, new DottedRuleStyler()); } var dashedStyles = new[] { BorderInformation.BorderStyleEnum.Dashed }; var dashedPreparedRow = GetPreparedRow(row.Clone(), borderPosition, dashedStyles); if (ContainsBorderStyle(dashedPreparedRow.Columns, borderPosition, dashedStyles)) { ruleStylers.Add(dashedPreparedRow, new DashedRuleStyler()); } var solidStyles = new[] { BorderInformation.BorderStyleEnum.Solid, BorderInformation.BorderStyleEnum.DoubleLineSolid }; var solidPreparedRow = GetPreparedRow(row.Clone(), borderPosition, solidStyles); if (ContainsBorderStyle(solidPreparedRow.Columns, borderPosition, solidStyles)) { ruleStylers.Add(solidPreparedRow, new SolidRuleStyler()); } return(ruleStylers); } throw new ArgumentException("specified row has no columns"); }