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
 Origin Forum
 file name as column label

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
Pythe Posted - 08/03/2004 : 11:24:32 AM
Hi,

Who can help me with the following?
I want to import one column from multiple ASCII files into one worksheet. For this I have defined a filter for the import wizard, but after import I cannot recognize from which file each column is derived from. I would like to either put the filename into the column name or label, or to use a value in the file header (where the filename is also located). I cannot use the options in the wizard, because this info in the header is in the first column, while I only want to import the second column.

I have seen a post with a similar problem ("Importing file name as column label ") in which a script was used. With my (very) limited programming knowledge I tried to adapt the script for my situation. At first it worked fine, but if I import extra data to the worksheet, it doesn't work anymore.

Maybe someone can write me a script for this problem?
7   L A T E S T    R E P L I E S    (Newest First)
Pythe Posted - 08/05/2004 : 03:46:29 AM
Hi easwar,

The new code works like a charm! Thanks a lot!
As what the filename concerns: the filename is short, but with folder names included it is long indeed:

D:\My Documents\Werk\CCP\experiments\04-08-03 fluor C132-OG CN-\OG001.SP

But when I use the drag and drop method (which I find more convenient anyway) it all works fine, now I can import more than 100 files at the same time. Saves a lot of time...

Thanks again!

Pythe
easwar Posted - 08/04/2004 : 2:26:04 PM
Hi,

There is a workaround where you do not have to get any new files from us:

As long as you are okay with importing multiple files ONLY via drag-and-drop method, you can add the following script code to the edit box on the last page of the Import Wizard (replace the previous code) and then the (last) column from each file will get the correct file name assigned to the label:

%a = Doc.DropFileName$;     // Get Path + File Name
// Need to extract just File Name from this string
ilen = %[ %a ]; // get length of string
for( ii = ilen; ii >= 1; ii-- ) // read from right end and find the "\" character
{
%b = %[ %a, ii : ii ];
if( %b == "\" ) break; // if "\" found, exit from loop
};
%b = %[ %a , ii + 1 : ilen ]; // get part of string to right of "\" found
wks.col$( wks.ncols ).label$ = %b; // assign extracted filename to column label
wks.labels(); // turn on display of label




Now, as for the problem where you can import only 13 files, we suspect this is because your path name is very long and this is causing a buffer overflow. Can you verify if your path names are very long? If this is the case, we would need to correct this by increasing the buffer size.

Thanks,

Easwar
OriginLab

easwar Posted - 08/04/2004 : 11:30:38 AM
Hi,

First of all, I want to apologize for not realizing that File->Open creates new windows and not append columns to existing worksheet as you had asked for.

We think that File->Open should continue to behave as it does now - which is to open each file in a new window - even if the filter specifies such. For example, if no active worksheet window exists, File->Open will still need to create a window.

To solve your problem, what we need to do is to fix the import wizard so that the file name is available for user in script for each file. This will then work with drag-and-drop as well.

So we will try to add this change to the import wizard code and provide you with an update so that the proper file names go into the label. We will e-mail this to you separately.

Now, regarding the issue of only 13 files being allowed for File->Open as well as from Import Wizard, we could not reproduce that problem. For example, we duplicated a data file 38 times and used a filter to import them all using File->Open as well as Wizard and all 38 were imported successfully. Please send your Import Filter and one or more of your data files so that we can try reproduce this problem.

Please send them to tech@originlab.com and mention this post in your e-mail.

Easwar
OriginLab

Pythe Posted - 08/04/2004 : 03:32:12 AM
Hi,

I have tried to open them as you said in your last post, but instead of opening the files as one column each in the same worksheet, it opens them in a new worksheet for each file, with two columns: one containing the imported data without a label, one without data and having the filename as column label. (settings in filter contain the "start new columns" as import mode). Furthermore, the maximum of files opened simultaneously seems to be 13 (both in this way as in selecting them in the import wizard. The only way to import, say, 100 files at the same time is to drag and drop. Is this a known problem?
easwar Posted - 08/03/2004 : 2:09:07 PM
Hi,

When importing multiple files, if you do that from the wizard, the code I posted will not work - it just takes the last file's name for each and uses that - which is what you found out. There does not appear to be a solution to that.

However, you can do the following:
When saving the import filter created using the Wizard, save it to the User Files area. If you do that, then instead of using the Wizard to import the files, you can go to the File->Open menu item and open the files from there. You will see that the filter you saved will appear in the "Files of Type" drop-down list on the File->Open dialog. You can then select that filter, and further select multiple files to be "opened". If you follow this route, the correct file name will be assigned to the (last) column for each file.

Easwar
OriginLab

Pythe Posted - 08/03/2004 : 12:58:12 PM
Hi easwar,

This is the kind of solution I'm looking for. However, when I use the script in the filter and import multiple files, each column gets the same name, possibly of the first imported file. Furthermore, if I then add another file to the worksheet, this column also gets this same name. Am I doing something wrong?
easwar Posted - 08/03/2004 : 12:06:46 PM
Hi,

As long as you are adding only one column per file that is imported, here is a solution:

1> Open your filter again in import wizard and navigate to the "Save Filters" page where you specify the name for saving filter etc
2> Check the checkbox named "Specify Advanced Filter Options" once you have specified other things such as filter name and location to store filter
3> Click Next to get to the last page, where there is an edit box. This edit box can contain LabTalk script code, that then gets executed at the end of each import that uses this saved filter.
In the edit box, enter the following two lines, and then click Finish:


wks.col$(wks.ncols).label$=%A; // set label of last column in wks to file name
wks.labels(); // turn on display of label






The above will then set the label of last column to be the file name. If you are adding more than one column per import, then only the last column will have the file name in label. The problem with adding more than one column to existing wks is that there is currently no way in the LabTalk code at the end of the import to know how many columns were added by the import. This is something we will address in the next version. Also, in the next version, we will add capability to directly place file name in all columns that get added by the import, without having to do this via script code in the filter.

Easwar
OriginLab



Edited by - easwar on 08/03/2004 12:10:06 PM

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