Spire.Doc is working to create and populate a table with our data, but with no explicit formatting the first two columns are taking up the majority of the table. The first and second columns are taking up about 40% of the table each only leaving about 20% left for the last column. How do I set the third column to take up the right 50% of the table leaving the left 50% for the other two columns. How do I explicitly set the width of the columns in a filled out table?
Here is the method that is generating our document using spire.
public static void CreateDocumentWithMergeFields(Dictionary<string, string> fieldNames, string filePath)
{
//get filePath from dialog.
var spireStringDocPath = filePath;
//Create a word document
Document document = new Document();
Section section = document.AddSection();
Table table = section.AddTable(true);
//create the header
string[] header = { "FieldName", "MergeField", "Description" };
//add cells
table.ResetCells(fieldNames.Count+1, header.Length);
//setting header row as first row
TableRow headerRow = table.Rows[0];
headerRow.IsHeader = true;
headerRow.Height = 23;
Paragraph fieldNameHeaderCell = headerRow.Cells[0].AddParagraph();
TextRange fieldNameHeaderText = fieldNameHeaderCell.AppendText(header[0]);
Paragraph mergeFieldHeaderCell = headerRow.Cells[1].AddParagraph();
TextRange mergeFieldHeaderText = mergeFieldHeaderCell.AppendText(header[1]);
Paragraph descriptionHeaderCell = headerRow.Cells[2].AddParagraph();
TextRange descriptionHeaderText = descriptionHeaderCell.AppendText(header[2]);
headerRow.Cells[2].SetCellWidth(75, CellWidthType.Percentage);
//for each fieldName add a row with field and merge field
int loopIndex = 1;
foreach (KeyValuePair<string, string> kvp in fieldNames)
{
//add a new row to the table.
TableRow row = table.Rows[loopIndex];
Paragraph fieldNameCell = row.Cells[0].AddParagraph();
//append the field name to the 1st column
var fieldNameText = fieldNameCell.AppendText(kvp.Key);
Paragraph mergedFieldCell = row.Cells[1].AddParagraph();
//create merge field on the second column
var mergeFieldText = mergedFieldCell.AppendField(kvp.Key, FieldType.FieldMergeField) as MergeField;
//mergedFieldCell.AppendText(kvp.Key);
Paragraph descriptionCell = row.Cells[2].AddParagraph();
//appened description in the third column
var descriptionText = descriptionCell.AppendText(kvp.Value);
row.Cells[2].SetCellWidth(75, CellWidthType.Percentage);
loopIndex++;
}
//Save doc file
document.SaveToFile(spireStringDocPath, FileFormat.Doc);
}