Problem in merging table inside another table row

Hi,

I have attached a JPG file(Table.JPG) which contains the design in my word templete i have TableStart and TableEnd region with in a row of another table.
After merging i am getting the result as below

QTY PART DESCR COND DEL XLBS PRICE XPRICE
2 0006833 CONE (0504943) A 46.00 221.13 442.26
WEIGHT (LBS) 46.00
SUBTOTAL (USD): $442.26
FREIGHT (USD): $0.00
INSURANCE (USD): $0.00
PACKING CHARGES (USD): $0.00
GRAND TOTOAL (USD): $442.26

The alignment of the inner table and the outer table are not displaying properly.
i like to know what i have to do to make the alignment properly for both inner & outer table.

Hi

Thanks for your inquiry. Could you please attach your input, output documents and expected output? I will investigate the issue and provide you more information.
Best regards,

hi,
herewith i have attached the template that i have used (SalesOrderQuote.dot).
I have also attached the output that i have got(Quote20064171642687.pdf).
The problem that i am facing is the cell alignment of the table is not properly formed.you can see this in the PDF file.
Thanks.

Hi

Thank you for additional information. Have you tried saving your output document as DOC? Is cell alignment also incorrect in DOC? Please save your output document in DOC and attach it here. I will compare DOC and PDF and provide you more information.
Also, as I can see, you use Aspose.Words 6.1.0. Please try using the latest version of Aspose.Words. You can download it from here:
https://releases.aspose.com/words/net
Best regards,

hi,
i have download the latest Aspose.Word 8.1.0 and have tried saving the document as DOC, PDF & HTML.
i am getting the expected result in the DOC file. but in PDF some rows are missing and the alignment is not properly formed.
In Html file the alignment are not properly formed.
i have attached DOT, DOC & PDF file for your reference.
Thanks,

Hi

Thank you for additional information. Could you please provide me simple code which you use to fill the document with data, this will allow me to reproduce the problem on my side.
Best regards,

hi,
Below is the code that we used to generate the document.

public static void SalesOrderMailMerger(string orderId, string customerId, string fName)
{
    try
    {
        Aspose.Words.License license = new Aspose.Words.License();
        license.SetLicense("Aspose.Total.lic");
        Aspose.Cells.License Cellslicense = new Aspose.Cells.License();
        Cellslicense.SetLicense("Aspose.Total.lic");
        SalesOrder salesOrderObj = SalesOrder.GetSalesOrderById(orderId);
        CustomerSalesInfoList customerSalesInfoList = CustomerSalesInfoList.GetCustomerSalesOrderItem(orderId, customerId);
        CustomerInfo cinfo = CustomerInfo.GetCustomerInfo(customerId);
        CisCompanyDetails details = GetCompanyDetails();
        CisCompanyAddress primaryAddress = GetPrimaryAddress();
        decimal totalCost;
        decimal totalWeight;
        decimal? _freight = 0;
        decimal? _insurance = 0;
        decimal? _packingfee = 0;
        if (Convert.ToBoolean(salesOrderObj.InvoiceFreight))
            _freight = salesOrderObj.Freight;
        if (Convert.ToBoolean(salesOrderObj.InvoiceInsurance))
            _insurance = salesOrderObj.InsuranceFee;
        if (Convert.ToBoolean(salesOrderObj.InvoicePacking))
            _packingfee = salesOrderObj.PackingCharges;
        IFormatProvider provider = CultureInfo.CurrentUICulture;
        Document doc = new Document(HttpContext.Current.Server.MapPath(Resources.FilePathResource.SAO_QuoteTemplateFilePath));
        DataTable OrderItems = ConstructSalesItemsDataTable(customerSalesInfoList, out totalCost, out totalWeight);
        doc.MailMerge.Execute(new string[] { "CISCOMPANY", "HADDRESS1", "HADDRESS2", "HCITY", "HSTATE", "HZIP", "HPHONE", "HFAX", "HWEBSITE", "HEMAIL",
                "CREATEDBY","CREATEDBYEMAIL","SALESORDERID","CREATEDON","COMPANY","ADDRESS","CITY","STATE","ZIP","COUNTRY",
                "PHONE","FAX","ATTENTION","EXPIRATION","PAYMENTTERMS","COMPANY","SHIPTO","ATTENTION","SHIPTYPE", "XLBSTOTAL","SUBTOTAL", "FREIGHT","INSURANCE","PACKINGCHARGES","GRANDTOTAL","Notes","TERMSOFSALE","TERMSOFPAYMENT" ,"FOOTERCOMPANY"},
            new object[] {details.LegalCompanyName,primaryAddress.Address1,primaryAddress.Address2,primaryAddress.City,primaryAddress.State,primaryAddress.Zip,
                details.Phone,details.Fax,details.Website,details.Email, salesOrderObj.CN, salesOrderObj.UserPrincipleName,salesOrderObj.Id,salesOrderObj.CreatedOnString, cinfo.Company,cinfo.Address,cinfo.City,cinfo.State,cinfo.PostalCode,cinfo.CountryAbbreviation,cinfo.Phone,cinfo.Fax,salesOrderObj.Attention,
                SalesExpirationExtension.Name(salesOrderObj.ExpiresAfter),salesOrderObj.PaymentTerms,cinfo.Company, salesOrderObj.Address.Replace("","\r\n"),
                salesOrderObj.Attention,salesOrderObj.ShipType, totalWeight, string.Format("{0:c}", totalCost), string.Format("{0:c}", _freight),string.Format("{0:c}", _insurance),string.Format("{0:c}", _packingfee),
                string.Format("{0:c}", totalCost+_freight+_insurance+_packingfee),salesOrderObj.Notes.Replace("","\r\n"),salesOrderObj.TermsofSale,salesOrderObj.TermsofPayment,details.LegalCompanyName });
        doc.MailMerge.MergeField += new MergeFieldEventHandler(HandleRemoveParagraphs);

        doc.MailMerge.ExecuteWithRegions(OrderItems);
        string imagePath = HttpContext.Current.Server.MapPath(Resources.FilePathResource.Cis_Logo + details.CompanyLogo);
        string[] keys = { "MyImageFieldName" };
        string[] values = { imagePath };
        doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(HandleMergeImage);
        doc.MailMerge.Execute(keys, values);
        doc.Save(HttpContext.Current.Server.MapPath(Resources.FilePathResource.SAO_MergeHTMLOutputPath) + fName + ".html", SaveFormat.Html);
        doc.Save(HttpContext.Current.Server.MapPath(Resources.FilePathResource.SAO_MergePDFOutputPath) + fName + ".pdf", SaveFormat.Pdf);
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

In ConstructSalesItemsDataTable

public static DataTable ConstructSalesItemsDataTable(CustomerSalesInfoList customerSalesInfoList, out decimal totalCost, out decimal totalWeight)
{
    DataTable dtStockItem = new DataTable("OrderItems");
    totalCost = 0;
    totalWeight = 0;
    try
    {
        dtStockItem.Columns.Add("QTY");
        dtStockItem.Columns.Add("QTYSHIPPED");
        dtStockItem.Columns.Add("PARTNUMBER");
        dtStockItem.Columns.Add("DESCRIPTION");
        dtStockItem.Columns.Add("CONDITION");
        dtStockItem.Columns.Add("PRICE");
        dtStockItem.Columns.Add("XPRICE");
        dtStockItem.Columns.Add("XLBS");
        dtStockItem.Columns.Add("EXTLBS");
        dtStockItem.Columns.Add("NOTE");
        dtStockItem.Columns.Add("DEL");
        foreach(CustomerSalesInfo customerSlaesInfo in customerSalesInfoList)
        {
            DataRow drStockItem = dtStockItem.NewRow();
            drStockItem["QTY"] = customerSlaesInfo.Quantity;
            drStockItem["QTYSHIPPED"] = customerSlaesInfo.Quantity;
            drStockItem["PARTNUMBER"] = customerSlaesInfo.PartNumber;
            drStockItem["DESCRIPTION"] = customerSlaesInfo.DescriptionWA;
            drStockItem["CONDITION"] = customerSlaesInfo.Condition;
            drStockItem["PRICE"] = customerSlaesInfo.CostPrice;
            drStockItem["XPRICE"] = customerSlaesInfo.XPrice;
            drStockItem["XLBS"] = customerSlaesInfo.XWeight;
            drStockItem["EXTLBS"] = Convert.ToDecimal(customerSlaesInfo.Quantity * customerSlaesInfo.XWeight);
            drStockItem["NOTE"] = customerSlaesInfo.ItemNotes;
            drStockItem["DEL"] = customerSlaesInfo.DeliveryDays;
            dtStockItem.Rows.Add(drStockItem);
            totalCost = totalCost + Convert.ToDecimal(customerSlaesInfo.XPrice);
            // totalWeight = totalWeight + Convert.ToDecimal(customerSlaesInfo.Quantity * customerSlaesInfo.XWeight);
            totalWeight = totalWeight + Convert.ToDecimal(customerSlaesInfo.XWeight);
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return dtStockItem;
}

In HandleRemoveParagraphs

private static void HandleRemoveParagraphs(object sender, MergeFieldEventArgs e)
{
    if (e.FieldName == "NOTE")
    {
        // Get parent Table Aspose.Words.Tables.Table myTable = (e.Field.Start.ParentParagraph.ParentNode.ParentNode.ParentNode as Aspose.Words.Tables.Table);
        // Remove empty peragraph after table
        myTable.NextSibling.Remove();
        // Remove empty paragraph before table
        myTable.PreviousSibling.Remove();
        Aspose.Words.Tables.Row row = (e.Field.Start.ParentNode.ParentNode.ParentNode as Aspose.Words.Tables.Row);
        if (e.FieldValue.ToString().Length <= 0)
        {
            row.Remove();
        }
    }
}

In HandleRemoveParagraphs

private static void HandleMergeImage(object sender, MergeImageFieldEventArgs e)
{
    if (e.FieldName == "MyImageFieldName")
    {
        string fileName = e.FieldValue as string;
        e.ImageFileName = fileName;
    }
}

Thanks.

Hi,
Thank you for additional information. The problem occurs because there are few tables one by one in your document. I linked your request to the appropriate issue. You will be notified as soon as it is fixed.
I can suggest you temporary workaround of this issue for now:
Please try using the following code before saving your document:

// Get collection of tables
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
Paragraph spliter = new Paragraph(doc);
spliter.ParagraphBreakFont.Size = 1;
// loop through all tables
foreach(Table table in tables)
{
    // Check if the next node after the tabel is another table.
    if (table.NextSibling != null && table.NextSibling.NodeType == NodeType.Table)
    {
        Table nextTable = (Table) table.NextSibling;
        // Append all rows form the current table to the next.
        while (table.HasChildNodes)
            nextTable.Rows.Insert(0, table.LastRow);
    }
}
// Save output document
doc.SaveToPdf(@"Test\out.pdf");

Hope this helps.
Best regards,

hi,
I have tried the workaround before saving the document.
Now the output looks better. but still i am facing the cells alignment problem while saving in HTML/PDF
I have attached the screen shot of the HTML output here for your reference.
Is there any workaround to fix that alignment Issue.
Thanks

Hi

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
Best regards,

The issues you have found earlier (filed as 9902) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(8)