Exemplo n.º 1
0
        private string RenderContentRow(Row row, IList <Column> columns)
        {
            var sb = new StringBuilder();

            // Left border
            if (_shownBorders.IsLeftBorderVisible)
            {
                sb.Append(BorderStyle.Left);
            }

            // Cells
            var totalColumns = columns.Count;
            var j            = 0;

            foreach (Cell cell in row.Cells)
            {
                // cell separator
                if (j != 0)
                {
                    if ((j > 1 && j < totalColumns - 1) &&
                        _shownBorders.IsCenterSeparatorVisible ||
                        ((j == 1) && (_shownBorders.IsLeftSeparatorVisible)) ||
                        ((j == (totalColumns - 1)) && (_shownBorders.IsRightSeparatorVisible)))
                    {
                        sb.Append(BorderStyle.Center);
                    }
                }

                // Cell content
                var sepWidth = BorderStyle.Center.Length;
                var width    = -sepWidth;
                for (var pos = j; pos < j + cell.ColumnSpan; pos++)
                {
                    width = width + sepWidth + columns[pos].Width;
                }

                var renderedCell = cell.Render(width);
                sb.Append(renderedCell);
                j = j + cell.ColumnSpan;
            }

            // Render missing cells
            for (; j < totalColumns; j++)
            {
                // cell separator
                if (j != 0)
                {
                    if ((j > 1 && j < totalColumns - 1) &&
                        _shownBorders.IsCenterSeparatorVisible ||
                        ((j == 1) && (_shownBorders.IsLeftSeparatorVisible)) ||
                        ((j == (totalColumns - 1)) && (_shownBorders.IsRightSeparatorVisible)))
                    {
                        sb.Append(BorderStyle.Center);
                    }
                }

                // Cell content
                var col          = columns[j];
                var renderedCell = CellStyle.RenderNullCell(col.Width);
                sb.Append(renderedCell);
            }

            // Right border
            if (_shownBorders.IsRightBorderVisible)
            {
                sb.Append(BorderStyle.Right);
            }

            return(sb.ToString());
        }