Copy format from one line to another using C #

This question is very similar to the one asked here . But the answer above suggests copying the format along with the data. I have an excel sheet (.xlsx) that I generate using SSIS. Now I set the formatting in the first line, which I want to copy to all the lines that are already filled in the sheet. How can I do this using C #? I am using Excel.

+4
source share
3 answers

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); 
+8
source

So, you want to copy the format from the first cell and apply it to your entire sheet.

There is a processing method:

  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); 
+2
source

I use it, as mickro explained, and it works great !!!!!

  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!

0
source

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


All Articles