Copy properties between cells

I need to work out how to duplicate font settings between two cells(bold, size, name, underline) etc.
how would I do that?

@conniem,

Thanks for your inquiry. Instead of copying the font properties, we suggest you please clone the Run node of source cell node, insert it into destination cell node, and set its text according to your requirement. Hope this helps you.

If you still face problem, please share some more detail about your requirement along with input and expected output documents. We will then provide you more information on this.

what I have : a table with a single row and a single cell.
that cell has font set to bold.(for example);
this is my current code to append a new row to the table, with possibly multiple cells. I need the font setting from the first row/first cell to apply to all new cells:

public Row AppendRow(int cellCount)
{
// Create the specified number of cells.
Aspose.Words.Tables.Row newRow = new Aspose.Words.Tables.Row(AsposeDocument);
Aspose.Words.Tables.Row oldRow = m_Table.FirstRow;
Aspose.Words.Tables.Cell c = m_Table.FirstRow.Cells[0];
Aspose.Words.Run aRun;
// Create the specified number of cells for each row.
double totalwidth;
double tablewidth = m_Table.FirstRow.Cells[0].CellFormat.Width;

       for (int cellId = 1; cellId <= cellCount; cellId++)
       {
          Aspose.Words.Tables.Cell cell = new Aspose.Words.Tables.Cell(AsposeDocument);
          aRun = (Run)c.FirstParagraph.Runs[0].Clone(true);
          aRun.Text = "";       
          cell.RemoveAllChildren();
          cell.EnsureMinimum();
          cell.CellFormat.Width = m_Table.FirstRow.Cells[0].CellFormat.Width / cellCount;   
          newRow.Cells.Add(cell);           
          cell.Paragraphs[0].AppendChild(aRun);
       }
       totalwidth = 0;
       for (int x = 0; x < newRow.Cells.Count; x++)
          totalwidth = totalwidth + newRow.Cells[x].CellFormat.Width;
       if (totalwidth != tablewidth)
           newRow.Cells[newRow.Cells.Count-1].CellFormat.Width = newRow.Cells[newRow.Cells.Count-1].CellFormat.Width + (tablewidth - totalwidth);

        m_Table.Rows.Add(newRow);
        newRow.RowFormat.Borders.ClearFormatting();
        return newRow;
    }

however, it does not seem to be doing anything, font wise.

Addendum: turns out, it’s because I’m setting the text in the cell after I create it with the correct font.
so question now is how can I set text in the cell without losing font?

@conniem,

Thanks for your inquiry. We have modified the code. Please use the following method to get the desired output. Hope this helps you.

public static Row AppendRow(int cellCount, Table m_Table)
{
    // Create the specified number of cells.
    Aspose.Words.Tables.Row newRow = new Aspose.Words.Tables.Row(m_Table.Document);
    Aspose.Words.Tables.Row oldRow = m_Table.FirstRow;
    Aspose.Words.Tables.Cell c = m_Table.FirstRow.Cells[0];
    Aspose.Words.Paragraph paragraph;
    // Create the specified number of cells for each row.
    double totalwidth;
    double tablewidth = m_Table.FirstRow.Cells[0].CellFormat.Width;

    for (int cellId = 1; cellId <= cellCount; cellId++)
    {
        Aspose.Words.Tables.Cell cell = new Aspose.Words.Tables.Cell(m_Table.Document);
        paragraph = (Paragraph)c.FirstParagraph.Clone(true);
        foreach (Run run in paragraph.Runs)
        {
            run.Text = "";
        }
        cell.RemoveAllChildren();
        cell.CellFormat.Width = m_Table.FirstRow.Cells[0].CellFormat.Width / cellCount;
        newRow.Cells.Add(cell);
        cell.AppendChild(paragraph);
    }

    totalwidth = 0;
    for (int x = 0; x < newRow.Cells.Count; x++)
        totalwidth = totalwidth + newRow.Cells[x].CellFormat.Width;
    if (totalwidth != tablewidth)
        newRow.Cells[newRow.Cells.Count - 1].CellFormat.Width = newRow.Cells[newRow.Cells.Count - 1].CellFormat.Width + (tablewidth - totalwidth);

    m_Table.Rows.Add(newRow);
    newRow.RowFormat.Borders.ClearFormatting();
    return newRow;
}