DataTable: Add Subtitle

This commit is contained in:
2024-03-24 13:50:20 +01:00
parent e435e5da8d
commit 9d80c5913f
2 changed files with 13 additions and 4 deletions

View File

@ -20,7 +20,7 @@ namespace Elwig.Helpers.Export {
FileName = filename;
File.Delete(filename);
ZipArchive = ZipFile.Open(FileName, ZipArchiveMode.Create);
_tables = new();
_tables = [];
}
public void Dispose() {
@ -101,7 +101,12 @@ namespace Elwig.Helpers.Export {
<style:style style:name="header" style:family="table-cell" style:parent-style-name="default">
<style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/>
<style:paragraph-properties fo:text-align="center"/>
<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" fo:font-size="16pt"/>
<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" fo:font-size="16pt"/>
</style:style>
<style:style style:name="subheader" style:family="table-cell" style:parent-style-name="default">
<style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/>
<style:paragraph-properties fo:text-align="center"/>
<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
</style:style>
<style:style style:name="th" style:family="table-cell" style:parent-style-name="default">
<style:table-cell-properties style:text-align-source="fix" style:repeat-content="false" style:vertical-align="middle"/>
@ -198,6 +203,9 @@ namespace Elwig.Helpers.Export {
FormatCell(table.FullName, colSpan: totalSpan, style: "header") +
$" </table:table-row>\r\n" +
$" <table:table-row>\r\n" +
FormatCell(table.Subtitle, colSpan: totalSpan, style: "subheader") +
$" </table:table-row>\r\n" +
$" <table:table-row>\r\n" +
$" <table:table-cell table:number-columns-repeated=\"{totalSpan}\"/>\r\n" +
$" </table:table-row>\r\n" +
$" <table:table-row>\r\n");
@ -251,8 +259,8 @@ namespace Elwig.Helpers.Export {
protected static string FormatCell(object? data, int rowSpan = 1, int colSpan = 1, string? style = "default", bool isCovered = false, string?[]? units = null) {
if (data?.GetType().IsValueType == true && data.GetType().Name.StartsWith("ValueTuple"))
return string.Join("", data.GetType().GetFields().Zip(units ?? Array.Empty<string?>())
.Select(p => FormatCell(p.First.GetValue(data), rowSpan, colSpan, style, isCovered, new[] { p.Second }))
return string.Join("", data.GetType().GetFields().Zip(units ?? [])
.Select(p => FormatCell(p.First.GetValue(data), rowSpan, colSpan, style, isCovered, [p.Second]))
);
var add = (style != null ? $" table:style-name=\"{style}\"" : "") + (rowSpan > 1 || colSpan > 1 ? $" table:number-rows-spanned=\"{rowSpan}\" table:number-columns-spanned=\"{colSpan}\"" : "");

View File

@ -8,6 +8,7 @@ namespace Elwig.Models.Dtos {
public string Name { get; set; }
public string FullName { get; set; }
public string? Subtitle { get; set; }
public IEnumerable<T> Rows { get; private set; }
public int RowNum => Rows.Count();
public int ColNum => ColumnNames.Count();