76 lines
2.5 KiB
C#
76 lines
2.5 KiB
C#
using NotVisualComponent.Helpers;
|
|
using NotVisualComponent.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NotVisualComponent
|
|
{
|
|
public partial class ExcelHardTable : Component
|
|
{
|
|
public ExcelHardTable()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public ExcelHardTable(IContainer container)
|
|
{
|
|
container.Add(this);
|
|
InitializeComponent();
|
|
}
|
|
public void CreateDoc<T>(TableWithHeaderConfig<T> config)
|
|
{
|
|
string NullReplace = "null";
|
|
config.CheckFields();
|
|
config.ColumnsRowsDataCount = (config.ColumnsRowsWidth.Count, config.Data.Count + 1);
|
|
IContext creator = new WorkWithExcel();
|
|
creator.CreateHeader(config.Header);
|
|
creator.CreateTableWithHeader();
|
|
creator.CreateMultiHeader(config);
|
|
|
|
var array = new string[config.Data.Count, config.Headers.Count];
|
|
|
|
for (var j = 0; j < config.Data.Count; j++)
|
|
{
|
|
for (var i = 0; i < config.Headers.Count; i++)
|
|
{
|
|
(int, int, string, string) first = (0, 0, null, null);
|
|
foreach (var x in config.Headers.Where(x => x.ColumnIndex == i))
|
|
{
|
|
first = x;
|
|
break;
|
|
}
|
|
|
|
var (_, _, _, name) = first;
|
|
if (name != null)
|
|
{
|
|
var propertyInfo = config.Data[j]?.GetType().GetProperty(name);
|
|
if (propertyInfo != null)
|
|
{
|
|
object? value = propertyInfo.GetValue(config.Data[j], null);
|
|
array[j, i] = value == null
|
|
? NullReplace
|
|
: value.ToString();
|
|
}
|
|
else
|
|
{
|
|
array[j, i] = NullReplace;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
array[j, i] = NullReplace;
|
|
}
|
|
}
|
|
}
|
|
|
|
creator.LoadDataToTableWithMultiHeader(array, config.ColumnsRowsWidth[1].Row);
|
|
creator.SaveDoc(config.FilePath);
|
|
}
|
|
}
|
|
}
|