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

edsger

Netherlands
Posts

Posted - 01/20/2005 :  12:25:48 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version 7.5SR4:
Operating System: win xp pro sp1

Dear all, this may be a trivial question.

I have a worksheet which I want to split up (row wise) in a certain amount of segments (only known after compilation). for this I would like to create an array of worksheets or at least dynamically add worksheets to the project and adress them. I have tried some stuff but it doesn't seem to be working. If anyone has a solution I would love to hear it.

thanks in advance.

Mike Buess

USA
3037 Posts

Posted - 01/20/2005 :  3:08:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm sure there are several ways to do that but the following method might get you started. It copies an existing worksheet to a matrix, dices the matrix nRows at a time into a submatrix and passes the submatrix to a function which creates a worksheet. In your case it might not be convenient to use a matrix but the general method used to create worksheets might be helpful.

void split_wks(string sWksName, int nRows)
{
Worksheet wks(sWksName);
matrix mm();
mm.CopyFromWks(wks);
matrix mx;
int i,j;
for(i=0;i<mm.GetNumRows()/nRows;i++)
{
j = i*nRows;
mm.GetSubMatrix(mx,0,-1,j,j+nRows);
new_wks(mx);
}
}
void new_wks(matrix mx)
{
uint cc = mx.GetNumCols();
WorksheetPage wp;
wp.Create("Origin.otw");
Worksheet wks(wp.GetName());
Dataset dd;
for(int i=0; i<cc; i++)
{
if(i>1)
wks.AddCol();
dd.Attach(wks,i);
mx.GetColumn(dd,i);
}
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/20/2005 3:12:30 PM

Edited by - Mike Buess on 01/20/2005 3:30:03 PM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/28/2005 :  11:32:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
My previous post did not really answer your question which, if I understand correctly, was about how to create a dynamic array of worksheets. I don't believe that's possible, but you can create a (string)array of worksheet names as shown below. The lines that are commented out attempt to create a static array of worksheets, which I would have thought possible. However, Origin 7.5SR5 crashes on execution when I include that code. Since it compiles OK I'm not sure what's going on there.
void split_wks(string sWksName, int nRows)
{
Worksheet wks(sWksName);
StringArray sa;
matrix mm,mx;
mm.CopyFromWks(wks);
string sName;
int i,j;
for(i=0;i<mm.GetNumRows()/nRows;i++)
{
j = i*nRows;
mm.GetSubMatrix(mx,0,-1,j,j+nRows);
sName = new_wks(mx);
if( !sName.IsEmpty() )
sa.Add(sName);
}

for(i=0;i<sa.GetSize();i++)
test_stringarray(sa[i]);

//Worksheet wa[10];
//int nWks = sa.GetSize() > 10 ? 10 : sa.GetSize();
//for(i=0;i<nWks;i++)
//wa[i].Attach(sa[i]);
}
string new_wks(matrix mx)
{
uint cc = mx.GetNumCols();
WorksheetPage wp;
wp.Create("Origin.otw");
Worksheet wks(wp.GetName());
if( !wks )
return "";
Dataset dd;
for(int i=0; i<cc; i++)
{
if(i>1)
wks.AddCol();
dd.Attach(wks,i);
mx.GetColumn(dd,i);
}
return wp.GetName();
}
void test_stringarray(string wksName)
{
Worksheet wks(wksName);
if( wks )
out_str(wksName);
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/28/2005 1:05:23 PM
Go to Top of Page

edsger

Netherlands
Posts

Posted - 01/31/2005 :  03:39:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Well I more or less resolved the problem by modifying you code as follows. By returning a string with the name of the new worksheet I am able to place it in a loop where it adds the worksheet and performs a couple of operations


string subWorksheet(string sWksName, int startRow, int endRow) {
Worksheet wks(sWksName);
matrix mm();
mm.CopyFromWks(wks);
matrix mx;
string wpName;

mm.GetSubMatrix(mx,0,-1,startRow,endRow);
wpName = new_wks(mx);

return wpName;
}

string new_wks(matrix mx) {
uint cc = mx.GetNumCols();
WorksheetPage wp;
wp.Create("Origin.otw");
Worksheet wks(wp.GetName());
Dataset dd;

for(int i=0; i<cc; i++){
if(i>1)
wks.AddCol();

dd.Attach(wks,i);
mx.GetColumn(dd,i);
}

return wp.GetName();
}



Edsger
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