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
 add columns(>=3) to worksheet and fill data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jeson fon

China
3 Posts

Posted - 08/04/2012 :  8:40:15 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):OriginPro 8 SR0 v8.0725(B725)
Operating System:Win7

Hi,
Every super programmer,there a problem about worksheet column.

void fillColumns()
{
Dataset s1;
//specify wks, col num:
if (s1.Attach("data1", 0))
{
s1.SetSize(100);
for (int ii = 0; ii < 100; ii++)
s1[ii] = ii;
}
//specify data set name:
if (s1.Attach("data1_b"))
{
s1.SetSize(100);
for (int ii = 0; ii < 100; ii++)
s1[ii] = ii^2;
}
}

Now,I want to add third column or more column and fill value,would you tell me how can I do.
Thanks.

Jeson Fon

rlewis

Canada
253 Posts

Posted - 08/04/2012 :  10:08:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try Something like ...

void DoSomeStuff()
{
	Worksheet Wks=Project.ActiveLayer();
	if (Wks.IsValid()==true)
	{
		Dataset s1;
		if (s1.Attach(Wks, 0))
		{
			s1.SetSize(100);
			for (int ii = 0; ii < 100; ii++)
			s1[ii] = ii;
		}

		if (s1.Attach(Wks,1))
		{
			s1.SetSize(100);
			for (int ii = 0; ii < 100; ii++)
			s1[ii] = ii^2;
		}
		
		int jCol=Wks.AddCol();
		if(jCol>=0)
		{
			if(s1.Attach(Wks,jCol))
			{
				// Add code for filling column attached to dataset s1
			}
		}
	}
	
}

Edited by - rlewis on 08/05/2012 04:54:47 AM
Go to Top of Page

jeson fon

China
3 Posts

Posted - 08/06/2012 :  11:18:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
rlewis,thanks you for your help,but failed.eg:

void DoSomeStuff()
{
	Worksheet Wks=Project.ActiveLayer();
	if (Wks.IsValid()==true)
	{
		Dataset s1;
		if (s1.Attach(Wks, 0))
		{
			s1.SetSize(100);
			for (int ii = 0; ii < 100; ii++)
			s1[ii] = ii;
		}

		if (s1.Attach(Wks,1))
		{
			s1.SetSize(100);
			for (int ii = 0; ii < 100; ii++)
			s1[ii] = ii^2;
		}
		
		int jCol=Wks.AddCol();
		if(jCol>=0)
		{
			if(s1.Attach(Wks,jCol))
			{
			 s1.SetSize(100);
			 for (int ii = 0; ii < 100; ii++)
			 s1[ii] = sqrt(ii);            // Add code for filling column attached to dataset s1
			}
		}
	}
	
}

Is the red code wrong?

Jeson fon
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 08/07/2012 :  12:19:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I compiled and ran the code you posted and it worked just fine ...
Go to Top of Page

jeson fon

China
3 Posts

Posted - 08/07/2012 :  12:28:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Oh£¬could the version problem?
Origin Ver. and Service Release (Select Help-->About Origin):OriginPro 8 SR0 v8.0725(B725)
Operating System:Win7

It dosn't work in my computer,
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 08/07/2012 :  12:37:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have Origin-Pro8.0 SR6 installed on a Win-XP machine ...
Try Help - Check for updates to update your Origin-Pro to the most up to date Service release for 8.0
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