How to copy format of one line to another line in Excel using C #

I am inserting data in Excel using C #. Whenever I add a new line in Excel using C #, I want the program code to have the same format as above, for example, color, font and background color.

This is an OLEDB insert.

Post insert, I want to apply the format of the first line to the second line. With the artist format from the UI, this is a simple job, I cannot find a way to do the same with C #.

+4
source share
1 answer

1) First you need to get the range that you want to copy, for example. RngToCopy 2) Then set the range you want to paste into. 3) use the code snippet below.

Range RngToCopy = ws.get_Range(StartCell, EndCell).EntireRow; Range RngToInsert = ws.get_Range(StartCell, Type.Missing).EntireRow; oRngToInsert.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, oRngToCopy.Copy(Type.Missing)); //ws is the worksheet object, set StartCell and EndCell as per your requirement 
+6
source

Source: https://habr.com/ru/post/1492016/


All Articles