[英]How to copy format of one row to another row in Excel with c#
我正在使用C#將數據插入Excel。 每當我使用C#向Excel添加新行時,我都希望與上一行具有相同的格式,即以編程方式將顏色,字體和背景顏色全部設置為彩色。
這是OLEDB插入物。
插入后,我想將第一行的格式應用於第二行。 使用UI中的格式畫器是一項簡單的工作,我找不到使用C#做到這一點的方法。
1)首先,您需要獲取要復制的范圍,例如RngToCopy 2)然后設置要插入的范圍。 3)使用下面提到的代碼段。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.