简体   繁体   English

如何将特定单元格(带有值、颜色、字体)从一个 excel 文件复制到另一个 excel 文件 C#?

[英]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如果您只想复制文本或格式(等),则将PasteSpecialCopy方法一起使用: 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.

相关问题 如何使用C#将一个Excel工作簿中特定范围的单元格复制到另一工作簿中 - how to copy cells from a specific range from one excel workbook to another workbook using c# 如何使用 C# 将选定列的所有行从一个 excel 文件复制到另一个文件 - How to copy all the rows of selected column from one excel file to another using C# 将特定的列从一个Excel电子表格复制到C#中的另一列 - Copy specific columns from one excel spreadsheet to another in C# 如何使用 C# 写入现有 Excel (xlsc) 文件中的特定单元格 - How to write to specific cells in an existing Excel (xlsc) file with C# 如何使用C#将Excel文件的特定单元格导入datagridview - How to import specific cells of an Excel file into datagridview using c# 如何使用C#渲染Excel单元格字体颜色? - How to render the Excel cells font color with C#? 如何从现有Excel文件的单元格中获取值? C# - How to get values from cells of an existing excel file? C# 如何在不打开c#winforms中的excel文件的情况下将excel工作表复制到另一个excel工作簿中? - How to copy excel worksheets Into another excel workbook without opening the excel file in c# winforms? c#-(Excel互操作)如何在VSTO中将一个工作表复制到另一工作簿? - c# - (Excel interop)How can I copy one worksheet to another workbook in VSTO? 有没有办法使用 C# 为 Excel 文件的选定单元格着色? - Is there a way to color selected cells of an Excel file using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM