доработки по ворду

This commit is contained in:
Мк Игорь 2023-05-09 18:53:32 +04:00
parent b2a5ea6274
commit 503c88533b
2 changed files with 74 additions and 22 deletions

View File

@ -37,7 +37,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
}
});
}
SaveWord(info);
SaveWord(info);
}
public void CreateDocStores(WordInfo info)
{
@ -54,25 +54,39 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Center
}
});
foreach (var store in info.Stores)
//foreach (var store in info.Stores)
//{
// CreateParagraph(new WordParagraph
// {
// Texts = new List<(string, WordTextProperties)>
// {
// (store.StoreName, new WordTextProperties { Bold = true, Size = "24", }),
// (" ", new WordTextProperties { Size = "24"}),
// (store.Address, new WordTextProperties { Size = "24" }),
// (" ", new WordTextProperties { Size = "24"}),
// (store.OpeningDate.ToShortDateString(), new WordTextProperties { Size = "24" })
// },
// TextProperties = new WordTextProperties
// {
// Size = "24",
// JustificationType = WordJustificationType.Both
// }
// });
//}
CreateTable(new()
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(store.StoreName, new WordTextProperties { Bold = true, Size = "24", }),
(" ", new WordTextProperties { Size = "24"}),
(store.Address, new WordTextProperties { Size = "24" }),
(" ", new WordTextProperties { Size = "24"}),
(store.OpeningDate.ToShortDateString(), new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
("Название", 3000),
("Дата", null),
("Адрес открытия", 4500),
},
info.Stores
.Select(x => new List<string>
{
x.StoreName,
Convert.ToString(x.OpeningDate.ToShortDateString),
x.Address,
})
.ToList());
SaveWord(info);
}
/// <summary>
@ -91,6 +105,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfo info);
}
protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows);
}
}

View File

@ -117,5 +117,43 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.Implements
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close();
}
}
private static TableCell GetTableCell(string text, int? widthCell = null)
{
TableCell cell = new(new Paragraph(new Run(new Text(text))));
if (widthCell != null)
{
cell.Append(new TableCellProperties()
{
TableCellWidth = new() { Width = widthCell.ToString() }
});
}
return cell;
}
protected override void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows)
{
if (_docBody == null)
{
return;
}
Table table = new();
TableProperties tblProp = new TableProperties(
new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 }
)
);
table.AppendChild(tblProp);
table.Append(new TableRow(nameAndWidthColumns.Select(x => GetTableCell(x.Item1, x.Item2))));
table.Append(rows.Select(x => new TableRow(x.Select(y => GetTableCell(y)))));
_docBody.Append(table);
}
}
}