T O P I C R E V I E W |
Corsa88 |
Posted - 08/15/2016 : 09:36:12 AM 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 |
7 L A T E S T R E P L I E S (Newest First) |
Corsa88 |
Posted - 08/23/2016 : 11:16:15 AM 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! |
BettyLewellen |
Posted - 08/20/2016 : 06:58:39 AM 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> |
Shirley_GZ |
Posted - 08/18/2016 : 04:09:44 AM 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 |
Corsa88 |
Posted - 08/17/2016 : 04:06:39 AM 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 |
Shirley_GZ |
Posted - 08/17/2016 : 03:58:51 AM 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 |
Corsa88 |
Posted - 08/16/2016 : 06:07:02 AM 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 |
Shirley_GZ |
Posted - 08/16/2016 : 05:55:42 AM 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 |
|
|