We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Repeated Region: How to Achieve This?

I want to a summary of orders group by order date and subtotal and grand total for the records.
Output would be

Sales
From 11 Nov 2011 to 13 Nov 2011

Date:11 Nov 2011
SR# ITEM_NAME Quantity
1 Pizza 2
2 Cold Drink 2
total orders=2
Date:12 Nov 2011
3 Pizza 2

4 Cold Drink 6
5 Pizza 7

6 Cold Drink 3

total orders=4
Date:13 Nov 2011
7 Pizza 2

8 Cold Drink 6

9 Pizza 7

                                      <b>total orders=3</b><br>                                          <font size="5">G.Total=9</font><br><br>Plz note that one first row of the result is header row. How can i do that? Should i make two templates.<br>i.e one containing bookmarks and the other containing a data table. I have to use table for records. and bookmarks for the date. Any idea? should do that programticaly?<br><br>code so far:<br>Document doc = new Document("D:\\Templates\\MyTemplate.doc");<br><br>        DocumentBuilder builder = new DocumentBuilder(doc);<br><br>        // We call this method to start building the table.<br><br>        builder.startTable();<br>        ResultSetMetaData metaData = rs.getMetaData();<br>    <br>        // header row for columns header<br>        System.out.println(metaData.getColumnCount());<br>        int rowCount=1;<br>        for (int j = 1; j < 2; j++) {<br>            System.out.println("Header Row"+rowCount);<br>            for (int i = 1; i <= metaData.getColumnCount(); i++)<br><br>            {<br>                builder.insertCell();<br>                builder.write(metaData.getColumnName(i));<br>                System.out.print(" - " +metaData.getColumnName(i));<br><br>            }<br>            builder.endRow();<br>        }<br>        System.out.println();<br>        <br>        // columns values<br>        <br>        while(rs.next())<br>            {<br>            rowCount++;<br>            System.out.println("Row Started"+rowCount);<br>                for (int i = 1; i <= metaData.getColumnCount(); i++)<br>                    {<br>                        builder.insertCell();<br>                        builder.write(rs.getObject(i).toString());<br>                        System.out.print("----"+i);<br>                    }<br>                System.out.println("Row Ended"+rowCount);<br>                builder.endRow();<br>        }<br><br>        // Signal that we have finished building the table.<br><br>        builder.endTable();<br><br>        // Save the document to disk.<br><br>        doc.save("D:\\templates\\MyTemplate.doc");<br>        <br>        rs.close();<br><br><br><br><br>

Hi Bilal,


Thanks for your inquiry. I think, in your case, it would be easy for you if you use mail merge feature of Aspose.Words for reporting purpose. Please see the following link for more details:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/about-mail-merge-in-aspose-words.html

Moreover, to be able to achieve what you are looking for, I would like to suggest you to read the following article:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-use-nested-mail-merge-regions.html

I hope, this will help.

Best Regards,

Thank u awais for the quick reply.

I already read the article u mentioned at

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-

use-nested-mail-merge-regions.html

but problem is that i want to repeat the table with the header.

Plz see my desired output. And I also want to do it in programing way . what should i do then? Am i on the wrong path?




Hi

Thanks for your request. It would be great if you attach your sample data, template, output and expected output documents. We will check them and provide you more information.

Best regards,

Attached is the output file i got through above code. I want to group it by order date and want to do a total and sub total for each date. Then at the end i want to do grand total. Output like in the first post.


Hi

Thanks for your request. I think to achieve this you will have to use mail merge with nested regions and perform pre-processing of your data.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-use-nested-mail-merge-regions.html

Unfortunately, there is no direct way to achieve what you need, so you will have to pre-process your data.

Best regards,

Thank u very much for the reponses and help,

The link to article is for data that is hierarichal. i.e parent child relation. I have result set that i need to iterate on a list of dates. And i want to do that dynamicly (with code). I am creating a document with document builder and then saving the result set by iterating on date.
for each date in datelist
doc.getMailMerge().executeWithRegions(tableName, rs);



Hi

Thank you for additional information. But it is not clear for me what the problem is.

For example, in your template you have nested regions. In this case, you should create a data source with structure that match structure of nested regions. You should do this during pre-processing your input data.

In addition, I think, in your case, you can use ImailMergeDatasource:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.reporting.imailmergedatasource.html

Best regards,

ok
i will be back after i get the desired ouput. Thank u for the time and support.

Hi,

I hope all the aspose members are doing good. I have achieved the desired ouptut after some modifications in the required output. I repeated a table (no of iterations = no od dates ) inside a document.
Aspose programmers guide helped me a lot, Thank u all.

Hi,

Thanks for your request. It is perfect that you managed to achieve the desired output. Please let us know if you need more assistance, we will be glad to help you.

Best Regards,

Now the problem is that my table is splitting on multiple pages, I have 100 or more tables repeated according to date. But the table is splitting across pages. If i want to restrict the table to split across pages of a word what should i do?

instead of

// Disable breaking across pages for all rows in the table.


for(Row row : table)


row.getRowFormat().setAllowBreakAcrossPages(false);


or


// To keep a table from breaking across a page we need to enable KeepWithNext


// for every paragraph in the table except for the last paragraphs in the last


// row of the table.


for (Cell cell : (Iterable) table.getChildNodes(NodeType.CELL, true))


for (Paragraph para : cell.getParagraphs())


if (!(cell.getParentRow().isLastRow() && para.isEndOfCell()))


para.getParagraphFormat().setKeepWithNext(true);



i want some think like

NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
Iterator nodIter = tables.iterator();
while(nodIter.hasNext())
{
Table table = (Table) nodIter.next();
for(Row row : table)

row.getRowFormat().setAllowBreakAcrossPages(false);
}

but the bold line creates error; Type mismatch: cannot convert from element type Node to Row

Hi

Thanks for your request. Maybe you should use something like this:

NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);

Iterator<Node> nodIter = tables.iterator();

while(nodIter.hasNext())

{

Table table = (Table) nodIter.next();

for(Row row : table.getRows())

row.getRowFormat().setAllowBreakAcrossPages(false);

}

Best regards,

Thank u for ur help. I am stuck at this.
NodeCollection tables = dstDocBookMark.getChildNodes(NodeType.TABLE, true);
Iterator nodIter = tables.iterator();
while(nodIter.hasNext())
{
Table table = (Table) nodIter.next();
Rows rows = table.getRows();
for(Row row : rows)
row.getRowFormat().setAllowBreakAcrossPages(false);
}

NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);

Iterator nodIter = tables.iterator();

while(nodIter.hasNext())

{

Table table = (Table) nodIter.next();

for(Row row : table.getRows())

row.getRowFormat().setAllowBreakAcrossPages(false);

}

I get the same error :Type mismatch: cannot convert from element type Node to Row. I got same error when i used insertdocument code in my application,

I changed
/ Loop through all sections in the source document.

for (Section srcSection : srcDoc.getSections())


{

to
for (Node section : doc.getSections())
{
beacuse i was getting same type of error: Type mismatch: cannot convert from element type Node to Section

What is the problem in casting?

Hi

Thanks for your request. Which version of Aspose.Words for Java do you use? There were problems with typed collection in old versions of Aspose.Words for Java. So please try using the latest version and let me know how it goes on your side. You can download the latest version from here:

http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/category1360.aspx

Also, as I can see in the code example here:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/howto-insert-a-document-into-another-document.html

we use:

for (Section srcSection : srcDoc.getSections())

getSections(), getRows(), getCells() methods returns typed collection. So you can iterate through items in them without casting.

Best regards,


Thank u for help.How i can do it with older version. any workaround?

Hi

Thanks for your request. Use code like this:

for (int i = 0; i < doc.getSections().getCount(); i++)

{

Section sect = doc.getSections().get(i);

// Do something with section.

// ...........................

}

Best regards,

End:

Table table=null;
Rows rows=null;
int rowsCount=0;
while(nodIter.hasNext())
{
table = (Table) nodIter.next();
rows =table.getRows();
rowsCount = rows.getCount();
for(int i=0;i<rowsCount;i++)
{
rows.get(i).getRowFormat().setAllowBreakAcrossPages(false);
}
}


Thank u.

Hi

It is perfect that you managed to implement what you need. Please feel free to ask in case of any issues, we will be glad to help you.

Best regards,