I have issues with Aspose Words Table. After reading several documentation and I figured this might be correct way as attached a sample word template. It works but sometimes I noticed table is printing twice when if is used twice I believed. Below is the code.
public DataTable RetrieveCombinedCrscPercentages(int caseId)
{
DecisionController decision = new DecisionController();
DataSet ds = decision.RetrieveCalculatedCombinedPercentages(caseId);
DataTable dt = ds.Tables[0].Copy();
dt.Columns.Add("vasrdDisaPct", typeof(string));
dt.Columns.Add("vasrdDisaPct2", typeof(string));
dt.Columns.Add("crsceffdates", typeof(string));
dt.Columns.Add("crsceffdates2", typeof(string));
dt.Columns.Add("vasrdstartdate", typeof(string));
dt.Columns.Add("vasrdenddate", typeof(string));
dt.Columns.Add("VaeffstartDt", typeof(string));
DataTable pctDT = decision.RetrieveSlidingPercentageList(caseId, true);
// If we want to perform two consecutive mail merges on one document while taking data from two tables
// related to each other in any way, we can separate the mail merges with regions.
// Normally, MERGEFIELDs contain the name of a column of a mail merge data source.
// Instead, we can use "TableStart:" and "TableEnd:" prefixes to begin/end a mail merge region.
// Each region will belong to a table with a name that matches the string immediately after the prefix's colon.
// These regions are separate for unrelated data, while they can be nested for hierarchical data.
// foreach (DataRow dr in dt.Rows)
foreach (DataRow dr in dt.Rows)
{
DateTime startDate = (dr["StartDate"].ToString() == String.Empty) | dr["StartDate"].ToString().Equals(DateTime.MinValue.ToString()) ?
DateTime.MaxValue : DateTime.Parse(String.Format("{0:yyyy/mm/dd}", dr["StartDate"].ToString()));
DateTime startDate2 = (dr["StartDate"].ToString() == String.Empty) | dr["StartDate"].ToString().Equals(DateTime.MinValue.ToString()) ?
DateTime.MaxValue : DateTime.Parse(String.Format("{0:mm/yyyy}", dr["StartDate"].ToString()));
DateTime endDate = (dr["EndDate"].ToString() == String.Empty) | dr["EndDate"].ToString().Equals(DateTime.MinValue.ToString()) ?
DateTime.MaxValue : DateTime.Parse(String.Format("{0:yyyy/mm/dd}", dr["EndDate"].ToString()));
DataRow[] rows = pctDT.Select("StartDate ='" + startDate.ToString() + "'");
// Modify some row level properties.
int ctr = 0;
foreach (DataRow row in rows)
{
dr["vasrdDisaPct"] += row["VASRD_1"].ToString() + " " + row["VASRD_2"].ToString() + " " + row["VASRD_3"].ToString() + " (" + row["PERCENTAGE"].ToString() + "%) ";
dr["vasrdstartdate"] = Util.FormatNotificationDate(dr["StartDate"]);
dr["vasrdendDate"] = Util.FormatNotificationDate(dr["EndDate"]);
if (dr["vasrdendDate"].ToString() != "")
{
dr["crsceffdates"] = dr["CombDisaPctRnd"].ToString() + "% from " + dr["vasrdstartdate"] + " to " + dr["vasrdenddate"] +
" for Code(s) " + dr["vasrdDisaPct"];
}
else
{
dr["crsceffdates"] = dr["CombDisaPctRnd"].ToString() + "% from " + dr["vasrdstartdate"] + " for Code(s) " + dr["vasrdDisaPct"];
}
ctr++;
}
}
// dt.TableName = "CombinedCRSCPercentages";
return dt;
}
Output
a. The effective date of this CRSC is:
80% from 01 Oct 2013 to 31 Oct 2014 for Code(s) 7541 (60%) 7913 (20%) 8520 (10%) 8520 (10%)
Combined % | CRSC Effective Date |
---|---|
80 | 01 Oct 2013 |
90% from 01 Nov 2014 for Code(s) 7005 (60%)
Combined % | CRSC Effective Date |
---|---|
90 | 01 Nov 2014 |
But want it as below
80% from 01 Oct 2013 to 31 Oct 2014 for Code(s) 7541 (60%) 7913 (20%) 8520 (10%) 8520 (10%)
90% from 01 Nov 2014 for Code(s) 7005 (60%)
Combined % | CRSC Effective Date |
---|---|
80 | 01 Oct 2013 |
90 | 01 Nov 2014 |
I have highlighted the section that is causing problem. A CH61 APPROVAL (KL) Output.docx (85.8 KB)
A CH61 APPROVAL (KL) Template.docx (85.7 KB)