Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Apr 25, 2024 4:58 am

I am using FreeSpire 14.2 version

My C# code concatenates data of two excel files - "file" and "finalFilePath". As a result, the final file will contain combined data in Sheet1.

Code: Select all
Workbook finalWorkbook = new Workbook();
finalWorkbook.LoadFromFile(finalFilePath);
Worksheet finalWorkSheet = finalWorkbook.Worksheets[0];

Workbook workbook = new Workbook();
workbook.LoadFromFile(file);
Worksheet sheet = workbook.Worksheets[0];

Spire.Xls.CellRange sourceRange = sheet.AllocatedRange;
Spire.Xls.CellRange destRange;
destRange = finalWorkSheet.Range[finalWorkSheet.LastRow + 1, 1];

sourceRange.Copy(destRange,true);


The concatenated data saved properly in final xlsx file. However, when I navigate through cells, it does not show correct CellValue for any row. Instead, it shows incrementing numbers like 1, 2, 3 in CellValues of a row.

How can I copy data along with correct CellValue ?

anil_soman
 
Posts: 1
Joined: Thu Apr 25, 2024 4:51 am

Thu Apr 25, 2024 6:34 am

Hi,

Thanks for your inquiry.
According to the messages you provided, I tested the your code with two simple excel files and find that the final file contain correctly combined data in Sheet1.
Sorry for that I don’t understand your issue that it shows incrementing numbers like 1, 2, 3 in CellValues of a row. Could you share some screenshots to show your issue? In addition, you can use our latest commercial version (Spire.Xls for Net 14.3.3) to test this scenario.


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS