Spire.XLS for .NET is a professional Excel .NET component that can be used to any type of .NET 2.0, 3.5, 4.0 or 4.5 framework application, both ASP.NET web sites and Windows Forms application.

Thu May 10, 2012 9:22 am

Hallo,

i want to try copy rows. At first i insert a new row with
Code: Select all
worksheet->InsertRow(range->row + 1 , range->LastRow);

Can I copy all Datas from range into new Row?

Thanks in advance and Have a nice day !

Lars

lameb
 
Posts: 10
Joined: Mon Feb 20, 2012 2:39 pm

Fri May 11, 2012 7:44 am

Hi lameb,

We have solved your problem of rows copying. Below are the steps and codes to solve it, please have a try.
1, Locate the source rows which need to be copyed.
2, Insert same number of target rows in a new position.
3, Copy data from the source rows to the target row.

Code: Select all
using Spire.Xls;

namespace XlsCopyRows
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\MiscDataTable.xls");

            Worksheet worksheet = workbook.Worksheets[0];
            int firstColumn = worksheet.FirstColumn;
            int lastColumn = worksheet.LastRow;
            int firstRow = worksheet.FirstRow;
            int lastRow = worksheet.LastRow;
            //rows count
            int copyRows = lastRow - firstRow + 1;
            //insert rows count
            worksheet.InsertRow(lastRow + 1, copyRows);
            CellRange originDataRang = worksheet.Range[firstRow, firstColumn, lastRow, lastColumn];
            CellRange targetDataRang = worksheet.Range[lastRow + 1, firstColumn, lastRow + 1, lastColumn];
            worksheet.Copy(originDataRang, targetDataRang, true);

            workbook.SaveToFile("Sample.xls");
            try
            {
                System.Diagnostics.Process.Start(workbook.FileName);
            }
            catch
            {
            }
        }
    }
}

It works fine on my side. But if there is something not smooth on your side, Please do not hesitate to contact us for anything at any time.

Regards
Eric
e-iceblue support
Attachments
MiscDataTable.zip
(2.5 KiB) Downloaded 268 times

Eric
 
Posts: 17
Joined: Tue Apr 24, 2012 4:53 am

Wed May 16, 2012 8:23 am

Hi Eric,

Thank you for your suggested solution.
The coding works.

Best Regards,
Lars

lameb
 
Posts: 10
Joined: Mon Feb 20, 2012 2:39 pm

Thu Jun 28, 2012 3:41 am

Please feel free to contact us for anything at any time. Have a great day!
e-iceblue support
User avatar

iceblue support
 
Posts: 240
Joined: Tue Dec 21, 2010 2:56 am

Return to Spire.XLS