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
 Importing multiple ASCII files with Origin C

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
lauransl Posted - 01/09/2013 : 10:19:27 AM
Hi,
I am trying to open different .dat files from the same folder with origin c by:

ASCIMP ai;
string strFile = GetOpenBox("*.* All Files"); // or "*.txt"
if(strFile.IsEmpty())
return;// user cancel

but it only lets me open one .dat file each time. How can I do to open all the .dat files from the folder?

Thanks a lot!

Laura
6   L A T E S T    R E P L I E S    (Newest First)
Thomas83 Posted - 05/24/2013 : 03:02:09 AM

I would like to have all imported files in only one worksheet!
Thomas83 Posted - 05/24/2013 : 02:50:45 AM
Hi greg.
I have a very similar problem. My code is very close to luaranslīs except that I defined a stringarray to choose the filetype additionally. I want to import multiple files. Ok, I cannot use GetOpenBox. But what do you mean with "You just need to hook that code to yours ..."? What does the final code look like? Here is my code:
void Part_Imp()
{
Worksheet wks = Project.ActiveLayer();

ASCIMP ai;
StringArray saFileTypes;
saFileTypes.SetSize (2);
saFileTypes[0]="*.txt";
saFileTypes[1]="*.dat";
string strFile = GetOpenBox(saFileTypes, GetAppPath());
if(!strFile.IsFile())
{
strFile = GetOpenBox(saFileTypes, GetAppPath());
if(strFile.IsEmpty())
return;
}
if(AscImpReadFileStruct(strFile, &ai)==0)

{
ai.iMode = ASCIMP_MODE_APPEND_COLS;
ai.iRenameCols = 0;
ai.iPartial = 1;
ai.iPartialC1 =
ai.iPartialC2 =
ai.iPartialR1 = 0;
ai.iPartialR2 = 9;
ai.iDelimited = 1;
ai.iDelimiter = ASCIMP_DELIM_DEMICOLON;
ai.nNumSep = NF_IS_EUROPEAN;
int nRet = wks.ImportASCII(strFile, ai);
out_int("nRet = ", nRet);
if(0 == nRet)
wks.AutoSize();
}
else
out_str("failed to read ascii file");

Thanks a lot in advance.
Regards
greg Posted - 01/10/2013 : 12:46:07 PM
You can't use GetOpenBox for multiple files.

My code showed how to do these two things:
Prompt for multiple files
Handle each file separately

You just need to hook that code to yours by replacing my

printf("%s\n", strNames.GetToken(idx,'\x0D'));

with

string strFileName = strNames.GetToken(idx,'\x0D');
strFileName.TrimLeft();
Datasheet_ImportASCII_Ex2(strFileName);

and modifying your code to accept a string argument:

void Datasheet_ImportASCII_Ex2(string strFile)

and commenting out your GetOpenBox

//string strFile = GetOpenBox("*.* All Files"); // or "*.txt"
lauransl Posted - 01/10/2013 : 09:40:36 AM
What I have done is what is shown below, but it only allows me to open one file each time. What I would like to use is GetMultiOpenBox to open all my data files at once in different workbooks. But as GetMultiOpenBox doesn't behave as a string... I don't know how to use it.
Thanks!
Laura


void Datasheet_ImportASCII_Ex2()
{

ASCIMP ai;
string strFile = GetOpenBox("*.* All Files"); // or "*.txt"
if(strFile.IsEmpty())
return;// user cancel


if(AscImpReadFileStruct(strFile, &ai)==0)
{

ai.iPartial = 1; // 1 to specify partial import
ai.iPartialC1 = 0; // import from 2nd column (0 offset)
ai.iPartialC2 = 7; // set the last column, so here just import 4 columns
ai.iPartialR1 = 130; // set the import row from
ai.iPartialR2 = 2000; // set the import row to

ai.iMaxLabels = 0; // Not set any header line to Comments label

ai.nNumSep = NF_IS_AMERICAN;

ai.iMode = 0; // import as New Wks(0), New Columns (1), New Rows (2)

Worksheet wks;
wks.Create();
if(0 == wks.ImportASCII(strFile, ai))
{
// Set user parameter labels to specified names
Grid grid;
grid.Attach(wks);
vector<string> vsUserLabels = {"Expanded Discription", "Type Indication"};
grid.SetUserDefinedLabelNames(vsUserLabels);


}
}
else
out_str("failed to read ascii file");



}
lauransl Posted - 01/10/2013 : 04:26:10 AM
Thanks Greg, but what I really need is something that allows me to open multiple files each in a new worksheet. I don't know what command to use.
Thanks for your help!
Laura
greg Posted - 01/09/2013 : 12:51:21 PM
GetOpenBox is for single files. Provided you have 8.1 or later, you could use something like this to handle multiple files:

void multiple_files()
{
#include <XFbase.h>

string strXFdlg = "dlgfile";
XFBase xf(strXFdlg);
if( !xf.IsValid() )
printf("Failed to attach to XFunction\n");
else
{
// Setup
string strNames, strGroup, strTitle, strInit;
int iMulti;
// Or use FDLOG Group names - like ASCII, Image
strGroup = "*.*";
strTitle = "My Import Dialog"; // Your own title
strInit = "D:\\Temp\\"; // Path to open in
iMulti = 1; // Use 0 for just one file

xf.SetArg("fname", strNames);
xf.SetArg("group", strGroup);
xf.SetArg("title", strTitle);
xf.SetArg("init", strInit);
xf.SetArg("multi", iMulti);
xf.Run(0);
for( int idx = 0 ; idx < strNames.GetNumTokens('\x0D') ; idx++ )
{
printf("%s\n", strNames.GetToken(idx,'\x0D'));
}
}
}

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