[英]How can I copy specific cells(with Value,Color,Font) from one excel file to another excel file C#?
Here I have used this code from copying cells from one excel file to another.在这里,我使用此代码将单元格从一个 Excel 文件复制到另一个。 But it take lot of time.
但这需要很多时间。
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10;j++) {
xlWorkSheet.Cells[i, j].style.Font.Color = ws.Cells[i, i].style.Font.Color;
xlWorkSheet.Cells[i, j].Interior.Color = ws.Cells[i, i].Interior.Color;
xlWorkSheet.Cells[i, j] = ws.Cells[i, i];
}
}
Is there any other method available?有没有其他方法可用?
Follow the documentation: Range.Copy method遵循文档: Range.Copy 方法
If you would like to copy only text or formatting (etc.), then use PasteSpecial
together with Copy
method: Range.PasteSpecial如果您只想复制文本或格式(等),则将
PasteSpecial
与Copy
方法一起使用: Range.PasteSpecial
Usage:用法:
//define cells (range) to copy
Excel.Range from = srcworkSheet.Range["A1:D100"];
//define destination range
Excel.Range to = destworkSheet.Range["A1"];
from.Copy(to);
//this should also works:
//xlWorkSheet.Cells[i, j].Copy(ws.Cells[i, j]);
Good Luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.