Hi there,
Was testing out the capabilities of Aspose.Word and found that I had to use DocumentBuilder in order to write documents that contain nested tables.
Solved that portion but now my problem is that I have no way (at least not that I can find in the documented API) to set table properties.
Is there a way for me to resize the table so that it would fit into the parent cell margins?
Thanks and Regards.
Just to add on, there seems to be no workaround possible. Specifying the perferred column width seems to be ignored as the perferred table width still stays the same.
Currently the table created by DocumentBuilder is bigger than the cell in which it is residing in, hence much contents are not viewable. A manual resize can be done by going into table propeties and setting table perferred width to 90%, however, my document contains too much of these nested tables to change each and everyone manually.
Hope that I have overlooked something!
Thanks and Regards.
The code for mail merge as follows
private void HandleMergeField(object sender, MergeFieldEventArgs e)
{
if (e.FieldName == "ScanResult")
{
string allscanresult = e.FieldValue.ToString();
allscanresult = allscanresult.Trim();
if (allscanresult!="")
{
string[] scanresultrows = allscanresult.Split(new char[] {'\n'});
builder.MoveToMergeField(e.FieldName);
builder.StartTable();
foreach (string scanresultrow in scanresultrows)
{
// builder.RowFormat.AllowAutoFit = false;
builder.Font.ClearFormatting();
string scanresultrowtrim = scanresultrow.TrimEnd(';');
string[] scanresultcells = scanresultrowtrim.Split(new char[] { ';' });
foreach (string scanresultcell in scanresultcells)
{
builder.InsertCell();
builder.CellFormat.Width = 100;
builder.Write(scanresultcell);
// builder.CellFormat.Width = 100;
}
builder.EndRow();
// builder.RowFormat.AllowAutoFit = false;
}
builder.EndTable();
}
}
}
}
Could you post/share the technique you developed to simulate nested tables by using DocumentWriter?
Thanks, Narayan
Not sure that I have understood you correctly. If you mean how to make nested tables using DocumentBuilder then here is a sample code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// start table
builder.StartTable();
builder.InsertCell();
builder.Write("Text");
builder.InsertCell();
builder.Write("Text");
// start nested table
builder.StartTable();
builder.InsertCell();
builder.Write("Text");
builder.InsertCell();
builder.Write("Text");
builder.EndRow();
builder.EndTable();
// end nested table
builder.InsertCell();
builder.Write("Text");
builder.EndRow();
builder.EndTable();
// end table
string filename = Application.StartupPath + @"\TestNestedTables Out.doc";
// Save resulting document.
doc.Save(filename);
// Open saved document in MS Word.
System.Diagnostics.Process.Start(filename);
Best regards,