@@ -100,10 +100,10 @@ public bool HeaderTextAlignmentRight
100100 }
101101 }
102102
103+ private bool _rowTextAlignmentRight ;
103104 /// <summary>
104105 /// Gets or sets a value indicating whether the row text is aligned to the right or left
105106 /// </summary>
106- private bool _rowTextAlignmentRight ;
107107 public bool RowTextAlignmentRight
108108 {
109109 get => _rowTextAlignmentRight ;
@@ -114,10 +114,10 @@ public bool RowTextAlignmentRight
114114 }
115115 }
116116
117+ private bool _footerTextAlignmentRight ;
117118 /// <summary>
118119 /// Gets or sets a value indicating whether the footer text is aligned to the right or left
119120 /// </summary>
120- private bool _footerTextAlignmentRight ;
121121 public bool FooterTextAlignmentRight
122122 {
123123 get => _footerTextAlignmentRight ;
@@ -128,6 +128,20 @@ public bool FooterTextAlignmentRight
128128 }
129129 }
130130
131+ private bool _showBorders = true ;
132+ /// <summary>
133+ /// Gets or sets a value indicating whether the table borders are visible. Default is true.
134+ /// </summary>
135+ public bool ShowBorders
136+ {
137+ get => _showBorders ;
138+ set
139+ {
140+ _showBorders = value ;
141+ ClearCache ( ) ;
142+ }
143+ }
144+
131145 /// <summary>
132146 /// Sets the headers of the table. Overwrites them each time.
133147 /// </summary>
@@ -194,8 +208,6 @@ public Table ClearRows()
194208 return this ;
195209 }
196210
197-
198-
199211 /// <summary>
200212 /// Clears the cached generated table string
201213 /// </summary>
@@ -238,28 +250,37 @@ public string ToTable()
238250
239251 if ( Headers ? . Any ( ) == true )
240252 {
241- formattedTable = CreateTopLine ( maximumCellWidths , Headers . Count ( ) , formattedTable ) ;
242- topLineCreated = true ;
253+ if ( ShowBorders )
254+ {
255+ formattedTable = CreateTopLine ( maximumCellWidths , Headers . Count ( ) , formattedTable ) ;
256+ topLineCreated = true ;
257+ }
243258
244- formattedTable = CreateValueLine ( maximumCellWidths , Headers , HeaderTextAlignmentRight , TableDrawing . VerticalLine , formattedTable ) ;
259+ formattedTable = CreateValueLine ( maximumCellWidths , Headers , HeaderTextAlignmentRight , ShowBorders ? TableDrawing . VerticalLine : TableDrawing . EmptySpace , formattedTable ) ;
245260
246261 previousRow = Headers ;
247262
248263 //When there are no rows immediatly draw the bottom line after the header
249264 if ( Rows ? . Any ( ) == true )
250265 {
251266 nextRow = Rows . First ( ) ;
252- formattedTable = CreateSeperatorLine ( maximumCellWidths , previousRow . Count ( ) , nextRow . Count ( ) , TableDrawing . HorizontalHeaderLine , formattedTable ) ;
267+ if ( ShowBorders )
268+ {
269+ formattedTable = CreateSeperatorLine ( maximumCellWidths , previousRow . Count ( ) , nextRow . Count ( ) , TableDrawing . HorizontalHeaderLine , formattedTable ) ;
270+ }
253271 }
254272 else
255273 {
256- formattedTable = CreateBottomLine ( maximumCellWidths , Headers . Count ( ) , TableDrawing . HorizontalHeaderLine , formattedTable ) ;
274+ if ( ShowBorders )
275+ {
276+ formattedTable = CreateBottomLine ( maximumCellWidths , Headers . Count ( ) , TableDrawing . HorizontalHeaderLine , formattedTable ) ;
277+ }
257278 }
258279 }
259280
260281 if ( Rows ? . Any ( ) == true )
261282 {
262- if ( ! topLineCreated )
283+ if ( ! topLineCreated && ShowBorders )
263284 {
264285 formattedTable = CreateTopLine ( maximumCellWidths , Rows . First ( ) . Count ( ) , formattedTable ) ;
265286 topLineCreated = true ;
@@ -272,21 +293,27 @@ public string ToTable()
272293 {
273294 var row = CleanupRow ( Rows [ i ] ) ;
274295
275- formattedTable = CreateValueLine ( maximumCellWidths , row , RowTextAlignmentRight , TableDrawing . VerticalLine , formattedTable ) ;
296+ formattedTable = CreateValueLine ( maximumCellWidths , row , RowTextAlignmentRight , ShowBorders ? TableDrawing . VerticalLine : TableDrawing . EmptySpace , formattedTable ) ;
276297
277298 previousRow = row ;
278299
279300 if ( rowIndex != lastRowIndex )
280301 {
281302 nextRow = CleanupRow ( Rows [ rowIndex + 1 ] ) ;
282303
283- formattedTable = CreateSeperatorLine ( maximumCellWidths , previousRow . Count ( ) , nextRow . Count ( ) , TableDrawing . HorizontalLine , formattedTable ) ;
304+ if ( ShowBorders )
305+ {
306+ formattedTable = CreateSeperatorLine ( maximumCellWidths , previousRow . Count ( ) , nextRow . Count ( ) , TableDrawing . HorizontalLine , formattedTable ) ;
307+ }
284308 }
285309
286310 rowIndex ++ ;
287311 }
288312
289- formattedTable = CreateBottomLine ( maximumCellWidths , previousRow . Count ( ) , TableDrawing . HorizontalLine , formattedTable ) ;
313+ if ( ShowBorders )
314+ {
315+ formattedTable = CreateBottomLine ( maximumCellWidths , previousRow . Count ( ) , TableDrawing . HorizontalLine , formattedTable ) ;
316+ }
290317 }
291318
292319 if ( Footers ? . Any ( ) == true )
@@ -411,22 +438,30 @@ private StringBuilder CreateValueLine(int[] maximumCellWidths, string[] row, boo
411438 if ( Padding > 0 )
412439 paddingString = string . Concat ( Enumerable . Repeat ( ' ' , Padding ) ) ;
413440
414- foreach ( var column in row )
441+ for ( int i = 0 ; i < row . Length ; i ++ )
415442 {
443+ var column = row [ i ] ;
444+
445+ var leftVerticalLine = verticalLine ;
446+ if ( i == 0 && ! ShowBorders )
447+ {
448+ leftVerticalLine = TableDrawing . Empty ;
449+ }
450+
416451 var restWidth = maximumCellWidths [ cellIndex ] ;
417452 if ( Padding > 0 )
418453 restWidth -= Padding * 2 ;
419454
420455 var cellValue = alignRight ? column . PadLeft ( restWidth , ' ' ) : column . PadRight ( restWidth , ' ' ) ;
421456
422457 if ( cellIndex == 0 && cellIndex == lastCellIndex )
423- formattedTable . AppendLine ( string . Format ( "{0}{1}{2}{3}{4}" , verticalLine , paddingString , cellValue , paddingString , verticalLine ) ) ;
458+ formattedTable . AppendLine ( string . Format ( "{0}{1}{2}{3}{4}" , leftVerticalLine , paddingString , cellValue , paddingString , verticalLine ) ) ;
424459 else if ( cellIndex == 0 )
425- formattedTable . Append ( string . Format ( "{0}{1}{2}{3}" , verticalLine , paddingString , cellValue , paddingString ) ) ;
460+ formattedTable . Append ( string . Format ( "{0}{1}{2}{3}" , leftVerticalLine , paddingString , cellValue , paddingString ) ) ;
426461 else if ( cellIndex == lastCellIndex )
427- formattedTable . AppendLine ( string . Format ( "{0}{1}{2}{3}{4}" , verticalLine , paddingString , cellValue , paddingString , verticalLine ) ) ;
462+ formattedTable . AppendLine ( string . Format ( "{0}{1}{2}{3}{4}" , leftVerticalLine , paddingString , cellValue , paddingString , verticalLine ) ) ;
428463 else
429- formattedTable . Append ( string . Format ( "{0}{1}{2}{3}" , verticalLine , paddingString , cellValue , paddingString ) ) ;
464+ formattedTable . Append ( string . Format ( "{0}{1}{2}{3}" , leftVerticalLine , paddingString , cellValue , paddingString ) ) ;
430465
431466 cellIndex ++ ;
432467 }
0 commit comments