I'm trying to copy a cell's style to another cell using Excel-DNA library and the copy process will be made through a button from ribbon.
I defined a public class RibbonController : ExcelRibbon with:
public override string GetCustomUI(string RibbonID)
{
return $@"
<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='tab1' label='my tools'>
<group id='group1' label='Test'>
<button id='playBtn' label='Import JSON' onAction='OnButtonPressed'/>
</group >
</tab>
</tabs>
</ribbon>
</customUI>";
}
and
public void OnButtonPressed(IRibbonControl control)
{
Microsoft.Office.Interop.Excel.Application excelFile = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
Worksheet sheet = excelFile.Worksheets["Sheet1"];
sheet.Cells[2,2].Style = sheet.Cells[1,1].Style;
}
The cell from row 1 and column 1, has bold and foreground color.
How do I copy the entire style to cell from row 2 and column 2 ?
Seems that assigning Style property is not enough because the style is not applied.