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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 array of worksheets

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
edsger Posted - 01/20/2005 : 12:25:48 PM
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.

3   L A T E S T    R E P L I E S    (Newest First)
edsger Posted - 01/31/2005 : 03:39:31 AM
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
Mike Buess Posted - 01/28/2005 : 11:32:15 AM
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
Mike Buess Posted - 01/20/2005 : 3:08:22 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000