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 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");
        }
 public Row InitRowAllCellsDashed()
 {
     Row row = new Row(8);
       foreach (var cell in row.Columns)
       {
     cell.Borders = InitBorders();
     cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
     cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
       }
       return row;
 }
 private string GetHeaderSeparator(Row row)
 {
     var str = new StringBuilder();
       var spacesReplacementLength = 2;
       foreach (var cell in row.Columns)
       {
     str.Append(string.Format("{0}{1}", GetColumnSeparator(), new string('-', cell.Text.Length + spacesReplacementLength)));
       }
       str.Append(GetColumnSeparator());
       return str.ToString();
 }
        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;
        }
        public Row InitRowNoTopAndBottomBorderSet()
        {
            Row row = new Row(8);
              int i = 1;
              foreach (var cell in row.Columns)
              {
            cell.Borders = InitBorders();
            cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.None;
            cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.None;
            i++;
              }

              return row;
        }
        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;
        }
 public Row InitRowMixed()
 {
     Row row = new Row(6);
       var i = 1;
       foreach (var cell in row.Columns)
       {
     cell.Borders = InitBorders();
     if(i == 1 || i == 2)
       cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Dotted;
     if(i == 3)
       cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Solid;
     if(i == 4 || i == 5)
       cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
     if(i == 6)
       cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.DoubleLineSolid;
     i++;
       }
       return row;
 }
        public Row InitRowOnlyFirstCellDashed()
        {
            Row row = new Row(8);
              int i = 1;
              foreach (var cell in row.Columns)
              {
            cell.Borders = InitBorders();
            if (i == 1)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
            else
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.None;

            if (i == 1)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
            else
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.None;
            i++;
              }
              return row;
        }
        public Row InitRowTop34NotDashedBottom158NotDashed()
        {
            Row row = new Row(8);
              int i = 1;
              foreach (var cell in row.Columns)
              {
            cell.Borders = InitBorders();
            if (i != 3 && i != 4)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
            else
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.None;

            if (i != 1 && i != 5 && i != 8)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Dashed;
            else
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.None;
            i++;
              }

              return row;
        }
 private string AppendFullBorderConfig(Row row, bool useBottomRuleFromRow)
 {
     Dictionary<Row, HorizontalRuleStyler> horizontalRuleStylers;
       var fullBorders = new StringBuilder();
       if (useBottomRuleFromRow)
       {
     horizontalRuleStylers = HorizontalRuleStylerFactory.GetBottomHorizontalRuleStyler(row);
     foreach (var horizontalRuleStyler in horizontalRuleStylers)
     {
       fullBorders.Append(horizontalRuleStyler.Value.GetBottomHorizontalRule(horizontalRuleStyler.Key));
     }
       }
       else
       {
     horizontalRuleStylers = HorizontalRuleStylerFactory.GetTopHorizontalRuleStyler(row);
     foreach (var horizontalRuleStyler in horizontalRuleStylers)
     {
       fullBorders.Append(horizontalRuleStyler.Value.GetTopHorizontalRule(horizontalRuleStyler.Key));
     }
       }
       return fullBorders.ToString();
 }
        private string AppendHorizontalRuleIfSet(Row row, bool useBottomRuleFromRow, int rowCount, int totalRows)
        {
            if (_extendedFeatures.AddHlines)
              {
            return "\\hline";
              }

              if (_extendedFeatures.FullBorderConfig)
              {
            return AppendFullBorderConfig(row, useBottomRuleFromRow);
              }

              if (_extendedFeatures.HighQualityTable)
              {
            if(rowCount == 0)
              return "\\toprule";
            if (rowCount == 1)
              return "\\midrule";
            if (rowCount == totalRows)
              return "\\bottomrule";
              }

              return string.Empty;
        }
 private string GetHorizontalRule(Row row, Cell.BorderPositionEnum borderPosition)
 {
     return GetRuleCommand(GetRuleRangesFromTo(row, borderPosition));
 }
        private string AppendColumnDefinitions(Row firstRow)
        {
            var builder = new StringBuilder();

              if (_extendedFeatures.HighQualityTable)
              {
            builder.Append(GetColumnSpaceRemovalChars());
              }

              foreach (var cell in firstRow.Columns)
              {
            var justifier = JustifierFactory.GetJustifier(cell, _extendedFeatures.AutoJustify);
            builder.Append(justifier.GetAlignment());
            builder.Append(AppendVerticalBorders());
              }

              if (_extendedFeatures.HighQualityTable)
              {
            builder.Append(GetColumnSpaceRemovalChars());
              }

              return builder.ToString();
        }
 public override string GetTopHorizontalRule(Row row)
 {
     return GetHorizontalRule(row, Cell.BorderPositionEnum.Top);
 }
        public Row InitRowTopAndBottom12Double3None456Solid78None()
        {
            Row row = new Row(8);
              int i = 1;
              foreach (var cell in row.Columns)
              {
            cell.Borders = InitBorders();
            if (i ==1 || i == 2)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.DoubleLineSolid;
            else if(i == 4 || i == 5 || i == 6)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.Solid;
            else
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.None;

            if (i == 1 || i == 2)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.DoubleLineSolid;
            else if (i == 4 || i == 5 || i == 6)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Solid;
            else
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.None;
            i++;
              }

              return row;
        }
        public Row InitRowTopBottom12Solid3DoubleSolid()
        {
            Row row = new Row(3);
              int i = 1;
              foreach (var cell in row.Columns)
              {
            cell.Borders = InitBorders();
            if (i == 1 || i == 2)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.Solid;
            else if (i == 3)
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.DoubleLineSolid;
            else
              cell.Borders[Cell.BorderPositionEnum.Top].BorderStyle = BorderInformation.BorderStyleEnum.None;

            if (i == 1 || i == 2)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.Solid;
            else if (i == 3)
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.DoubleLineSolid;
            else
              cell.Borders[Cell.BorderPositionEnum.Bottom].BorderStyle = BorderInformation.BorderStyleEnum.None;
            i++;
              }

              return row;
        }
 private string AppendQuitLineAndAddHorizontalRuleIfSet(Row row, int rowCount, int totalRows)
 {
     return string.Format("\\\\{0}", AppendHorizontalRuleIfSet(row, true, rowCount, totalRows));
 }
 private string AppendTableContent(Table table, Row firstRow)
 {
     StringBuilder tableContent = new StringBuilder();
       var rowCount = 0;
       foreach (var row in table.Rows)
       {
     tableContent.Append(AppendRow(row, firstRow, ++rowCount, table.Rows.Count));
       }
       return tableContent.ToString();
 }
 private StringBuilder AppendRow(Row actualRow, Row firstRow, int rowCount, int totalRows)
 {
     StringBuilder rowContent = new StringBuilder();
       var cells = actualRow.Columns as IList<Cell> ?? actualRow.Columns.ToList();
       for (int i = 0; i < cells.Count(); i++)
       {
     var preparedValue = PrepareCellValue(cells[i], firstRow.Columns[i]);
     rowContent.Append(AppendValueWithCellSeperator(preparedValue));
       }
       rowContent = RemoveLastCellSeperator(rowContent);
       rowContent.Append(AppendQuitLineAndAddHorizontalRuleIfSet(actualRow, rowCount, totalRows));
       rowContent.Append(AppendNewLine());
       return rowContent;
 }
 public abstract string GetBottomHorizontalRule(Row row);
 public abstract string GetTopHorizontalRule(Row row);
 public static Dictionary<Row, HorizontalRuleStyler> GetTopHorizontalRuleStyler(Row row)
 {
     return GetHorizontalRuleStyler(row, Cell.BorderPositionEnum.Top);
 }