Skip to content
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

Unable to fill dynamic tags in row #713

Open
darkblueapi opened this issue Jan 20, 2025 · 0 comments
Open

Unable to fill dynamic tags in row #713

darkblueapi opened this issue Jan 20, 2025 · 0 comments

Comments

@darkblueapi
Copy link

Goal - fill columns created dynamically. I can not use class with pre-created fields because in my case tags have to be found first.

Expectations:

excel:
{{model.name}} {{manufacturer.name}}

after processing:
A1 B1
A2 B2
A3 B3
A4 B4

Reality:

code:

      var value = new Dictionary<string, object>
            {
                ["model"] = new[]
                {
                    new { name = "A1" },
                    new { name = "A2" },
                    new { name = "A3" },
                    new { name = "A4" }
                },
                
                ["manufacturer"] = new[]
                {
                    new { name = "B1" },
                    new { name = "B2" },
                    new { name = "B3" },
                    new { name = "B4" },
                },
                
            };

excel:
{{model.name}} {{manufacturer.name}}

Result
B1 {{manufacturer.name}}
B2 {{manufacturer.name}}
B3 {{manufacturer.name}}
B4 {{manufacturer.name}}


Another approach through multiple SaveAsByTemplateAsync()

code:

 MemoryStream memoryStream = new MemoryStream(0);
           
           memoryStream.Write(bytes, 0, bytes.Length);
           
           var value = new Dictionary<string, object>
           {
               ["model"] = new[]
               {
                   new { name = "A1" },
                   new { name = "A2" },
                   new { name = "A3" },
                   new { name = "A4" }
               },

           };
           
           byte[] copiedData = memoryStream.ToArray();
           await memoryStream.SaveAsByTemplateAsync(copiedData, value);
           
           
           memoryStream.Position = 0;
           MemoryStream clonedStream = new MemoryStream();
           await memoryStream.CopyToAsync(clonedStream);
           clonedStream.Position = 0;

           await memoryStream.DisposeAsync();

           byte[] copiedData1 = clonedStream.ToArray();
           
           var value1 = new Dictionary<string, object>
           {
               ["manufacturer"] = new[]
               {
                   new { name = "B1" },
                   new { name = "B2" },
                   new { name = "B3" },
                   new { name = "B4" }
               },

           };
           
           
           await clonedStream.SaveAsByTemplateAsync(copiedData1, value1);

Result

A1 B1
A1 B2
A1 B3
A1 B4
A2 B1
A2 B2
A2 B3
A2 B4
A3 B1
A3 B2
A3 B3
A3 B4
A4 B1
A4 B2
A4 B3
A4 B4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant