I want to bring the cell format above as it is

Hi, Syncfusion Teams


As in the title, I want to copy the format of the cell above in Excel as it is.

(The same role as 'ctrl + D' in Excel.)


1 Reply

RS Ramya Sivakumar Syncfusion Team February 10, 2022 11:51 AM UTC

Hi TaeWook, 

Greetings from Syncfusion. 

The CopyTo option is used to copy the cells from source range to destination range. Please use the following code snippet to copy the cell format and let us know if this is helpful. 
 
Code snippet: 
using (ExcelEngine excelEngine = new ExcelEngine()) 
{ 
    //Instantiate the Excel application object 
    IApplication application = excelEngine.Excel; 
 
    //Assigns default application version 
    application.DefaultVersion = ExcelVersion.Xlsx; 
 
    //Load the file into stream 
    FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open); 
 
    //Loads or open an existing workbook through Open method of IWorkbooks 
    IWorkbook workbook = application.Workbooks.Open(inputStream); 
 
    //Access first worksheet from the workbook 
    IWorksheet worksheet = workbook.Worksheets[0]; 
                                 
    //Copy the cell format 
    worksheet.Range["A5"].CopyTo(worksheet.Range["A6:A10"]);                 
 
    FileStream stream = new FileStream("Style.xlsx", FileMode.Create, FileAccess.ReadWrite); 
    workbook.SaveAs(stream); 
    stream.Dispose(); 
}  

Please refer the following link to know more about the copy or move a range. 

Regards, 
Ramya. 


Loader.
Up arrow icon