Hello Support
We have Mutiple page document where the PRODUCT LINE Items will overflow in continuation pages as attached.
1) We have one header / Footer for first page and then different header/ footer for continuation pages
2) WE have page wise totals on all the pages
Please let us know how can we do this with ASPOSE Word .net Mail merge .
Is it best to have the Header or Footer so that it will come on all the pages or is there any other way.
We also do not want any Gaps between header / body and footer so that it looks like same table.
Another query is that for Product line items , can we have a Fix Table height that can cover complete page even if we only have 2-3 line items in it .
Regards
Atul
Urgently awaiting your reply
impexdocs:
1) We have one header / Footer for first page and then different header/ footer for continuation pages
impexdocs:
2) WE have page wise totals on all the pages
impexdocs:
Is it best to have the Header or Footer so that it will come on all the pages or is there any other way.We also do not want any Gaps between header / body and footer so that it looks like same table.
impexdocs:
Another query is that for Product line items , can we have a Fix Table height that can cover complete page even if we only have 2-3 line items in it .
Thank you Tahir for the reply
I am attaching the below :
1) Page1.rtf, Page 2.rtf, Page 3.rtf is the Output how we want . It can go to n number of pages depending on Line items.
2) TemplateDocument.docx is teh Template we have created with Merge Fields and Bookmark
3) 1stpage.png is the screenshot how we envision for 1st page
4) 2ndpage.png is the screenshot how we envision for 2nd page and continuation page.
Below is my queries:
1) If you check the Documents , we have “Total of this Page” which is coming on every Page . How can we have page wise totals.
2) If you check the attached image it shows how we are envisioning the Document for 1st page and continuation pages . Let us know if this is OK.
3) If we have only 2 Product Line items in 3rd page , how can we add blank Rows so that the Body Table merges with the footer Table.
4) How can we Merge Body Table with Footer Table so that it looks one table.
5) Can we have repetitive section which is repetitive on all the pages .
Thanks
Atul
Thanks for the Quick Reply. I am checking your suggestion for the Sum .
However Please reply back for :
3) If we have only 2 Product Line items in 3rd page , how can we add
blank Rows so that the Body Table merges with the footer Table.
4) How can we Merge Body Table with Footer Table so that it looks one table.
I have attached the screenshot to explain it better
Regards
Atul
impexdocs:
3) If we have only 2 Product Line items in 3rd page , how can we add blank Rows so that the Body Table merges with the footer Table.
impexdocs:
4) How can we Merge Body Table with Footer Table so that it looks one table.
- Please attach your input Word documents.
- Please
create a standalone/runnable simple application (for example a Console
Application Project) that demonstrates the code (Aspose.Words code) you used to generate
your output document - Please attach the output Word file that shows the undesired behavior.
- Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.
Hello Tahir
Thanks for the Quick Response. We are stil not able to get the Page wise Totals for each pages and the Blank Paragraphs.
Any help will be appreciated.
As suggested Please find the Input Template,
Output Document PDF, and
runnable Sample Application.
Also attached the Query document as what we are facing the issue and wants the guidance as how to achieve it.
Regards
Atul
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:DoNotOptimizeForBrowser/>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
Table table = (Table)doc.FirstSection.Body.GetChild(NodeType.Table, 0, true);
LayoutCollector collector = new LayoutCollector(doc);
int page = 1;
double pageSum = 0.0;
foreach (Row r in table.Rows)
{
if (collector.GetStartPageIndex(r.LastCell) == page)
{
double sum = 0.0;
bool isNumeric = double.TryParse(r.LastCell.ToString(SaveFormat.Text).Trim(), out sum);
if (isNumeric)
pageSum = pageSum + sum;
}
else
{
Shape shape = new Shape(doc, ShapeType.TextBox);
shape.AppendChild(new Paragraph(doc));
shape.FirstParagraph.AppendChild(new Run(doc, pageSum.ToString()));
shape.Width = 50;
shape.Height = 20;
shape.WrapType = WrapType.None;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
shape.Top = 50;
shape.Left = -30;
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
var renderObject = collector.GetEntity(r.LastCell.FirstParagraph);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(r.LastCell.FirstParagraph.GetText());
((Row)r.PreviousSibling).LastCell.FirstParagraph.AppendChild(shape);
pageSum = 0.0;
page++;
}
}
doc.Save(MyDir + "Out.docx");
Hello Tahir
Thanks for the Reply and the Code Snippet . We were able to get the First page Total using this .
Now we are working on subsequent page Totals.
For the Second Query for Page 2 (or last page ) contents , I ahev attached the Final Output which we require. I have given 2 OPTIONS . Whichever is possible please let us knoe and How is it possible.
Please check the 3rd Page of these documents which is the Last Page of the Docment.
1) Option 1 : Output_Document(Option 1).rtf
2) Option 2 : Output_Document(Option 2).rtf
3) This is the layout how we have designed it . If it is not OK then let us know . : Document_LayoutSectionDetails.rtf
Also let us know how we can merge the Body Section and Footer so that there is no Gap in it.
If you can update the Sample Code which we gave and send us the Final Code with the resolution of both the queries it will be appreciated.
Regards
Atul
Hello Tahir
We are even ready for Priority Support and Custom Work if Aspose for give us assurance if this can be achieved.
We need this implemented in the Sample code we gave .
It will be good if we can gave a Call conference also where we can explain what we want .
Note : This is possoble in Crustal Reports but we want to replace Crystal Reports with ASPOSE WORD…
Its becoming Urgent now as Client wants it quickly.
Regards
Atul
impexdocs:
Thanks for the Reply and the Code Snippet . We were able to get the First page Total using this .Now we are working on subsequent page Totals.
impexdocs:
It will be good if we can gave a Call conference also where we can explain what we want .
impexdocs:
Note : This is possoble in Crustal Reports but we want to replace Crystal Reports with ASPOSE WORD..
impexdocs:
Also let us know how we can merge the Body Section and Footer so that there is no Gap in it.
Document doc = new Document(MyDir + "input.docx");
DocumentBuilder dcbuild = new DocumentBuilder(doc);
DataTable dtlblPermitNumber = new DataTable();
DataTable dtedn = new DataTable();
DataTable dtPaking = new DataTable();
DataSet dsLineDetail = new DataSet();
dtlblPermitNumber.TableName = "Product";
dtPaking.TableName = "Packing";
dtedn.Columns.Add("EXPORTER");
dtedn.Columns.Add("ShipmentID");
DataRow row;
DataRow row1;
DataRow drPaking;
row = dtedn.NewRow();
row["EXPORTER"] = "ABC PTY LTD\r\nUNIT 12 HILL AVE\r\nROSUSE NSW 2154\r\nAUSTRALIA";
row["ShipmentID"] = "1";
dtedn.Rows.Add(row);
dtlblPermitNumber.Columns.Add("ShipmentID");
dtlblPermitNumber.Columns.Add("PCODE");
dtlblPermitNumber.Columns.Add("DGOODS");
dtlblPermitNumber.Columns.Add("QTY");
dtlblPermitNumber.Columns.Add("UPRICE");
dtlblPermitNumber.Columns.Add("Total");
for (int j = 0; j < 48; j++)
{
row1 = dtlblPermitNumber.NewRow();
row1["ShipmentID"] = "1";
row1["PCODE"] = "PO000" + j;
row1["DGOODS"] = j + ": 100 CARTONS ASSORTED FOODS 100 CARTONS";
row1["QTY"] = j + "000";
row1["UPRICE"] = j + "00" + j;
row1["Total"] = "1500" + j;
dtlblPermitNumber.Rows.Add(row1);
}
dtPaking.Columns.Add("ShipmentID");
dtPaking.Columns.Add("Marks");
dtPaking.Columns.Add("NoOfPKGS");
dtPaking.Columns.Add("DesOfGoods");
dtPaking.Columns.Add("NetWT");
dtPaking.Columns.Add("GrossWT");
dtPaking.Columns.Add("Volume");
drPaking = dtPaking.NewRow();
drPaking["ShipmentID"] = "1";
drPaking["Marks"] = "AS ADDRESSED";
drPaking["NoOfPKGS"] = "100 CARTON";
drPaking["DesOfGoods"] = " 1 X 20' CONTAINER STC\r\n100 CARTONS\r\nASSORTED FOODS\r\n15000 KGS";
drPaking["NetWT"] = "22";
drPaking["GrossWT"] = "33";
drPaking["Volume"] = "44";
dtPaking.Rows.Add(drPaking);
dsLineDetail.Tables.Add(dtedn);
dsLineDetail.Tables.Add(dtPaking);
dsLineDetail.Tables.Add(dtlblPermitNumber);
if (dtlblPermitNumber.Rows.Count > 0)
{
dsLineDetail.Relations.Add(new DataRelation("LineItem", dtedn.Columns["ShipmentID"], dtlblPermitNumber.Columns["ShipmentID"], false));
}
if (dtPaking.Rows.Count > 0)
{
dsLineDetail.Relations.Add(new DataRelation("LineItem2", dtedn.Columns["ShipmentID"], dtPaking.Columns["ShipmentID"], false));
}
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields;
doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveStaticFields;
doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveUnusedRegions;
doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveUnusedFields;
doc.MailMerge.Execute(dtedn);
// doc.MailMerge.ExecuteWithRegions(dtlblPermitNumber);
doc.MailMerge.ExecuteWithRegions(dsLineDetail);
// doc.InsertBreak(BreakType.PageBreak);
doc.MailMerge.DeleteFields();
//Add total
Table table = (Table)doc.FirstSection.Body.GetChild(NodeType.Table, 0, true);
LayoutCollector collector = new LayoutCollector(doc);
int page = 1;
double pageSum = 0.0;
foreach (Row r in table.Rows)
{
if (collector.GetStartPageIndex(r.LastCell) == page)
{
double sum = 0.0;
bool isNumeric = double.TryParse(r.LastCell.ToString(SaveFormat.Text).Trim(), out sum);
if (isNumeric)
pageSum = pageSum + sum;
}
else
{
Shape shape = new Shape(doc, ShapeType.TextBox);
shape.AppendChild(new Paragraph(doc));
shape.FirstParagraph.AppendChild(new Run(doc, pageSum.ToString()));
shape.Width = 50;
shape.Height = 20;
shape.WrapType = WrapType.None;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
shape.Top = 50;
shape.Left = -30;
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
var renderObject = collector.GetEntity(r.LastCell.FirstParagraph);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
//Console.WriteLine(r.LastCell.FirstParagraph.GetText());
((Row)r.PreviousSibling).LastCell.FirstParagraph.AppendChild(shape);
pageSum = 0.0;
page++;
}
}
collector = new LayoutCollector(doc);
int pagenumber = collector.GetStartPageIndex(table.LastRow.FirstCell.LastParagraph);
int nextpagenumber = pagenumber + 1;
Row lastrow = (Row)table.LastRow.Clone(true);
foreach (Cell cell in lastrow.Cells)
{
cell.RemoveAllChildren();
cell.EnsureMinimum();
}
while (pagenumber != nextpagenumber)
{
table.Rows.Add(lastrow.Clone(true));
collector = new LayoutCollector(doc);
pagenumber = collector.GetStartPageIndex(table.LastRow.FirstCell.LastParagraph);
}
table.LastRow.Remove();
doc.Save(MyDir + "Out.docx");
Hello Tahir
in the “out.docx” which you attached as output , I can see that there is a BLANK Last page . How to avoid that .
Also the $ItemTotal (page total) on 4th Page ( last page) is not coming
Please let us know
Regards
Atul
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-AU</w:LidThemeOther>
<w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
Hello Tahir
in the “out.docx” which you attached as output , I can see that there is a BLANK Last page . How to avoid that .
Also the $ItemTotal (page total) on 4th Page (only on last page) is not coming
Please let us know
Also I Have attached the Inputtemplate.docx and the OUTPUT which we got using your codes. (ouputtemplate.docx)
Note the Gap in between the Table and the Footer . This Gap reduces or increases depending on the CONTENT of the DESCRIPTION OF GOODS in the PRODUCT TABLE as the Line Items are Dynamically coming and there is no fix amount of Characters in it . It can be of 1 line for one product and 3 lines or 4 lines for another product.
Your Example was good for Fixed Static Data .
Please advise
Regards
Atul
impexdocs:
in the "out.docx" which you attached as output , I can see that there is a BLANK Last page . How to avoid that .
impexdocs:
Also the $ItemTotal (page total) on 4th Page (only on last page) is not coming
impexdocs:
Also I Have attached the Inputtemplate.docx and the OUTPUT which we got using your codes. (ouputtemplate.docx)Note the Gap in between the Table and the Footer . This Gap reduces or increases depending on the CONTENT of the DESCRIPTION OF GOODS in the PRODUCT TABLE as the Line Items are Dynamically coming and there is no fix amount of Characters in it . It can be of 1 line for one product and 3 lines or 4 lines for another product.
Hello Tahir
Sorry for getting back after some days.
We are still not able to get the page Totals on the LAST Page .
$ItemTotal (page total) does not work on Last page if there are more then 2 pages .
It shows the totals all the intermediate pages.
Please let us know what code changes we have to do to achieve this
Regards
Atul
//.... your code.....
//.... your code.....
//.... your code.....
table.LastRow.Remove();
collector = new LayoutCollector(doc);
pageSum = 0.0;
int lastpage = collector.GetStartPageIndex(table.LastRow.LastCell);
foreach (Row r in table.Rows)
{
if (collector.GetStartPageIndex(r.LastCell) == lastpage)
{
Console.WriteLine(collector.GetStartPageIndex(r.LastCell));
double sum = 0.0;
bool isNumeric = double.TryParse(r.LastCell.ToString(SaveFormat.Text).Trim(), out sum);
if (isNumeric)
pageSum = pageSum + sum;
}
}
Shape shp = new Shape(doc, ShapeType.TextBox);
shp.AppendChild(new Paragraph(doc));
shp.FirstParagraph.AppendChild(new Run(doc, pageSum.ToString()));
shp.Width = 50;
shp.Height = 20;
shp.WrapType = WrapType.None;
shp.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shp.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
shp.Top = 50;
shp.Left = -30;
table.LastRow.LastCell.FirstParagraph.AppendChild(shp);
doc.Save(MyDir + "Out.docx");