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
 Origin Forum
 Scripting: Load Files and changes on the Worksheet
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mattse123

Germany
3 Posts

Posted - 11/07/2017 :  06:07:44 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hey, i just got a brief question about an issue i did not find an answer after around 2 days of searching in origin-forums.

The Situation is the following: I work in the field of organic photovoltaics, where i generate multiple measurement files.
I want to automatically import the files into one worksheet - for the first file, the first and the second column should be imported as x and y values.
For all following files, only the second column should be imported as y-values.
I did already succeed with that, using the following Code:



string fns, path$ = "C:\Users\myname\Desktop\OriginTest\"; 
	findfiles f:=fns$ ext:="*.dat";
	int numFiles = fns.GetNumTokens(LF);

	
	for(int ifile = 1; ifile <= numFiles; ifile++){
		
		if(ifile==1){
			string strToken$ = fns.GetToken(ifile)$;
			strToken$=;
			impasc fname:=strToken$ 
			
			options.PartImp.Partial:=0
			options.PartImp.FirstCol:=2
			options.Sparklines:=0
			options.Names.AutoNames:=0
			options.Names.FNameToSht:=1
			options.ImpMode:=1
			options.Miscellaneous.LeadingZeros:=1;
	
		}
		
		else if(ifile>1){
			string strToken$ = fns.GetToken(ifile)$;
			strToken$=;
			impasc fname:=strToken$ 
			
			options.PartImp.Partial:=1
			options.PartImp.FirstCol:=2
			options.Sparklines:=0
			options.Names.AutoNames:=0
			options.Names.FNameToSht:=1
			options.ImpMode:=1
			options.Miscellaneous.LeadingZeros:=1;
	
		}
		
	}


The problem i have now is the following: I want to import only the rows until let's say the last row minus 10 rows. How can i find out how many rows my worksheet has? I only found out the worksheet-commands like:


WorksheetPage wp;
wp.Create("Origin");
	
	
	Worksheet wks(wp.Layers(0));
	
	int nRows = wks.GetNumRows();


But when i simply use the impASC-command, i don't have a worksheet-object to work on. Can i internally cast the imported data to a worksheet-object, so to use the GetNumRows()-command on it?

________________

I hope i explained my Problem in an understandable manner. Thank you for your help in advance.

Edited by - mattse123 on 11/07/2017 06:12:14 AM

greg

USA
1378 Posts

Posted - 11/07/2017 :  3:25:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Not sure what you want with the "minus 10 rows", but there are two row properties in Origin:

// The number of displayed rows in the active worksheet
DisplayRows = wks.nrows;

// The number of rows of data in a column
range ra = [Book1]Sheet1!2; // Second column
DataRows = ra.GetSize();

So you could try:
impasc fname:=strToken$
options.PartImp.Partial:=1
options.PartImp.FirstCol:=2
options.PartImp.LastRow:=$(DataRows - 10)
options.Sparklines:=0
options.Names.AutoNames:=0
options.Names.FNameToSht:=1
options.ImpMode:=1
options.Miscellaneous.LeadingZeros:=1;
for example.

There is no hope!
(But I may be wrong.)
Go to Top of Page

mattse123

Germany
3 Posts

Posted - 11/08/2017 :  08:17:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

first of all, thank you for your answer. It already helped me in a way. I know now that i can acces the imported Data simply by the

wks. ****

commands.

All i need to do now is to check if a row is filled with only zero-entries. Is there a method to acces the value of an element within the worksheet? If that's possible, i can simply check it with a double-for loop and delete the rows filled with zero-entries.

Go to Top of Page

mattse123

Germany
3 Posts

Posted - 11/09/2017 :  06:45:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey there, i tried to acces an element in an array now with the syntax:



double temp2 =%(col(2)[50]$);



which shows me the entry at this position in the current worksheet. Still and surprisingly, i cannot access the element as soon as i start working with variables, like



double temp2 =%(col(i)[j]$);



Can somebody explain which mechanic lies behind this? It seems completeley odd to me at the moment.
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