由于报表生成的图表中往往有多个,并且这些图表对应的数据应该也是多组,我该如何修改才能做到一次生成多个图表?
这是输入模版
功能测试.docx (37.3 KB)
这是代码:
LicenseUtil.getLicense();
Document doc = new Document(inputFile);
List<TestData> testDataList = generateTestDataList();;
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(TestData.class);
engine.buildReport(doc, testDataList, "testDataList");
doc.save(outputFile);
报错提示:
java.lang.IllegalStateException: An error has been encountered at the end of expression 'TestData y
in testDataList2]>'. Can not get the value of member 'testDataList2' on type 'class java.util.ArrayList'.
我代码上需要如何修改呢?
数据无所谓,您随便填一些就行,我好奇的是应该怎么传进去?
@747209427 请参阅以下代码示例和附加模板:
public class DataList {
public List<Data> getData()
{
return mData;
}
private List<Data> mData = new ArrayList<Data>();
}
public class Data {
public Data(String name, double value)
{
mName = name;
mValue = value;
}
public String getName()
{
return mName;
}
public double getValue()
{
return mValue;
}
private String mName;
private double mValue;
}
// Build dummy data. There will 5 sets of data in the list
// so the result document will have 5 charts.
List<DataList> dataList = new ArrayList<DataList>();
for (int i = 0; i < 5; i++)
{
DataList data = new DataList();
for (int j = 0; j < 5; j++)
data.getData().add(new Data("data" + i + j, j + i + 1));
dataList.add(data);
}
// Build the report.
Document doc = new Document("C:\\Temp\\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(DataList.class);
engine.buildReport(doc, dataList, "dataList");
doc.save("C:\\Temp\\out.docx");
这样貌似能解决一些问题,但感觉不太灵活,如果中间间隔了很多文字段落咋办呢?真实使用的话图表不会都挨在一起的