The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Copy rows from one worksheet to another
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

smordi

Hungary
1 Posts

Posted - 03/10/2009 :  09:53:42 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
winXP Prof, Origin Pro 8

Hi,
I have two workbooks created. One is filled with ImportASCII, and now I want to copy all columns of, let's say row 10-230 to a new workbook.
The creation and the importing works fine, I just don't know how to copy it.
Probably possible with a lot of Datasets, but there must be an easier way as I want to copy ALL columns.

Thanks for any suggestions, I'm really lost here :)

Greetings from Budapest
Steffen

Laurie

USA
404 Posts

Posted - 04/01/2009 :  1:58:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

void Worksheet_CopyTo_Ex1()
{
    Worksheet wks = Project.ActiveLayer();
    if(wks)
    {    	
    	Worksheet wksDest;
    	wksDest.Create("origin");    	
 
    	int nC1 = 0, nC2 = wks.GetNumCols()-1; //want to copy all columns
    	int nR1 = 9, nR2 = 230; // want to copy rows 10-230 
    	int nDestC1 = 0; // copy data to destination worksheet start from the first column    	
    	DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS; // want to keep column format and designations with copied data
 
    	int nRet = wks.CopyTo(wksDest, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl); 
    	
    }
}


OriginLab Technical Support
Go to Top of Page

malkovich

Germany
14 Posts

Posted - 12/11/2009 :  05:36:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
WinXP pro., Origin 8G.0.63.988 SR6 v8.0988

I tried to use CopyTo to copy a row from one worksheet to another, but it does not work. It should copy six times one row. The function always returns "0", and copies one row of the source worksheet to the first row of the dest worksheet. Also it copies a row of the source wks to the "longname" row of the dest wks.
When I execute the example of Laurie Origin creates a new worksheet with the correct numbers of cols but not enough rows and copies nothing.

Any idea?
Go to Top of Page

Iris_Bai

China
Posts

Posted - 12/13/2009 :  8:52:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If you want to copy one row, for example, the first row in source worksheet, please set r1=0 and r2=1. r2 is the ending row index, default is -1 for last row and exclusive.


Iris
Go to Top of Page

malkovich

Germany
14 Posts

Posted - 12/14/2009 :  09:04:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Iris,

thanks for your reply. I tried this already but it does not work. The function CopyTo does not seem to work for me, no matter what parameters I use. The sample code Laurie posted does not copy the worksheet contents but only creates a new worksheet with the same numbers of comlumns as the current worksheet. The funtion is not described in the help files so I have no idea what I can try instead.
Go to Top of Page

Iris_Bai

China
Posts

Posted - 12/14/2009 :  9:44:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please take a look on the sample code Laurie posted above, nR2 = 230, if source worksheet not have 230 rows, CopyTo function will do nothing except prepare the number of column. This is bug, tracker as #14850, we should always copy data from nR1 to last row if nR2 over the number of rows of worksheet.

For now, you can set nR2 = -1, -1 means last row.

If still not work, please send your data file or *ogw file to us according to Sending a File to OriginLab Technical Support

Iris

Edited by - Iris_Bai on 12/15/2009 12:48:25 AM
Go to Top of Page

malkovich

Germany
14 Posts

Posted - 12/15/2009 :  05:44:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris,

thank you for your help, it works now.
But one more question: I want to specify the row of the destination worksheet to copy different rows of the source wks to consecutive rows of the destination wks.
I modified the code to:


void Worksheet_CopyTo_Ex2(int Row1 = 0, int Row2 = 1)
{
    Worksheet wksSrc, wksDest;
    if( wksSrc.Attach("Book1") && wksDest.Attach("Book2") )
    {    	
    	int nC1 = 0, nC2 = wksSrc.GetNumCols()-1; //want to copy all columns
    	int nR1 = Row1, nR2 = Row2; // want to copy rows 10-230 
    	int nDestC1 = 0; // copy data to destination worksheet start from the first column    	
    	DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS; // want to keep column format and designations with copied data
 
    	int nRet = wksSrc.CopyTo(wksDest, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl); 
    }
    else
    {
    	out_str("error attaching worksheets");
    }
}


I first create two Workseets "Book1" and "Book2", type some numbers into cells of Book1 and then execute the function.

Now I need a parameter to copy first Book1 row 1 to Book2 row 1 and the let's say Book1 row 3 to Book2 row 2 and so on.
How can I do this?

Greetings and Thanks in advance
Go to Top of Page

additive

Germany
109 Posts

Posted - 12/15/2009 :  2:11:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks to OriginLab, they've updated the CopytTo method in version 8.1 SR0.
You can set the destination row using the optional argument nDestR1:

int CopyTo( Worksheet & wksDest, int nC1, int nC2, int nR1, int nR2, int nDestC1, int nLNRow = -1, 

   DWORD dwCntrl = CPYT_EXTERN_UPDATE_ORIGIN, int nDestR1 = 0, vector<int>* pvnLabelTypes = NULL )


Hope this helps!

Michael
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000