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
 Creating an 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
gspiga Posted - 05/25/2012 : 3:04:29 PM
Hi All,

I am trying to import and process multiple sets of data at the same time. My goal is to import all of them in different worksheets (to keep things neat later on), with each worksheet attached to a layer of a worksheet page. In this way, each dataset should appear in a different "tab" of the worksheet.

My problem is that the number of files I have to import changes everytime. Therefore, my guess is that I need to create a dynamic array of Worksheets, which I then attach to different layers. Somehow, I haven't found a way of doing it that actually works. My code so far is:


void testmain(){
	//get input files
	StringArray inputFiles;
	string importfile;
	int numFiles = GetMultiOpenBox(inputFiles,"[Curve Data (*.TXT)] *.TXT", "C:\Users\Desco\SFU\Thesis\Lumerical\Sims\Curves");
	
	//open a new project
	Project MyProj;
	MyProj.Open();
	
	//Create a new worksheet page
	WorksheetPage wkspage();
	wkspage.Create();
	wkspage.Rename("Raw Data",FALSE,TRUE);
	wkspage.Layers(0).Delete();
        Worksheet wks;
 
	
	ASCIMP ai;
	
	//For every input file, create a new worksheet layer, and the associate worksheet handler
	string name;
	for (int i=0; i<numFiles; i++){	
		name=GetFileName(inputFiles[i],TRUE);
		name.Delete(11,5);
		int index = wkspage.AddLayer(name,CREATE_NO_DEFAULT_TEMPLATE );
		wks=wkspage.Layers(index);
		//add columns and get indexes
		int lambdaIdx=wks.AddCol("Wavelength");
		int transIdx = wks.AddCol("Transmission");
		if (0 == AscImpReadFileStruct(inputFiles[i],&ai)){
    		if(0 == wks.ImportASCII(inputFiles[i], ai))
        		out_str("Import data successful: "+inputFiles[i]);

		}
		//problem...the last worksheet is getting displayed on all three layers
		
	}
	
}	


As you can see from the comment, since I'm effectively "recycling" the worksheet wks, I end up with all layers showing the same data (specifically, that of the file which was imported last).

Can anybody suggest a better way of doing this?

Thanks a million, and Cheers!

Gianmarco
4   L A T E S T    R E P L I E S    (Newest First)
greg Posted - 05/30/2012 : 5:25:19 PM
#include <origin.h>
plus your code
compile and run
works fine in 8.5 also
gspiga Posted - 05/25/2012 : 6:42:52 PM
Update: I just downloaded an evaluation version of Origin 8.6, tried the same code and got the same result (all the worksheets have the last worksheet's data). I wonder what we are doing different.
Greg, did you have any special includes in your file?
gspiga Posted - 05/25/2012 : 6:22:32 PM
Thanks Greg,
I am using 8.5.0, which might be the reason for my issue. Also, I just discovered that I cannot make dynamic worksheet arrays in my version (e.g.
Worksheet * wksArr = new Worksheet[n]()
compiles but gives a de-referencing error during runtime.

Do you know if this has been fixed in 8.6?
greg Posted - 05/25/2012 : 5:05:37 PM
I tried your code in Origin 8.6 and it was working properly. In my case I selected five files and got five worksheets each with the correct data.
What version of Origin are you using? (Check Help : About Origin for the exact version number.)

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