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