MSOfficeTemplateReport 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MSOfficeTemplateReport --version 2.0.0
                    
NuGet\Install-Package MSOfficeTemplateReport -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSOfficeTemplateReport" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MSOfficeTemplateReport" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MSOfficeTemplateReport" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MSOfficeTemplateReport --version 2.0.0
                    
#r "nuget: MSOfficeTemplateReport, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MSOfficeTemplateReport@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MSOfficeTemplateReport&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MSOfficeTemplateReport&version=2.0.0
                    
Install as a Cake Tool

Генерация отчетов по шаблонам EXCEL и WORD

ПРАВИЛА ФОРМИРОВАНИЯ ШАБЛОНОВ

Правила формирования шаблона Word

Тэги, за исключением тэгов в табличной части (которая заполняется из коллекций), состоят из пары {{Ключ.Значение}}, где ключ - key элемента переданной в Dictionary<string, object>, а значение - это наименование поля объекта.

<img width="1349" height="384" alt="wordtemplate" src="https://github.com/user-attachments/assets/849bc2ee-4e0b-42e5-bb2c-0c3ebe93c78e" />

Тэги в табличной части (которая заполняеися из коллекций) имеют следующую структуру {{Item.Value}}, где "Item" - это обязателное слово, а 'Value' - это имя поля из элемента коллекции. Для таблиц, тек же, необходимым условием является задание в свойствах таблицы заголовка замещающего текста который должен совпадать с наименованием поля с коллекцией в объекте или, если коллекция была передана как отдельная переменная, псевданиму данной переменной.

<img width="386" height="449" alt="wordtemplatetablesettings" src="https://github.com/user-attachments/assets/34fcbb96-f174-4d46-90f4-625c6d553602" />

Правила формирования шаблона Excel

Оформление тэгов в шаблонах Excel аналогично Word за исключением наличия специальных тэгов: <<Sum>> - Выводит сумму значений колонки <<RowNumber>> - Нумерует строки

<img width="1181" height="314" alt="exceltemplate" src="https://github.com/user-attachments/assets/27dd2d40-f264-4788-857f-3f1891e36869" />

Для таблиц в Excel, которые заполняются из коллекций, необходимо создавать именованный диапазон ячеек который должен состоять из двухстрок.

<img width="1177" height="160" alt="excelnamedarray" src="https://github.com/user-attachments/assets/8ee5b4db-28e5-4c53-b464-f97769562420" />

<img width="559" height="446" alt="exceltemplatetablesettings" src="https://github.com/user-attachments/assets/305faf8c-949d-4d9a-90fe-7c1a42777086" />

<hr>

ПРИМЕР КОНСОЛЬНОГО ПРИЛОЖЕНИЯ НА С#

Для выполнения примера необходимо в корень проекта добавить файлы шаблонов по ссылкам выше и в свойствах файла в VisualStudio выставить параметры - действе при сборке - содержание, копировать в выходной каталог - копировать более позднюю версию.

  • класс Order.cs
internal class Order
{
    public int Number { get; set; }

    public string Date { get; set; }

    public string Customer { get; set; }

    public decimal Sum => Positions.Sum(x => x.Sum);

    public string SumString => Sum.ToString("N2");

    public List<OrderPosition> Positions { get; set; }
}
  • класс OrderPosition.cs
internal class OrderPosition
{
    public int RowNumber { get; set; }
    
    public string Name { get; set; }
    
    public int Amount { get; set; }
    
    public decimal Price { get; set; }

    public decimal Sum => Amount * Price;

    public string PriceString => Price.ToString("N2");

    public string SumString => Sum.ToString("N2");
}
  • класс Program.cs
using MSOfficeTemplateReport;
using TestProject;

const string wordTemplatePath = "testwordtemplate.docx";

var template = Template.Create(wordTemplatePath);

template.AddVariable("Order", new Order());

var result = template.Generate();

result.SaveAs("result.xlsx");
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 79 3/18/2026
2.0.0 79 3/18/2026
1.0.12 103 1/19/2026
1.0.11 98 1/19/2026
1.0.10 98 1/16/2026
1.0.9 102 1/16/2026
1.0.8 101 1/16/2026
1.0.7 103 1/15/2026
1.0.6 105 1/15/2026
1.0.5 489 5/14/2024
1.0.4 186 5/1/2024
1.0.3 180 4/27/2024
1.0.2 187 4/27/2024
1.0.1 188 4/25/2024
1.0.0 181 4/25/2024

Данная версия не совместима с предыдущими. Читайте Redme