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
 Origin Forum
 Import multiple .nc files and export into Excel
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Corsa88

7 Posts

Posted - 08/15/2016 :  09:36:12 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi all

I have multiple .nc files that i need to extract and store into Excel. I have tried the following function:

string fns, path$="C:\netCDF\";
findfiles fname:=fns$ ext:="*.nc";
impNetCDF fname:=fns$; //Import all netCDF files in folder C:\netCDF
//Export each worksheet in current project as CSV files
doc -e LB
{
expASC type:=csv path:="C:\CSV\[%H]%(page.active$).CSV";
}


Upon execution, Originpro gives me an error, saying:

Attention!
Please select a worksheet


However, I am unable to select any worksheet by clicking, unless I click OK, where the error message disappears.
When I check the output folder, only the last .nc is extracted into excel.

Anyone has any ideas what is going wrong? Appreciate your advice!

Also, how could I edit the script, such that the output file retains the filename of the input .nc file?

Have a pleasant day!

Regards
Ben

Edited by - Corsa88 on 08/15/2016 09:41:58 AM

Shirley_GZ

China
Posts

Posted - 08/16/2016 :  05:55:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The X-Function "expASC" is only used to export current worksheet as a CVS file. For matrix sheet, you need use X-Function "expMatASC".


So when the active page is a matrix, the attention will appear. You can try the script below to export the worksheets separately:

string fns, path$="C:\netCDF\";
findfiles fname:=fns$ ext:="*.nc";
impNetCDF fname:=fns$; //Import all netCDF files in folder C:\netCDF
//Export each worksheet in current project as CSV files
doc -e w
{
doc -e Lw
{
expASC type:=csv path:="C:\CSV\[%H]%(page.active$).CSV"; 
}
}

Thanks,
Shirley
OriginLab

Originlab Technical Service Team
Go to Top of Page

Corsa88

7 Posts

Posted - 08/16/2016 :  06:07:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shirley

Thanks for your clarification. I note that in the revised script, expASC was still being used. Do I change this to expMatASC as you have suggested?

Regards
Ben
Go to Top of Page

Shirley_GZ

China
Posts

Posted - 08/17/2016 :  03:58:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It depends on which object you want to export, worksheet or matrix sheet.

If you want to export matrix sheets too, you can write another similar loop to export them, such as

doc -e M
{
doc -e Lw
{
expMatASC type:=csv path:="C:\CSV\[%H]%(page.active$).CSV"; 
}
}


Thanks,
Shirley

Originlab Technical Service Team
Go to Top of Page

Corsa88

7 Posts

Posted - 08/17/2016 :  04:06:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shirley

Oh I see, thanks for the clarification.

One final question, is there a way to name the output CSV files using the file names of the input files?

Regards
Ben
Go to Top of Page

Shirley_GZ

China
Posts

Posted - 08/18/2016 :  04:09:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, you can try the script below:

doc -e w
{
doc -e Lw
{
str$ = page.longname$;  //get the long name(path+file name) of workbook
int nn = str.GetNumTokens('\');
sname$ = Token(str$, nn, '\')$; //get the file name
if(nn==0)
sname$=%H;  //If there is no long name in current workbook, use short name instead
expASC type:=csv path:="C:\CSV\[%(sname$)]%(page.active$).CSV"; 
}
}


to export the worksheets with the file names.

Thanks,
Shirley


Originlab Technical Service Team

Edited by - Shirley_GZ on 08/18/2016 04:23:28 AM
Go to Top of Page

BettyLewellen

1 Posts

Posted - 08/20/2016 :  06:58:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Just make a list of the file names and put it in a txt file let's say names.txt.
Then open the file with fopen matlab command.
Then use the command fgetl to read sequentially the filenames. Put fgetl command in a for end statement long as the number of files u have to open.
For each iteration read the netcdf file with filename contained in the variable u choose and created with fgetl.

<u>Betty_Lewellen</u>
Go to Top of Page

Corsa88

7 Posts

Posted - 08/23/2016 :  11:16:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Shirley_GZ

Yes, you can try the script below:

doc -e w
{
doc -e Lw
{
str$ = page.longname$;  //get the long name(path+file name) of workbook
int nn = str.GetNumTokens('\');
sname$ = Token(str$, nn, '\')$; //get the file name
if(nn==0)
sname$=%H;  //If there is no long name in current workbook, use short name instead
expASC type:=csv path:="C:\CSV\[%(sname$)]%(page.active$).CSV"; 
}
}


to export the worksheets with the file names.

Thanks,
Shirley


Originlab Technical Service Team



Thank you Shirley, I am happy to report that the code works well!
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