Posted 23 March 2021, 5:41 am EST
Hi Jose,
We are sorry but Spread doesn’t support this behavior by default. However, you can manually implement this functionality by copying the format from a specific Row/Column to the newly added Rows/Columns as follows:
private void AddRow(object sender, RoutedEventArgs e)
{
int addIndex = spread.ActiveSheet.ActiveRowIndex; // position where a new row will be added
int rowCount = 1; // Number of rows to add
spread.ActiveSheet.AddRows(addIndex, rowCount);
CopyRowsFormat(addIndex + 1, Enumerable.Range(addIndex, rowCount).ToList());
}
public void CopyRowsFormat(int rowFormatToCopy, List<int> copyToRows)
{
foreach(var copyToRow in copyToRows)
{
for (int col = 0; col < spread.ActiveSheet.Columns.Count - 1; col++)
{
var formatter = spread.ActiveSheet.Cells[rowFormatToCopy, col].Formatter;
if (formatter == null)
formatter = spread.ActiveSheet.Rows[rowFormatToCopy].Formatter;
if (formatter == null)
continue;
spread.ActiveSheet.Cells[copyToRow, col].Formatter = formatter;
}
}
}
Please refer to the same from attached sample. (see SpreadCellFormat.zip)
JFYI, this seems like a valid requirement so I have raised an enhancement request for the same. (Internal Tracking Id - SPNET-16131)
Best Regards,
Kartik
SpreadCellFormat.zip