ClosedXML report - format of input list

386 views Asked by At

The format for sending data to a closedXML template is a bit confusing to me.

In the Flat tables docs there's a sample for a template with header info and data from a list for the report, but I don't see where the list is connected to the template.

I have a similar scenario - header info for the top, data in a list for the report.

I've tried defining an object with all the data in it:

public class AllocationExportData
{
    public List<AllocationExportItem> AllocationList { get; set; }
    public string Host_custname { get; set; }
    public string Host_custaddr { get; set; }

}

and setting up the template using those variables

enter image description here

But only the top two values are being found

enter image description here

I figure I'm naming something wrong, or setting up the object wrong.

Anyone?

1

There are 1 answers

0
Laurent Gabiot On

About Host_city, Host_state etc... you need to add equivalently named properties in your AllocationExportData class.

About the issues in the table "Credit Recipient Information":

The link between a table in the Excel template and a collection in code is indeed not explicitly described in the ClosedXML.Report Quick Start. Fortunalty the Flat Tables page of the official documentation gives the necessary explanations.

Basically: You need to create a named range in your Excel sheet. See naming cells and ranges in Excel

The name of that range must be the name of the property representing the collection you wish to display on this table. Its type must implement IEnumerable (again see the Flat Tables page).

In your case, you should name the range: AllocationList

Now you have to define what is the range you want to name. Since you want each element of your AllocationList to be stacked vertically (i.e. each one on a specific line, not displayed on the same line, each one at the right of the preceding one), you want to create what the documentation call a "vertical table".

The Flat Tables page states:

Each range specifying a vertical table must have at least two columns and two rows. The leftmost column and bottommost row serve to hold configuration information and are treated specially. After the report is built the service column is cleared, and the service row is deleted if it is empty.

In your case, the range should include all the cells with the error "Unknown identifier [...]", plus a second empty row below.