Issues with Pivot Table In Word Document

I’m having issue generating the report, I’ve follow the example from this link Pivot Table but still unable to get the correct result, I’m using LINQ Reporting Engine.

public class Output
{
     public List<Datas1> Datas1 { get; set; }
     public List<Datas2> Datas2 { get; set; }
}

public class Datas1
{
    public string Name { get; set; }
}

public class Datas2
{
    public string Name { get; set; }
    public List<Datas1Details> D1Details { get; set; }

}
public class Datas1Details
{
    public string Data1Name { get; set; }
    public string Score { get;set; }
}

Output output = new Output
{
  Datas2 = new List<Datas2> { 
      new Datas2 { 
          Name = "Score1",
          D1Details = new List<Datas1Details>
          {
              new Datas1Details
              {
                  Data1Name= "A",
                  Score = "1",
              },
              new Datas1Details
              {
                  Data1Name= "B",
                  Score = "2",
              },
              new Datas1Details
              {
                  Data1Name= "C",
                  Score = "2",
              }
          }
      },
      new Datas2 {
          Name = "Score2",
          D1Details = new List<Datas1Details>
          {
              new Datas1Details
              {
                  Data1Name= "A",
                  Score = "1",
              },
              new Datas1Details
              {
                  Data1Name= "B",
                  Score = "2",
              },
              new Datas1Details
              {
                  Data1Name= "C",
                  Score = "2",
              }
          }
      },
      new Datas2 {
          Name = "Score3",
           D1Details = new List<Datas1Details>
          {
              new Datas1Details
              {
                  Data1Name= "A",
                  Score = "1",
              },
              new Datas1Details
              {
                  Data1Name= "B",
                  Score = "2",
              },
              new Datas1Details
              {
                  Data1Name= "C",
                  Score = "2",
              }
          }
      },
  },
  Datas1 = new List<Datas1>
  {
      new Datas1
      {
          Name= "A",
      },
      new Datas1
      {
          Name= "B",
      },
      new Datas1
      {
          Name= "C",
      }
   }
}

// Input directory
string dataDir = @"C:\Input.docx";

// Build Aspose
Document doc = new Document(dataDir);
ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.AllowMissingMembers;
engine.BuildReport(doc, output);

// Output directory
dataDir = @"C:\AsposeWord_Test_Output.docx";

// Save the output
doc.Save(dataDir);

Current generated output are wrong

Expected output

Input file
Input.docx (15.1 KB)

@alexey.noskov Are you able to help on this?

Hello, can you please advise?

@leoteoh I have forwarded your question to our LINQ Reporting engine developers. They will help you shortly.

Alright, I think the problem is row replaced column’s data.

@leoteoh

Once ReportBuildOptions.AllowMissingMembers is not applied, the issue is revealed. The engine cannot access Datas1 within the loop through Datas2, because it looks for Datas1 among members of a Datas2 item, but obviously fails. This is expected behavior described at Using Contextual Object Member Access.

The following steps may be taken to fix the issue:

  1. Assign a name to the data source, for example, “ds” as follows:
    engine.BuildReport(doc, output, "ds");
  1. Use the name within the loop through Datas2 to access Datas1 in the template like this:
    <<foreach [data1 in ds.Datas1] -horz>>

Here is the modified template: Input_Modified.docx (15.2 KB).

Thanks for the reply, what do you mean by ReportBuildOptions.AllowMissingMembers; is not applied? I have this line of code in the application engine.Options = ReportBuildOptions.AllowMissingMembers;

@leoteoh Ivan means that if do not apply ReportBuildOptions.AllowMissingMembers the problem becomes obvious and you can easily detect the problem by reading the exception message.