-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Dictionaries with attributes in LoadFromCollection #969
Labels
enhancement
New feature or request
Comments
So what you showed would not work as that's compile time. The set of keys for the |
Here's a better example of what I'm doing: var headers = new List<string> { "Barcode", "Current Org Level 3", "Current Org Level 4", "Current Org Level 5" };
headers.AddRange(data.Dates); // <=- This is a sorted list of date strings that are dynamically generated.
for (var i = 0; i < headers.Count; i++) {
var column = i + 1;
ws.Cells[1, column].Value = headers[i];
ws.Cells[1, column].Style.Font.Bold = true;
}
var row = 2;
foreach (var (barcode, value) in data.Entries) {
var column = 1;
var range = ws.Cells[row, column++];
range.Value = barcode;
range.Style.Font.Bold = true;
ws.Cells[row, column++].Value = value.ThreeName;
ws.Cells[row, column++].Value = value.FourName;
ws.Cells[row, column++].Value = value.FiveName;
// This is a Dictionary<string, int> where keys will be from the date list above.
// 👇
foreach (var date in data.Dates) {
try {
if (value.Values.TryGetValue(date, out var result) is false)
continue;
ws.Cells[row, column].Value = result;
} finally {
column++;
}
}
row++;
} |
Thanks, let's see if I understand this correctly:
|
Exactly.
From: Mats Alm ***@***.***>
Sent: Tuesday, August 8, 2023 7:00 AM
To: EPPlusSoftware/EPPlus ***@***.***>
Cc: Grosch, Scott ***@***.***>; Manual ***@***.***>
Subject: Re: [EPPlusSoftware/EPPlus] Support for Dictionaries with attributes in LoadFromCollection (Issue #969)
Thanks, let's see if I understand this correctly:
1. We need a new type of attribute that should have a property/member that defines the headers in the order they should appear as columns in the spreadsheet (corresponding to your headers variable above).
2. This attribute should only be used on properties that are of the Dictionary<string,*> type. If used on another type of member an exception will be thrown when LoadFromCollection is called.
3. When loading the data into the range we use the value returned by each key if present in the Dictionary.
4. The result will be that cells that corresponds to a key that wasn't present in the Dictionary will be empty or contain the value returned if the key was present in the Dictionary.
—
Reply to this email directly, view it on GitHub<#969 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AUN5BJGGIVCTO4SZ5VU4W2TXUJA67ANCNFSM6AAAAAA2KJKDCE>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.******@***.***>>
|
swmal
added a commit
that referenced
this issue
Nov 9, 2023
swmal
added a commit
that referenced
this issue
Nov 22, 2023
swmal
added a commit
that referenced
this issue
Nov 22, 2023
JanKallman
pushed a commit
that referenced
this issue
Nov 22, 2023
* #969, #1058 - implemented EPPlusDictionaryColumnAttribute for LoadFromCollection with attributes * #969, #1058 - added support for Dictionary property in LoadFromCollection * #1058, #969 - LoadFromCollection, support for Dictionary property * #1058, #969 - added testclass * #1058, #969 - added unit test for reading column headers/keys from attribute
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Via the attributes we could define a set of keys that should/could be present in a dictionary on each object in the list. Each key will become a column in the order they are defined.
Could look something like this:
Complex types as the value of the dictionary could be supported following the logic of nested classes.
The text was updated successfully, but these errors were encountered: