тут надо пофиксить таблицу...
This commit is contained in:
parent
34bf359bc0
commit
334111d632
@ -31,11 +31,11 @@ namespace Components.NonVisualComponents
|
|||||||
throw new ArgumentException("Не заданы все данные");
|
throw new ArgumentException("Не заданы все данные");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
foreach (var columnDefenition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(columnDefinition.PropertyName))
|
if (string.IsNullOrEmpty(columnDefenition.PropertyName))
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Не задано свойство столбца: {columnDefinition.Header}");
|
throw new ArgumentException($"Не задано свойство столбца: {columnDefenition.Header}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,13 +52,13 @@ namespace Components.NonVisualComponents
|
|||||||
Table table = builder.StartTable();
|
Table table = builder.StartTable();
|
||||||
|
|
||||||
|
|
||||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
foreach (var columnDefenition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
builder.InsertCell();
|
builder.InsertCell();
|
||||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Weight);
|
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefenition.Weight);
|
||||||
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
||||||
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
|
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
|
||||||
builder.Write(columnDefinition.Header);
|
builder.Write(columnDefenition.Header);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var mergedColumn in bigTable.MergedColumns)
|
foreach (var mergedColumn in bigTable.MergedColumns)
|
||||||
@ -82,25 +82,25 @@ namespace Components.NonVisualComponents
|
|||||||
}
|
}
|
||||||
builder.EndRow();
|
builder.EndRow();
|
||||||
|
|
||||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
foreach (var columnDefenition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
builder.InsertCell();
|
builder.InsertCell();
|
||||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition2.Weight);
|
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefenition.Weight);
|
||||||
builder.Write(columnDefinition2.Header);
|
builder.Write(columnDefenition.Header);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.EndRow();
|
builder.EndRow();
|
||||||
|
|
||||||
int columnIndex;
|
int columnIndex;
|
||||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
foreach (var columnDefinition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
string currentPropertyName = columnDefinition.PropertyName;
|
string currentHeader = columnDefinition.Header;
|
||||||
columnIndex = 0;
|
columnIndex = 0;
|
||||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
foreach (var columnDefenition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
string currentPropertyName1 = columnDefinition2.PropertyName;
|
string currentHeader1 = columnDefenition.Header;
|
||||||
|
|
||||||
if (currentPropertyName == currentPropertyName1)
|
if (currentHeader == currentHeader1)
|
||||||
{
|
{
|
||||||
table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First;
|
table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First;
|
||||||
table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous;
|
table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous;
|
||||||
@ -112,11 +112,11 @@ namespace Components.NonVisualComponents
|
|||||||
|
|
||||||
foreach (var item in bigTable.Data)
|
foreach (var item in bigTable.Data)
|
||||||
{
|
{
|
||||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
foreach (var columnDefenition in bigTable.ColumnDefenitions)
|
||||||
{
|
{
|
||||||
builder.InsertCell();
|
builder.InsertCell();
|
||||||
var propertyValue = item.GetType()
|
var propertyValue = item.GetType()
|
||||||
.GetProperty(columnDefinition2.PropertyName)?
|
.GetProperty(columnDefenition.PropertyName)?
|
||||||
.GetValue(item)?.ToString();
|
.GetValue(item)?.ToString();
|
||||||
|
|
||||||
builder.Write(propertyValue ?? "");
|
builder.Write(propertyValue ?? "");
|
||||||
|
@ -12,20 +12,20 @@ namespace Components.SupportClasses
|
|||||||
|
|
||||||
public string DocumentTitle = string.Empty;
|
public string DocumentTitle = string.Empty;
|
||||||
|
|
||||||
public List<ColumnDefinition> ColumnDefinitions;
|
public List<string> Header;
|
||||||
public List<ColumnDefinition> ColumnDefinitions2;
|
public List<ColumnDefenitions> ColumnDefenitions;
|
||||||
|
|
||||||
public List<T> Data;
|
public List<T> Data;
|
||||||
|
|
||||||
public List<int[]> MergedColumns;
|
public List<int[]> MergedColumns;
|
||||||
public BigTable(string filePath, string documentTitle, List<ColumnDefinition> columnDefinitions, List<ColumnDefinition> columnDefinitions2, List<T> data, List<int[]> mergedColumns)
|
public BigTable(string filePath, string documentTitle, List<string> header, List<ColumnDefenitions> columnDefenitions, List<T> data, List<int[]> mergedColumns)
|
||||||
{
|
{
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
DocumentTitle = documentTitle;
|
DocumentTitle = documentTitle;
|
||||||
ColumnDefinitions = columnDefinitions;
|
Header = header;
|
||||||
Data = data;
|
Data = data;
|
||||||
MergedColumns = mergedColumns;
|
MergedColumns = mergedColumns;
|
||||||
ColumnDefinitions2 = columnDefinitions2;
|
ColumnDefenitions = columnDefenitions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Components.SupportClasses
|
namespace Components.SupportClasses
|
||||||
{
|
{
|
||||||
public class ColumnDefinition
|
public class ColumnDefenitions
|
||||||
{
|
{
|
||||||
public string Header;
|
public string Header;
|
||||||
public string PropertyName;
|
public string PropertyName;
|
@ -58,21 +58,20 @@ namespace WinForms
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<ColumnDefinition> columnDefinitions = new List<ColumnDefinition>
|
List<string> header = new List<string>
|
||||||
{
|
{
|
||||||
new ColumnDefinition { Header = "Работа", PropertyName = "Work", Weight = 35 },
|
"Работа",
|
||||||
new ColumnDefinition { Header = "", PropertyName = "Education1", Weight = 35 },
|
"",
|
||||||
new ColumnDefinition { Header = "", PropertyName = "Education2", Weight = 10 },
|
"",
|
||||||
new ColumnDefinition { Header = "Фамилия", PropertyName = "LastName", Weight = 20 }
|
"Фамилия"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
List<ColumnDefinition> columnDefinitions2 = new List<ColumnDefinition>
|
List<ColumnDefenitions> columnDefenitions = new List<ColumnDefenitions>
|
||||||
{
|
{
|
||||||
new ColumnDefinition { Header = "Возраст", PropertyName = "Age", Weight = 20 },
|
new ColumnDefenitions { Header = "Возраст", PropertyName = "Age", Weight = 20 },
|
||||||
new ColumnDefinition { Header = "Опыт", PropertyName = "Experience", Weight = 20 },
|
new ColumnDefenitions { Header = "Опыт", PropertyName = "Experience", Weight = 20 },
|
||||||
new ColumnDefinition { Header = "Должность", PropertyName = "Position", Weight = 20 },
|
new ColumnDefenitions { Header = "Должность", PropertyName = "Position", Weight = 20 },
|
||||||
new ColumnDefinition { Header = "Фамилия", PropertyName = "LastName", Weight = 20 }
|
new ColumnDefenitions { Header = "Фамилия", PropertyName = "LastName", Weight = 20 }
|
||||||
};
|
};
|
||||||
|
|
||||||
List<Worker> data = new List<Worker>
|
List<Worker> data = new List<Worker>
|
||||||
@ -92,7 +91,7 @@ namespace WinForms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BigTable<Worker> bigTable = new(dialog.FileName, "Задание 2", columnDefinitions, columnDefinitions2, data, mergedColumns);
|
BigTable<Worker> bigTable = new(dialog.FileName, "Задание 2", header, columnDefenitions, data, mergedColumns);
|
||||||
wordTable.CreateTable(bigTable);
|
wordTable.CreateTable(bigTable);
|
||||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user