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
 Creating an 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

gspiga

3 Posts

Posted - 05/25/2012 :  3:04:29 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

greg

USA
1379 Posts

Posted - 05/25/2012 :  5:05:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.)
Go to Top of Page

gspiga

3 Posts

Posted - 05/25/2012 :  6:22:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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?
Go to Top of Page

gspiga

3 Posts

Posted - 05/25/2012 :  6:42:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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?
Go to Top of Page

greg

USA
1379 Posts

Posted - 05/30/2012 :  5:25:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
#include <origin.h>
plus your code
compile and run
works fine in 8.5 also
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