Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Wed Oct 12, 2011 10:34 am
hi there,
can you please tell me how i set a tables fixed width in spire.doc?
e.g.
i want a table that is always the full page width regardless of the content inside the table cells. the below code snippet is what i have so far...
vb.net
Dim theSection As Spire.Doc.Section = theTemplate.Sections(0)
Dim theTable As Spire.Doc.Table = theSection.AddTable()
theTable.TableFormat.HorizontalAlignment = Spire.Doc.Documents.RowAlignment.Center
theTable.Width = 800 <<<<< Read Only Property
Dim theRow As Spire.Doc.TableRow = theTable.AddRow
Dim theCell As Spire.Doc.TableCell = theRow.AddCell()
Dim theP As Spire.Doc.Documents.Paragraph = theCell.AddParagraph()
theP.AppendText("test centered full width text")
cheers!
-

fatmedia
-
- Posts: 13
- Joined: Fri Oct 07, 2011 2:31 pm
Wed Oct 12, 2011 10:44 am
ok i think i figured it out.
i need to set the cell widths individually.
theCell.Width = 500
is this the correct way to do it?
-

fatmedia
-
- Posts: 13
- Joined: Fri Oct 07, 2011 2:31 pm
Thu Oct 13, 2011 3:01 am
Hello fatmedia,
If you want to set the with of the cell individually, the method you gave can achieve the effect. I compiled the code as below:
- Code: Select all
Document doc = new Document();
doc.LoadFromFile(@"..\..\Template.docx",FileFormat.Docx);
Section section=doc.Sections[0];
String[] header = { "Name", "Capital", "Continent" };
Table table = section.AddTable();
//set the rows and columns of the table
table.ResetCells(header.Length+1, header.Length);
TableRow row = table.Rows[0];
//set the tableHeader
for (int i = 0; i < header.Length;i++ )
{
row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
Paragraph paragraph = row.Cells[i].AddParagraph();
//set the cell width
row.Cells[i].Width = 100;
TextRange textRange = paragraph.AppendText(header[i]);
}
doc.saveToFile(@"sample.docx",FileFormat.Docx);
Have a nice day.
Thanks and Regard
Tina
Technical Support/Developer,
e-iceblue Support Team
-


Tina.Lin
-
- Posts: 152
- Joined: Tue Sep 13, 2011 5:37 am