59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ReportGeneration.Abstract;
|
|
using ReportGeneration.Interface;
|
|
|
|
namespace ReportGeneration.Generators.LatexInclude;
|
|
|
|
public class LatexIncludeTableGenerator : TableGeneratorBase
|
|
{
|
|
private const string rowSuffix = @" \\ \hline";
|
|
|
|
public LatexIncludeTableGenerator(int columns) : base(columns)
|
|
{
|
|
}
|
|
|
|
public LatexIncludeTableGenerator(int columns, Stream stream) : base(columns, stream)
|
|
{
|
|
}
|
|
|
|
public LatexIncludeTableGenerator(int columns, Stream stream, Encoding encoding) : base(columns, stream, encoding)
|
|
{
|
|
}
|
|
|
|
protected override void OnOpen()
|
|
{
|
|
base.OnOpen();
|
|
var tabular = '|' + string.Concat(Enumerable.Repeat("l|", Columns));
|
|
|
|
WriteLine(@$"
|
|
\begin{{table}}[!ht]
|
|
\centering
|
|
\caption{{Caption}}
|
|
\begin{{tabular}}{{{tabular}}}
|
|
\hline");
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
base.OnClose();
|
|
WriteLine(@"
|
|
\end{{tabular}}
|
|
\end{{table}}");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override ITableGenerator AppendHeader(IEnumerable<string> row) => AppendRow(row.Select(Bold));
|
|
|
|
/// <inheritdoc />
|
|
public override ITableGenerator AppendRow(IEnumerable<string> row)
|
|
{
|
|
WriteLine(string.Join('&', row.Select(Escape)) + rowSuffix);
|
|
return this;
|
|
}
|
|
|
|
private string Bold(string str) => $@"\textbf{str}";
|
|
private string Escape(string str) => str.Replace("%", "\\%");
|
|
} |