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
 ExportASCII selected

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
mortenhuse Posted - 09/06/2007 : 07:20:08 AM
Origin Version (Select Help-->About Origin): 7,5
Operating System: Windows XP

Hi Origin,

I have a problem with my simple code regarding exporting selected cols from worksheet to ASCII file. I must say that I am a novice in this field...
I get the: "syntax error in decleration" message. I do not understand the syntax (the first 2 parameters at least) of this argument ExportASCII.

This is my code:


#include <Origin.h>

#include <wksheet.h>

PUBLIC int ExportASCII(LPCSTR lpcszFilename, DWORD dwCntrl, char cSeparator = '\t', int nR1 = 0, int nC1 = 0, int nR2 = -1, int nC2 = -1)

void test_export_ascii()

{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
}
}



Please Help me... :)

Regards

Morten
6   L A T E S T    R E P L I E S    (Newest First)
mortenhuse Posted - 09/06/2007 : 6:28:41 PM
Thank you Mike,

Now I have finnished making a small program that will make may day easier.
I must really say that this forum (in this case you Mike) and the possibility to do some (simple) programming for automatisation or more complex calculation in Origin, makes this software a powerful tool and my favourite tool for data processing.

Thank you Mike!

Regards

Morten
Mike Buess Posted - 09/06/2007 : 4:30:53 PM
There are a number of ways to do partial export. The intended approach is shown below. Note the peculiarity (possibly a bug) that the indices of the last row (nR2) and column (nC2) must be increased by one in order to export the desired range.

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
int nC1 = 1;
int nC2 = 3;
int nR1 = 0;
int nR2 = 10;
wks.ExportASCII(strFile, 0, '\t', nR1, nC1, nR2+1, nC2+1);
}
}


An alternative method is to select the desired range with LabTalk's worksheet -s command. (This is equivalent to selecting the range by hand prior to exporting with your original function.) The command takes LabTalk indices so all column and row indices must be increased by one.

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
int nC1 = 1;
int nC2 = 3;
int nR1 = 0;
int nR2 = 10;
string sCmd;
sCmd.Format("work -s %d %d %d %d",nC1+1,nR1+1,nC2+1,nR2+1);
wks.LT_execute(sCmd); // select desired range
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
wks.LT_execute("work -s"); // deselect range
}
}

Mike Buess
Origin WebRing Member
mortenhuse Posted - 09/06/2007 : 2:12:14 PM
Hi Again Mike,

Thanks again for clearing up in my missunderstanding. I see now how the selected argument works. My final goal was to set the range of cols and rows to export, let`s say from nC1=1 to nC2=3 and nR1=0 to nR2=10 for instance. How can that be done in my code??

You ar very helpful. Hope I am not bothering you too much...

Kind regards

Morten
Mike Buess Posted - 09/06/2007 : 09:35:13 AM
Hi Morten,

The WKS_EXPORT_SELECTED argument exports only columns that have been selected with the mouse. For example, columns A and C will be exported below. Are any columns highlighted in your worksheet?



Mike Buess
Origin WebRing Member
mortenhuse Posted - 09/06/2007 : 09:13:56 AM
Hi Mike,

Thank you very much for the quick and good reply. I did the changes you said and the compilation goes fine, but unfortunately the exported ascii file is empty. It works fine with th ALL command but I need the SELECTED command. Have tried to change parameters (start end cols and rows). Could it be something wrong in the two first parameteres LPCSTR or DWORD? I do not understand them...

Regards

Morten
Mike Buess Posted - 09/06/2007 : 09:03:40 AM
Hi Morten,

To get rid of the error message just remove the word PUBLIC from the ExportASCII declaration and add a semicolon at the end of the same line. However, ExportASCII is declared in wksheet.h so there is no need to do so in your function. Also, wksheet.h is included in Origin.h so there is no need to #include it in your function. Just remove both lines and your function will work fine...

#include <Origin.h>

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
}
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/06/2007 09:05:50 AM

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