简体   繁体   中英

Copy specific columns from one excel spreadsheet to another in C#

I have been trying to make a simple app to merge information from one excel spreadsheet to another in c#. But I don't find any reference about how could I do this.

enter image description here

I have the info in one spreadsheet and I need to copy that information in another spreadsheet file.

enter image description here

How can do this? Thanks in advance.

Here is another thing you may want to try out (the code uses GemBox.Spreadsheet library ):

ExcelFile source = ExcelFile.Load("Source.xlsx");
ExcelColumn sourceColumn = source.Worksheets[0].Columns[0];

ExcelFile destination = ExcelFile.Load("Destination.xlsx");
ExcelColumn destinationColumn = destination.Worksheets[0].Columns[0];

int count = source.Worksheets[0].Rows.Count;
for (int i = 0; i < count; i++)
    destinationColumn.Cells[i].Value = sourceColumn.Cells[i].Value;

destination.Save("Destination.xlsx");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM