Author |
Topic  |
|
ovince
Yugoslavia
Posts |
Posted - 10/09/2006 : 02:32:59 AM
|
Hello All,
I have several worksheets in the project. In each FOREACH loop I would like to use the first column of the worksheets to get 2 dataset and to create new worksheet with this two datasets as a columns.
I have two problems here:
1. Number of rows of newly created datasets is not the same and vary in loop. How to create worksheet with 2 columns of variable row numbers?
2. In the FOREACH loop I select to work with worksheets. How to avoid the newly created worksheets. I suppose this is not explained perfectly well so I will copy the code here
void make_hist() { foreach (PageBase pg in Project.Pages) { if( pg.GetType()==EXIST_WKS ) { Worksheet wks(pg.GetName()); //get datasets Dataset flux(wks, 0); Dataset T(wks, 8); //create new datasets for histogram Dataset hist1; hist1.Create(0,1); Dataset hist2; hist2.Create(0,1); //get the size of flux dataset int szFlux = flux.GetSize(); int jj1=0; int jj2=0; for(int ii = 0; ii<szFlux; ii++) { if (T[ii] <= 1) { hist1.Add(flux[ii]); jj1++; } if (T[ii] > 1) { hist2.Add(flux[ii]); jj2++; } }
NOW THE NEW WORKSHEET SHOULD BE CREATED THAT WILL CONTAIN hist1 AND hist2 AS A COLUMNS. ALL THIS BELLOW ARE DIFFERENT TRIES THAT FAILED TO WORK //LT_set_var("X", jj1); //LT_set_var("Y", jj2); //LT_execute("type $(X)\t$(Y);"); //LT_execute("create -wd jj1 aa jj2 bb;"); //Create a new worksheet for histogram result //WorksheetPage wpHist; //wpHist.Create("origin"); //get the name of the worksheet //string nameWpHist = wpHist.GetName(); //printf("%s\n",nameWpHist); //Worksheet wksResult(wpNewHist.Layers(0)); //LT_execute("win -ch 1;"); } } }
The newly created workseet should be 'hiden' from the FOREACH loop. I dont know how to do it also.
Thank you oliver
|
|
Deanna
China
Posts |
Posted - 10/09/2006 : 02:58:47 AM
|
For question 2, one solution is to save the names of the worksheet pages before creating new worksheets. Then instead of foreach loop, use for to loop over the old worksheets. For example:
uint iWksCount = Project.WorksheetPages.Count(); vector<string> vWksName(iWksCount); int ii = 0; foreach (WorksheetPage pg in Project.WorksheetPages) { vWksName[ii++] = pg.GetName(); } for (ii=0; ii<iWksCount; ii++) { string name = vWksName[ii]; out_str(name); Worksheet wks(name);
//Do something to wks... }
As for question 1, do you mean the two columns of the same worksheet should have different row numbers?
Deanna OriginLab Technical Services |
 |
|
ovince
Yugoslavia
Posts |
Posted - 10/09/2006 : 03:42:02 AM
|
hello Deanna,
Yes, the new worksheet should have 2 columns with different row numbers. this is where I add elements to datasets
int jj1=0; int jj2=0; for(int ii = 0; ii<szFlux; ii++) { if (T[ii] <= 1) { hist1.Add(flux[ii]); jj1++; }
if (T[ii] > 1) { hist2.Add(flux[ii]); jj2++; } } hist1 and hist2 datasets generaly do not have the same number of elements so the new worksheet will have 2 columns with different number of rows. In the first loop, lets say, 504 and 234, in the second loop 293 and 345 and so on.
oliver
oliver |
 |
|
Deanna
China
Posts |
Posted - 10/09/2006 : 04:08:23 AM
|
Well, all columns in the same worksheet should have the same number of rows. How about leaving some cells empty? For example, when one dataset has 504 elements and the other has 234, the row number of the worksheet should be set to 504. This will result in 270 empty cells in the second column. Is it acceptable?
Deanna OriginLab Technical Services |
 |
|
ovince
Yugoslavia
Posts |
Posted - 10/09/2006 : 04:20:00 AM
|
hi
well, I dont know. This worksheet I am creating is for overlaped histogram (program that you have written fewdays ago; do you remember). Will it work with null cels?
Making overlaped histogram in Origin manually works well with column of different number of rows. I hope it will work programmaticalt also because I have many workseets again
oliver |
 |
|
Deanna
China
Posts |
Posted - 10/09/2006 : 04:56:03 AM
|
I have just tested the program for overlap histogram on 2 columns with different numbers of elements. The result looks okay.
Please test it on your data. If any problem occurs, please tell me.
Deanna OriginLab Technical Services
Edited by - Deanna on 10/09/2006 05:01:55 AM |
 |
|
ovince
Yugoslavia
Posts |
Posted - 10/09/2006 : 07:39:43 AM
|
hi,
I steel don't know how to create worksheet from 2 datasets with different row numbers (please see the first letter). I have tried with this commands but does no work
//LT_set_var("X", jj1); //LT_set_var("Y", jj2); //LT_execute("type $(X)\t$(Y);"); //LT_execute("create -wd jj1 aa jj2 bb;");
jj1 and jj2 are row numbers of the newly created worksheet columns.
One mor question, how to hide the created worksheets?
Oliver
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/09/2006 : 08:53:33 AM
|
Hi Oliver,
It's not necessary to set the number of rows on creation. This will create a worksheet and assign datasets d1a and d2a to its columns regardless of the sizes of d1a and d2a. Then it will hide the worksheet...
Worksheet wks; wks.Create("Origin.otw"); Dataset d1b(wks,0); Dataset d2b(wks,1); d1b = d1a; d2b = d2a; wks.GetPage().Show(false); // hide worksheet
Mike Buess Origin WebRing Member |
 |
|
|
Topic  |
|