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
 LabTalk Forum
 multiple EXCEL --> ASCII
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

doncev

Germany
10 Posts

Posted - 07/18/2006 :  04:56:52 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7G SR2
Operating System:WinXP

Hello,
I would like to import several Excel datasheets (just one particular let say one named with "data") and export them into ASCII worksheets with the same names. Any idea how to do this?
Thanks.
Jelena

Mike Buess

USA
3037 Posts

Posted - 07/18/2006 :  08:58:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jelena,

Not sure what you mean by ASCII worksheet. You can export to a simple text file (.txt) use File > Export ASCII. (But you can do that directly from Excel with File > Save As, then select a text format.) If you want to save as an Origin worksheet file (.ogw) use File > Save Window As.

...You can also use LabTalk's save command...

save -w wksname filename; // save wksname as an ASCII file
save -i filename.ogw; // save active window as an OGW file

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/18/2006 09:12:09 AM
Go to Top of Page

doncev

Germany
10 Posts

Posted - 07/18/2006 :  09:07:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I know how to do it if I have a single files but as I have hunderds of files I would like to do it automaticaly. Any idea how to do it?
Thanks.
Jelena
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 07/18/2006 :  09:16:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
save -w wksname filename;
- or -
save -wh wksname filename; // see wks.export object for formatting options

...This script opens a multiple file selection dialog and imports/exports the selected Excel files.

fdlog.dlgName$="Select Export folder";
%Z=""; // clear path variable
fdlog.OpenPath(Z); // where to export ASCII files
fdlog.dlgName$="Select Excel files";
fdlog.UseGroup(Excel);
// select Excel files
if (fdlog.MultiOpen() != 0/0)
{
loop (ii, 1, fdlog.MultiOpen.Count)
{
FDlog.Get(A, ii); // get iith file name
doc -a %A; // import file
save -w %H %Z%H.txt; // export as ASCII
}
}

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/18/2006 10:42:24 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 07/18/2006 :  1:45:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jelena,

doc -a names the Origin worksheet after the Excel datasheet which is not necessarily the same as the xls filename so worksheet name conflicts might arise with the last script. Also, the script does not handle multiple datasheets and opens a prompt for each xls file. The following scrpt takes care of all of those problems. Note: naming conflicts are avoided by closing worksheets after their data are exported so the project will be empty on completion.

fdlog.dlgName$="Select Output Folder";
if( fdlog.OpenPath(Z) ) return;
fdlog.dlgName$="Select Excel Files";
fdlog.UseGroup(Excel);
if (fdlog.MultiOpen() == 0/0) return;
doc -e W {win -cd %H}; // close all worksheets
OpenAsExcel = system.excel.openAsExcel;
OpenAsPrompt = system.excel.openAsPrompt;
system.excel.openAsExcel = 0; // always import as Origin worksheet
system.excel.openAsPrompt = 0; // disable prompt
loop (ii, 1, fdlog.MultiOpen.Count)
{
FDlog.get(N, ii, 1); // %N=file name sans extension
FDlog.get(A, ii); // %A=file path\name
doc -a %A; // import Excel file
doc -e W {
save -w %H %Z%N_%H.txt; // save as ASCII
win -cd %H; // close wks
}
}
system.excel.openAsExcel = OpenAsExcel;
system.excel.openAsPrompt = OpenAsPrompt;
del -v OpenAs*;

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/18/2006 2:04:12 PM
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