Ods: Fix small issues
This commit is contained in:
@ -161,13 +161,12 @@ namespace Elwig.Helpers.Export {
|
||||
public async Task AddTable<T>(DataTable<T> table) {
|
||||
if (Content == null) await AddHeader();
|
||||
if (Content == null) return;
|
||||
var totalSpan = table.ColumnSpans.Sum(s => s.Item2);
|
||||
var totalSpan = table.ColumnSpans.Sum();
|
||||
|
||||
_tables.Add(table.FullName);
|
||||
|
||||
await Content.WriteAsync($" <table:table table:name=\"{table.FullName}\" table:default-cell-style-name=\"default\">\r\n");
|
||||
await Content.WriteAsync(
|
||||
$" <table:table table:name=\"{table.FullName}\">\r\n" +
|
||||
$" <table:table-column table:default-cell-style-name=\"default\"/>\r\n" +
|
||||
$" <table:table-row>\r\n" +
|
||||
FormatCell(table.FullName, colSpan: totalSpan, style: "header") +
|
||||
$" </table:table-row>\r\n" +
|
||||
@ -175,7 +174,7 @@ namespace Elwig.Helpers.Export {
|
||||
$" <table:table-cell table:number-columns-repeated=\"{totalSpan}\"/>\r\n" +
|
||||
$" </table:table-row>\r\n" +
|
||||
$" <table:table-row>\r\n");
|
||||
foreach (var (name, span) in table.ColumnSpans) {
|
||||
foreach (var (name, span) in table.ColumnNames.Zip(table.ColumnSpans)) {
|
||||
await Content.WriteAsync(FormatCell(name, colSpan: span, style: "th"));
|
||||
}
|
||||
await Content.WriteAsync(" </table:table-row>\r\n");
|
||||
@ -219,7 +218,7 @@ namespace Elwig.Helpers.Export {
|
||||
c = $"<table:table-cell office:value-type=\"string\"{add}><text:p>{data}</text:p></table:table-cell>";
|
||||
}
|
||||
|
||||
return c = $" {c}\r\n" + (colSpan > 1 ? $" <table:covered-table-cell table:number-rows-repeated=\"{colSpan - 1}\"/>\r\n" : "");
|
||||
return $" {c}\r\n" + (colSpan > 1 ? $" <table:covered-table-cell table:number-rows-repeated=\"{colSpan - 1}\"/>\r\n" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,18 +10,14 @@ namespace Elwig.Models.Dtos {
|
||||
public string FullName { get; set; }
|
||||
public IEnumerable<T> Rows { get; private set; }
|
||||
public int RowNum => Rows.Count();
|
||||
public int ColNum => ColumnNames.Count();
|
||||
|
||||
public IEnumerable<(string, Type?)> ColumnDefs => _map.Select(m => (m.Item1, m.Item2?.PropertyType ?? m.Item3?.FieldType));
|
||||
public IEnumerable<string> ColumnNames => ColumnDefs.Select(m => m.Item1);
|
||||
public IEnumerable<Type?> ColumnTypes => ColumnDefs.Select(m => m.Item2);
|
||||
public IEnumerable<(string, int)> ColumnSpans => ColumnDefs.Select(c => {
|
||||
var type = c.Item2;
|
||||
var elType = type?.GetElementType();
|
||||
return (c.Item1,
|
||||
type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Length :
|
||||
type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Length : 1
|
||||
);
|
||||
}).ToList();
|
||||
public int ColNum => ColumnNames.Count();
|
||||
public IEnumerable<Type?> ColumnFlatTypes { get; private set; }
|
||||
public IEnumerable<int> ColumnSpans { get; private set; }
|
||||
|
||||
private readonly PropertyInfo[] _properties;
|
||||
private readonly FieldInfo[] _fields;
|
||||
private readonly (string, PropertyInfo?, FieldInfo?)[] _map;
|
||||
@ -34,6 +30,17 @@ namespace Elwig.Models.Dtos {
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
Rows = rows;
|
||||
ColumnFlatTypes = ColumnTypes.SelectMany(type => {
|
||||
var elType = type?.GetElementType();
|
||||
return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Select(f => f.FieldType) :
|
||||
type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Select(f => f.FieldType) :
|
||||
new Type?[] { type };
|
||||
}).ToList();
|
||||
ColumnSpans = ColumnTypes.Select(type => {
|
||||
var elType = type?.GetElementType();
|
||||
return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Length :
|
||||
type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Length : 1;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string)>? colNames = null) :
|
||||
|
Reference in New Issue
Block a user