Copy format from one row to another using c#

前端 未结 3 1682
抹茶落季
抹茶落季 2020-12-20 23:56

This question is quite similar to the one asked here. But the answer given suggests copying the format along with the data. I have a excel sheet (.xlsx) that I generate usin

3条回答
  •  一向
    一向 (楼主)
    2020-12-21 00:48

    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);
    

提交回复
热议问题