We're sorry Aspose doesn't work properply without JavaScript enabled.

# 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");


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);