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.

Mon Oct 12, 2020 6:35 pm

I have two per-existing workbooks. I need to copy data from Workbook1.Sheet1 to Workbook2.Sheet3. What is the syntax in Spire.xls?

What I am wanting to do...

WB1.S1 Copy Range ("A1:D100") to WB2.S3.Range("M1:P100")

Thanks.

skyfox1964
 
Posts: 9
Joined: Sun Oct 11, 2020 2:30 pm

Tue Oct 13, 2020 7:11 am

Hi,

Thanks for your inquiry.
Please refer to following code:
Code: Select all
            Workbook workbook1 = new Workbook();
            workbook1.LoadFromFile(FilePath + @"23089-1.xlsx");
            Worksheet sheet1 = workbook1.Worksheets[0];

            Workbook workbook2 = new Workbook();
            workbook2.LoadFromFile(FilePath + @"23089-2.xlsx");
            Worksheet sheet2 = workbook2.Worksheets[2];
            //copy range
            sheet1.Range["A1:D100"].Copy(sheet2.Range["M1:P100"], true, true);

            workbook2.SaveToFile("T23089.xlsx", ExcelVersion.Version2013);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS