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
 [Solved] Again: How to _really_ delete rows?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hofmaale

20 Posts

Posted - 11/03/2015 :  03:51:06 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

this has been asked a few times in the forums, but unfortunately nothing seems to suit my needs. It's a mere cosmetic problem though, not a show stopper, but I'll ask anyway...

I have a custom import script importing binary data created by one of our measurement setups. The software stores raw measurement data, which is a good thing (full precicion data import instead of some truncated text floating-point representation), but it also exports the last set of "garbage" from the last incomplete frame.

I can find those rows which are always at the end of the worksheet, and now I want to delete them after the import. So far I tried:

  • Use Worksheet.DeleteRows() in OriginC directly on the worksheet. It deletes the data, but leaves the rows there.
  • Call Worksheet.LT_execute with mark -d on either a predefined range or the -begin a -end b notation
  • manually deleted the rows using the "Delete"-Option in the context menu


Unfortunately, only the manual version "really" deletes the rows, i.e. removes them from the worksheet. Also, the [DEL] key has a different effect. This does not have any impact on further work with the data, but it's a bit uncomfortable (for example if you want to scroll down to the end, you see only empty rows).

I know that I can configure the template to hide empty rows at the end, but this is only a workaround for me (it hides them, and does not delete, see http://www.originlab.com/forum/topic.asp?TOPIC_ID=18135).

So, is there a way to programmatically mimic the context-menu function of really deleting, i.e. removing, rows at the end of a worksheet? Ideally with direct worksheet manipulation; although something like a "Makro-Style" Mark&Execute is also ok (i.e. telling Origin to select the rows and then execute the Menu-Command "Delete").

Thanks in advance,

Alex


Origin Ver. and Service Release: 2015G Sr1
Operating System: Win 7 x64

Edited by - hofmaale on 11/03/2015 06:47:37 AM

kubra

Slovakia
10 Posts

Posted - 11/03/2015 :  04:44:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Alex

If your ending rows are completely empty, maybe you should try just upload data, and run script, that goes through every row, rewrites them to new worksheet, and stops, when it hits the empty rows.

Maybe something like this:

#include <Origin.h>
#include <okocUtils.h>
void flip(){
        Worksheet wks = Project.ActiveLayer();
	int nmbRows = wks.GetNumRows(); 
	int nmbCols = wks.GetNumCols();
	Worksheet newWks;
	int nAutoAddRows = 0;
	int R;
	int C;
	okoc_create_workbook(&newWks, "Book", "Sheet", CREATE_VISIBLE, 10 ,nmbCols, nAutoAddRows);
	for(R=0; R<=nmbRows-1; R++){
		if(!is_missing_value(wks.Cell(R,0))){
			for(C=0; C<=nmbCols-1; C++){
				newWks.SetCell(R, C, wks.Cell(R,C));
			}			
		}
		if(is_missing_value(wks.Cell(R,0))){
			break;
		}
	}
	wks.Destroy(0);
}


I also have a sheet (1000X3), and there are only 230 rows with values, rest is empty. This code works good and fast for it. If you have empty rows between values, only delete break command. That "10" is just beginning number of rows, nAutoAddRows will automatically add new row, only if needed (so no empty rows at the end).

I know, it is not proper solution by one command, but I haven´t found proper deleteRow command either. Maybe someone will know better solution.

I hope, i helped a little bit.

Have a nice day
Branislav

Edited by - kubra on 11/03/2015 04:46:39 AM
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 11/03/2015 :  05:23:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

You can active the sheet after importing and try the LabTalk script below:

wks.nRows=wks.maxRows;  //set the worksheet row number= the largest row index that has value

Best regards!
Jason
OriginLab Technical Service

Edited by - jasonzhao on 11/03/2015 05:25:17 AM
Go to Top of Page

hofmaale

20 Posts

Posted - 11/03/2015 :  06:21:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

kubra: Copying the worksheet would be possible, also of course importing only the relevant portion, although in this case I guess quite a bit of work (templates, formulas, averaging etc. is done automatically by my script).

jasonzhao: This seems to work! Thanks. with
wks.DeleteRange(numRows-1-toRemove, 0, numRows-1, numRows-1);
wks.LT_execute("wks.nRows=wks.maxRows;");

the result seems to be what I was looking for.

Thank you all for your support!
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