在 Aspose.Words LINQ 报告引擎中构建报告的动态对象

dynamic object to build reports in Aspose.Words LINQ Reporting Engine

我从客户那里得到 json 字符串:

{ "Client": { "Name": "John" } }

在文档中我有以下标签:

<<[client.name]>>

并尝试注入它:

var obj = JsonConvert.DeserializeObject(input.DataJson);
var engine = new ReportingEngine();
engine.BuildReport(document, obj);

但是没用。 我可以通过不区分大小写的属性检查来注入 json 吗?或者我必须修改 json 以将其属性设置为小写? 我该怎么做?

恐怕,LINQ Reporting Engine 目前不支持动态对象作为数据源。我们已经为您的场景记录了一个新的功能请求。此问题的 ID 是 WORDSNET-16421。一旦所请求的功能得到实施,我们将通过此线程通知您。您可以将 JSON 字符串转换为 DataSet 以使其按照以下示例中的描述工作:

// Assume you have following in document
// <<[Client.Name]>>
string json = "{ \"Client\": { \"Name\": \"John\" } }";

XmlDocument Xml = (XmlDocument)JsonConvert.DeserializeXmlNode(json);

DataSet ds = new DataSet();
ds.ReadXml(new MemoryStream(Encoding.UTF8.GetBytes(Xml.InnerXml)));

Document doc = new Document(MyDir + @"in.docx");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, ds.Tables[0].Rows[0], "Client");

doc.Save(MyDir + @"18.2.docx");

我在 Aspose 工作,担任开发人员推广员。