Copy format from one row to another using c#

▼魔方 西西 提交于 2019-11-29 14:09:13

You can use PasteSpecial with xlPasteFormats.

Excel.Range R1 = (Excel.Range)oSheet.Cells[11, 11];
R1.Copy(Type.Missing);

Excel.Range R2 = (Excel.Range)oSheet.Cells[15, 15];
R2.PasteSpecial(Excel.XlPasteType.xlPasteFormats,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);

So you want to copy format from first cell and apply it to all your sheet.

There is a way to process:

 Range sourceRange = sheet.get_Range("A1:A1");
 sourceRange.Copy();

 Range last = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing);
 Range destinationRange = sheet.get_Range("A1", last);

 destinationRange.PasteSpecial(XlPasteType.xlPasteFormats);

I use it as mickro explained and it worked perfectly!!!!!

                Range contentAlarms =exlWsheetAlarms.get_Range("A1:G"+countList);
                contentAlarms.Copy(Type.Missing);

                Range last = exlWsheetUlt.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing);
                Range destinationRange = exlWsheetUlt.get_Range("B90", last);

                destinationRange.PasteSpecial(XlPasteType.xlPasteFormats);

thanks!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!