Inserting a table into a word document

I am currently inserting a table into a word document with this code…

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.CurrentSection.Body.ChildNodes.Insert(0, (Node)tablePartsArray[0]);

but when the documnet comes up, the table is centered. Is there a way to left justify the table while inserting it or afterwards?
Please see the attached document for an output example
Thanks - John

Hi
Thanks for your request. Please try using the following code to achieve this.

// Open document
Document doc = new Document(@"Test109\in.doc");
// Get Table
Table tab = doc.FirstSection.Body.Tables[0];
// Loop throught all rows and set alignment of rows
foreach (Row row in tab.Rows)
{
    row.RowFormat.Alignment = RowAlignment.Left;
}
// Save output document
doc.Save(@"Test109\out.doc");

I hope this could help you.
Best regards.

You are the man!
Thank you so much.
- John

I am now trying to use a feature I had in VSTO to stretch a table in word to fit the window instead of its contents. Does this feature exist in Aspose?
Here’s the code I used in VSTO (wdDocument is my Word.Documetn object and wdApp is my WordApplication object):

wdDocument.Select();
wdApp.Selection.WholeStory();
wdApp.Selection.Tables[wdApp.Selection.Tables.Count].AllowAutoFit = true;
wdApp.Selection.Tables[wdApp.Selection.Tables.Count].AutoFitBehavior(WdAutoFitBehavior.wdAutoFitWindow);

Please advise on how to do this in Aspose.Words.
thanks.

Hi

Thanks for your inquiry. AllowAutoFit property is available in RowFormat. Please see the following link for more information.
https://reference.aspose.com/words/net/aspose.words.tables/table/allowautofit/
Regarding the second it sets preferred width of table to 100%. Unfortunately there is no way to set this using Aspose.Words. But I think you can calculate width of page and set width of cells in the table.
Best regards.