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
 Help manipulating worksheet columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cyantist

USA
8 Posts

Posted - 02/23/2010 :  08:25:13 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 7.5
Operating System: Windows XP

I'd like to automate the following task and would need some help:

I need to move specific columns from 1 worksheet to new (created or existing)worksheets. For example, if in the main worksheet, I have 5 columns, I'd like to distribute each of the 5 columns into designated columns in separate worksheets, thereby creating 5 new worksheets. I will have more than 1 column from the main worksheet that needs to be distributed and copied amongst the newly created worksheets, i.e., each newly created worksheet will have several columns of data copied from the main worksheet.

In summary:

Need to move Columns ABCXYZ in Main Worksheet to --

Col A and Col X --> New Worksheet 1
Col B and Col Y --> New Worksheet 2
Col C and Col Z --> New Worksheet 3

Thanks in advance for your kind help.

TreeNode

64 Posts

Posted - 02/24/2010 :  07:22:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi cyantist,

I found a very simple way to do it, in case you want to distribute
the columns in new created worksheets.
I think its not the best way to do this, but searching in a rush I didnt find a better
way yet.


void distribute_columns_ex()
{
	WorksheetPage wpMain;
	Worksheet wksMain, wks1, wks2, wks3;
	
	// main Worksheet must be activated
	wpMain = Project.Pages();	// --> activatetd book 
	wksMain = wpMain.Layers();	// --> activated sheet
	
	// create new worksheets and delete needless columns
	wks1.CreateCopy(wksMain);
	wks1.DeleteCol(2);	// after deleting column with index 2 (third column)
	wks1.DeleteCol(2);	// the next columns update there index
	wks1.DeleteCol(2);
	wks1.DeleteCol(2);
	
	wks2.CreateCopy(wksMain);
	wks2.DeleteCol(1);
	wks2.DeleteCol(2);
	wks2.DeleteCol(2);
	wks2.DeleteCol(3);
	
	wks3.CreateCopy(wksMain);
	wks3.DeleteCol(1);
	wks3.DeleteCol(1);
	wks3.DeleteCol(3);
	wks3.DeleteCol(3);
}


I tested this with a Workbook with one Worksheet, which had 7 columns.
First column was X-designated holding row index. The other 6 columns had sample data
random numbers).

So if you just want do distribute the columns of a Worksheet into new created ones,
this shows a very simple way. Probably its not the nicest one, but who cares...? ;D

But if you want to distribute the columns to existing Worksheet, you cant do it
like that.
I searched for a way to just add a Column object to an existing Worksheet. So
that you could do something like this:


{
	...

	Column col;
	col.Attach( wksMain.GetName(), index );

	wks1.AddCol( col ); // this is not supported, but would be nice...

        ...
}


When I find a better way to do things like that, I will let you know.


|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page

cyantist

USA
8 Posts

Posted - 02/24/2010 :  09:56:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Fantastic, thanks TreeNode! :)
Go to Top of Page

arsk

USA
5 Posts

Posted - 01/22/2011 :  05:53:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Treenode, I must also say thanks to you because you have helped me also in a way when you posted this answer for Cyantist. I was also having great trouble in solving it. But your answer was a life saver for me. Thanks a lot again for your kind help.

Hello
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