Mustafa El-assi
Mustafa El-assi

Reputation: 53

Combination of vertical and horizontal table in closedxml.report

I am working on a project and I’m using ClosedXML to document some results in an Excel sheet.

I have the following data structure:

Class Diagramm Switch class

The PortTag Dictionary is just a Key Value Pair of Port Id and Tag (either “T”, “U”, “F” or “-“) This should result in a Table that looks like this:

Table as needed

This is the combination of a vertical and a horizontal version and I’m failing to create it.

My current sheet displays information I polled off of a switch with SNMP and looks as follows:

current sheet

Is there any help you can offer me or direct me to a source of knowledge regarding this problem?

I already read the information on the Github Wiki and the Website (https://closedxml.github.io/ClosedXML.Report/docs/en/)

thank you very much !

Upvotes: 1

Views: 1904

Answers (1)

Aleksei
Aleksei

Reputation: 591

I. If all Vlan entries have the same set of keys

You can use this approach:

  1. Define a vertical table Vlans
  2. Define a horizontal table PortTag_Values inside
  3. Define another horizontal table PortTagKeys where the keys should be placed

enter image description here

  1. In code, add data as one variable and PortTagKeys as another (note that I ommit checks for null and empty collection for simplicity):
var template = new XLTemplate(workbook);
template.AddVariable(data);
template.AddVariable("PortTagKeys", data.Vlans[0].PortTag.Keys);
template.Generate();
  1. Get what you wanted: enter image description here

II. If Vlan entries may have different sets of keys

In this case, I would suggest performing a pre-processing to get a collection of all keys and to fill all PortTags with the same keys (putting - for missing keys). I doubt it is possible to do in "pure" ClosedXML.Report, without pre-processing.

Upvotes: 2

Related Questions