Aspose Words Cell width 100%

Hi,

I have a normal table with “n” columns.

but last/first row has only cell, I need that cell to be 100% width as table.

I tried a lot but unable to solve it.

Please provide a solution.

Header Header Header Header
Data Data Data Data
Data
Header
Data Data Data
Data

Thanks,
Lalitya

Hi Lalitya,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Hi Manzoor,

please look at the attached doc.

sorry i uploaded docx actually i’m coding in doc.

Thanks,
Lalitya

Hi Lalitya,

Thanks for your inquiry. Please use following code example add missing cell into the row. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "word+table.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Get max count of table's cell
int cellcount = 1;
foreach (Row row in table.Rows)
{
    if (row.Cells.Count > cellcount)
        cellcount = row.Cells.Count;
}
// Add missing cell to each row and merge it with last cell of row
foreach (Row row in table.Rows)
{
    for (int i = row.Cells.Count; i < cellcount; i++)
    {
        if (row.Cells.Count == 1)
        {
            row.LastCell.CellFormat.HorizontalMerge = CellMerge.First;
        }
        Cell cell = new Cell(doc);

        row.AppendChild(cell);
        cell.CellFormat.HorizontalMerge = CellMerge.Previous;
    }
}
doc.Save(MyDir + "Out.docx");

Hi Manzoor,

You saved my day.

Thank you very much.


Regards,
Lalitya

Hi Lalitya,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.