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 selection to layer
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

zorrax

China
5 Posts

Posted - 01/29/2013 :  04:05:52 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.6
Operating System: Win 7 64b

I would like to copy a selection range from one layer to another one.
I have found some other function to copy to another worksheet or page but not for layer.
what function can I use ?
thank u

Penn

China
644 Posts

Posted - 01/29/2013 :  05:03:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

From the inherit relationship, Worksheet class is actually a child-class of Layer class. And Layer class has three direct child-classes, Datasheet, GraphLayer, and Layout. Then, I am not sure the meaning of copying a selection range from one layer to another one, from Datasheet to Datasheet, or to GraphLayer, or to Layout, or other situation. So, better that you can provide more details on the meaning of "layer", and which function you have found to copy to another worksheet or page. Then I can figure out what you really want.

Penn
Go to Top of Page

zorrax

China
5 Posts

Posted - 01/29/2013 :  05:45:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thank you for your answer
I know that my question is not clear without example and I am not familiar with the different classes of originC

So I select some row of the sheet1 with this code
WorksheetPage wp = Project.WorksheetPages(0);
wks = wp.Layers(0);
bool bRet = wks.SetSelectedRange(vR1);

then I use the code to create a new page in the worksheetpage pg
int nn = wp.AddLayer(strNew);
Worksheet wks2 = wp.Layers(nn);

and I want to copy selected rows into the wks2
Go to Top of Page

zorrax

China
5 Posts

Posted - 01/29/2013 :  06:09:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have found my mistake
I create wks2 as a new one and not as a the wp.layer
Go to Top of Page

Penn

China
644 Posts

Posted - 01/30/2013 :  03:51:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can use the CopyTo method. Here is the example:

void copy_selected_rows()
{
	WorksheetPage wp = Project.WorksheetPages(0);  // workbook
	if(!wp)
		return;
	Worksheet wks = wp.Layers(0);  // first worksheet in workbook
	if(!wks)
		return;
	
	vector<int> vR1;  // the rows to be selected
	vR1.Add(5);  // indices of some rows to be selected
	vR1.Add(8);
	vR1.Add(14);
	vR1.Add(23);
	wks.SetSelectedRange(vR1);  // highlight the rows
	
	string strNew = "NewWks"; 
	int nn = wp.AddLayer(strNew);  // add a worksheet to workbook
	Worksheet wks2 = wp.Layers(nn);  // get the newly added worksheet
	if(!wks2)
		return;
	
	wks2.SetSize(vR1.GetSize(), wks.GetNumCols());  // set size of the new worksheet
	for(int ii = 0; ii < vR1.GetSize(); ii++)  // loop to copy the selected rows to the new worksheet
	{
		wks.CopyTo(wks2, 0, -1, vR1[ii], vR1[ii] + 1, 0, -1, CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS, ii);
	}
}


Penn
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