I’m using linq reporting engine through a DataSet.
In my model i have an attribute which is a List of String: private List targheAuto;
How can i write out all the strings contained in the list ? I tryed to use <> statement , but it doesn’t work with such a list of string…
Thanks
DocumentBuilder builder = new DocumentBuilder();
builder.write("The items are: <><>, <>and others.");
Document doc = builder.getDocument();
ArrayList arrList = new ArrayList();
arrList.add("Item1");
arrList.add("Item2");
arrList.add("Item3");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, arrList, "items");
doc.save(MyDir + "out.docx");
Hi, thanks for the feedback, but i’m using a dataSet populated from XML:
DataSet dataSet = new DataSet();
dataSet.readXml(new ByteArrayInputStream(dati.getBytes(StandardCharsets.UTF_8)));
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.getKnownTypes().add(Util.class);
engine.getKnownTypes().add(Date.class);
engine.buildReport(doc, dataSet);
where dati is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
xxx
dj333gz
du23232jj
dd2322d
sfdsfsdf
In my template i try to use:
<><><>
But is doesnt work
javax.xml.ws.soap.SOAPFaultException: Errore generico PDF. An error has been encountered at the end of expression 'targa in targheAuto]>'. Can not iterate over an instance of type 'class java.lang.String'.
Document doc = new Document(MyDir + "in.docx");
DataSet dataSet = new DataSet();
dataSet.readXml(MyDir + "in.xml");
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, dataSet.getTables().get(0), "richiedente");
doc.save(MyDir + "17.6.docx");
Hi Tahir, i’m sorry but it doesn’t work either.
targheAuto is a list of values:
dj333gz
du23232jj
and it should display 2 values and not only one.
Simone
It’s the way you get the lists in XML: two or more columns with same name !
The xml you attached is wrong: there are two instances of richiedente and that’s not what we have: we have an instance of richiedente containing two instances of targheAuto…
Hope you’ll correct this issue.
thanks
Simone
Hi Simone,
Thanks for your inquiry. Please note that com.aspose.words.net.System.Data.DataSet.readXml method mimics the .NET DataSet.ReadXml method. This method reads the XML and convert it into DataSet that contain DataTables.
In your case, you need to read the XML using Java code and create an ArrayList and pass it to ReportingEngine.buildReport method. The LINQ Reporting syntax will be
<<foreach [t in richiedente]>><<[t]>><</foreach>>
.
Document doc = new Document(MyDir + "in.docx");
ArrayList arrList = new ArrayList();
//Your code...
arrList.add(...);
arrList.add(...);
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, arrList, "richiedente");
doc.save(MyDir + "17.6.docx");
I’m not happy about it.
simone.padovan:targheAuto is a list of values:dj333gzdu23232jj
Document doc = new Document(MyDir + "in.docx");
ArrayList arrList = new ArrayList();
File fXmlFile = new File(MyDir + "input.xml");
javax.xml.parsers.DocumentBuilderFactory dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
org.w3c.dom.Document docXML = dBuilder.parse(fXmlFile);
docXML.getDocumentElement().normalize();
org.w3c.dom.NodeList nList = docXML.getElementsByTagName("richiedente");
for (int temp = 0; temp < nList.getLength(); temp++) {
org.w3c.dom.Node nNode = nList.item(temp);
if (nNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode;
for(int i = 0; i< eElement.getElementsByTagName("targheAuto").getLength(); i ++)
{
arrList.add(eElement.getElementsByTagName("targheAuto").item(i).getTextContent());
}
}
}
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, arrList, "richiedente");
doc.save(MyDir + "17.6.docx");