If the structure of your data files is not too complicated then the following Origin C approach will work. It imports to a temporary worksheet and copies the second column to the final worksheet. I use the file name for column name since I don't know details, but should be easy to extract the column name. It starts out with a folder selection dialog and imports all files in that folder with .dat extension. Change the extension in the FindFiles() function if necessary.static string strImportPath;
void import_from_folder()
{
if( strImportPath.IsEmpty() )
strImportPath = GetAppPath();
strImportPath = BrowseGetPath(strImportPath); // folder selection dialog
if( strImportPath.IsEmpty() )
return;
string sFldName = strImportPath.GetToken(strImportPath.GetNumTokens('\\')-2,'\\'); // folder name
WorksheetPage wp;
wp.Create("Origin.otw");
wp.Rename(sFldName);
Worksheet wFin(sFldName); // Final wks
Worksheet wTmp; // Import wks (temporary)
wTmp.Create("Origin.otw", CREATE_TEMP);
Dataset ds1, ds2;
string sCol;
int j;
StringArray sa;
FindFiles(sa, strImportPath, "dat"); // list all files with .dat (??) extension
for(int i=0; i<sa.GetSize(); i++)
{
if( import_one_file(wTmp, strImportPath, sa[i]) )
{
if( j )
wFin.AddCol();
else
{
ds1.Attach(wTmp,0);
ds2.Attach(wFin,0);
ds2 = ds1;
}
j++;
ds1.Attach(wTmp,1);
ds2.Attach(wFin,j);
ds2 = ds1;
sCol = GetFileName(strImportPath + sa[i], true); // strip extension
wFin.Columns(j).SetName(sCol);
}
}
}
bool import_one_file(Worksheet wks, string sPath, string sName)
{
bool bReturn;
ASCIMP ascimp;
if( AscImpReadFileStruct(sPath + sName, &ascimp)==0 )
{
if( wks.ImportASCII(sName, ascimp)==0 )
bReturn = true;
}
return bReturn;
}
Mike Buess
Origin WebRing Member
Edited by - Mike Buess on 02/20/2005 10:46:15 AM