I'm trying to make a table in this format, but it's coming out the same as below.
The header is giving a space that I am not able to remove.
The table must have 12 columns.
When I open Word I have to go to Scale and remove that space.
Can anybody help me.
Follow the code.
- Code: Select all
Document doc = new Document();
doc.LoadFromFile("C:\\Temp\\Dev.docx");
Section section = doc.Sections[0];
TextSelection selection = doc.FindString("@TABELA_LOTES_VOLUME", true, true);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);
//FAZER O LOOP
Spire.Doc.Table table = section.AddTable(true);
int totalColuna = 12;
int totalLinhas = 2;
table.ResetCells(totalLinhas, totalColuna);
body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);
//Set the first row as table header
TableRow FRow = table.Rows[0];
FRow.IsHeader = true;
//Set the height and color of the first row
FRow.Height = 23;
FRow.RowFormat.BackColor = Color.FromArgb(102, 102, 102);
FRow.RowFormat.CellSpacing = 0;
String[] Header = { "COLUNA 1", "COLUNA 2", "COLUNA 3", "COLUNA 4", "COLUNA 5", "COLUNA 6", "COLUNA 7", "COLUNA 8", "COLUNA 9", "COLUNA 10", "COLUNA 11", "COLUNA 12" };
for (int i = 0; i < Header.Length; i++)
{
//Set alignment for cells
Paragraph p = FRow.Cells[i].AddParagraph();
FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
p.Format.HorizontalAlignment = HorizontalAlignment.Center;
p.Format.WordWrap = true;
p.RemoveFrame();
p.RemoveAbsPosition();
//Set data format
TextRange TR = p.AppendText(Header[i]);
TR.CharacterFormat.FontSize = 10;
TR.CharacterFormat.Bold = true;
}
doc.SaveToFile("C:\\Temp\\Docmento1.docx", Spire.Doc.FileFormat.Docx);