Copy Rows

Technical support for Spire.XLS

Moderators: iceblue support, Flash, Manager

Copy Rows

Postby lameb » 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

Re: Copy Rows

Postby Eric » 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 235 times
Eric
 
Posts: 17
Joined: Tue Apr 24, 2012 4:53 am

Re: Copy Rows

Postby lameb » 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

Re: Copy Rows

Postby iceblue support » 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: 244
Joined: Tue Dec 21, 2010 2:56 am


Return to Spire.XLS

Who is online

Users browsing this forum: No registered users and 1 guest