Free Support Forum - aspose.com

Cell Alignment With ExecuteWithRegions and Dynamic DataTable

Hi,

We product a report that generates Word Tables. Programmatically, the tables are created using the MailMerge.ExecuteWithRegions method passing a DataTable argument. The DataTable is created dynamically because the number of columns in the generated Word Table is only known at run time. I didn't write the original code, but from what I can see there is a Word document with a table that contains a single column. It looks to me as if Aspose.Words modifies that single-column table to match the number of columns in the DataTable.

All of the above works beautifully. I want to make what I assume is a simple change which is to right-align the the columns containing numeric data. The first column which is always a description column should continue to be left-align. At the moment the numeric data is centered-aligned.

I don't see any code controlling the current alignment. The code creates a DataTable and then simply makes a method call of Document.MailMerge.ExecuteWithRegions(dataTable). So, I assume the current alignment is some default behavior. How can I control the cell alignment utilized for each column in the DataTable during the ExecuteWithRegions Merge operation?

I've attached a sample document showing (1) what a current table looks like presently (2) how we would like to change it and (3) the original table from our source document that is the target for the merge operation.

Thanks in advance for your help.

Ed

I just learned that I need to also control the individual column widths of these Word tables. I hope you can incorporate this into your answer.

Thanks,

Ed

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Since you add columns programmatically, you can programmatically change alignment in cells, you add on the fly, and their width.

I suppose, you use the technique as described here:

If so, you can specify column width when you add it to the table.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.tables.cellformat.width.html

To specify text alignment in the table cell, you should specify alignment of paragraph inside table cell:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.paragraphformat.alignment.html

Hope this helps. Please let me know if you need more assistance.

Best regards.