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

Free Support Forum - aspose.com

How to add column and rows to aspose.words table

Hi,


1. I have a html file which has tables on it, tables are html calendars,
2. I am getting those table and looping to each cell for me to be able to insert form fields and text to it.

Question:
How can add 1 column to rightmost of each calendar table and 1 row at the bottom and insert form fields also to it?

Hi there,

Thanks for sharing the detail. Please note that a table in MS Word is a set of independent rows. Each row has a set
of cells independent on cells of other rows. So there is no logical
“column” in a MS Word’s table. “The 1st column” is something like “a set
of the 1st cells of each row in a table”.

For example, it’s possible to have a table where the 1st row consists
of two cells: 2cm and 1cm and the 2nd row consists of different two
cells: 1cm and 2cm of width.

However, you can work with columns using the approach shared at following documentation link.
http://www.aspose.com/docs/display/wordsnet/Working+with+Columns

Please use the following code example to insert row at the end of table and insert a text input form field. Please let us know if you have any more queries.


<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:DoNotShowPropertyChanges/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

var doc = new Document(MyDir + "in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

//Get the first table in the document

Table table = doc.FirstSection.Body.Tables[0];

//insert empty row at the end of table

Row lastrow = (Row)table.LastRow.Clone(true);

table.AppendChild(lastrow);

foreach (Cell cell in lastrow.Cells)

{

cell.RemoveAllChildren();

cell.EnsureMinimum();

cell.CellFormat.ClearFormatting();

builder.MoveTo(cell.FirstChild);

builder.InsertTextInput("TextInput", TextFormFieldType.Regular, "", "Hello", 0);

}

doc.Save(MyDir + "Out.docx");