Page 1 of 1

SciLab import excel question

Posted: Mon Nov 06, 2017 3:12 am
by NanoSci
This is not related to nuclear, but I have been trying to access and use an excel file in scilab and I am having all sorts of problems. Is anyone here familiar enough to help me? Please!

Re: SciLab import excel question

Posted: Mon Nov 06, 2017 5:17 pm
by NumCruncher
NanoSci wrote: Mon Nov 06, 2017 3:12 am This is not related to nuclear, but I have been trying to access and use an excel file in scilab and I am having all sorts of problems. Is anyone here familiar enough to help me? Please!
Can you provide some detail as to what sorts of problems you are having? Is there an error message? something specific you don't know how to do? I think I am familiar enough to help, but I need to know what help you need :shock:

BTW, accessing an excel file is pretty easy using the readxls function in Scilab. You may also use xl_open and xl_read.

Anyway, give me something to work with and I will try to help.

Re: SciLab import excel question

Posted: Mon Nov 06, 2017 6:28 pm
by NanoSci
Thanks. I am a novice at this. I apologize if I did not provide enough detail. And, I've tried to read the on-line help, before posting here.

So, the documentation says to use

[fd,SST,Sheetnames,Sheetpos] = xls_open('SCI/modules/spreadsheet/demos/xls/Test1.xls')

to open the file In my case, my file is Annual_Variations.xlsx. I tried

[fd,SST,Sheetnames,Sheetpos] = xls_open('C:/Sim/DataCollections/xlsx/Annual_Variations.xlsx')

and it does not work. What am I doing wrong?

Re: SciLab import excel question

Posted: Mon Nov 06, 2017 6:49 pm
by NumCruncher
I'm pretty sure that XLSX files are not supported. Only xls files. That may be your problem. What is the error message you are getting, anyway?

Re: SciLab import excel question

Posted: Tue Nov 07, 2017 5:12 pm
by NanoSci
NumCruncher wrote: Mon Nov 06, 2017 6:49 pm I'm pretty sure that XLSX files are not supported. Only xls files. That may be your problem. What is the error message you are getting, anyway?
Thank you. I saved the file as XLS and that seems to have fixed it. Any idea why xlsx are not supported?

Also, I know there is documentation on line, but I am trying to read it and not all makes sense to me. I am trying to read in the excel file (primarily values), view the results on the console (it actually has 2 sheets) and then graph the results in sheet(1) and sheet(2).

Any shortcuts or anything you can suggest?

Re: SciLab import excel question

Posted: Wed Nov 08, 2017 8:03 pm
by NumCruncher
Well, as always, the devil is in the details, but here is a sample of how you could do this...


sheets = readxls('C:\excel_graph01.xls') // This should point to a valid file
s1=sheets(1) // Get Sheet(1)
disp(s1.value(),"Values in Sheet(1)") // Display the values in Sheet 1
disp(s1.text(),"Strings in Sheet(1)") // Display text in Sheet 1
s2=sheets(2) // Get Sheet(2)
disp(s2.value(),"Values in Sheet(2)") // Display the values in Sheet 2
disp(s2.text(),"Strings in Sheet(2)") // Display text in Sheet 2
// For the purposes of this example, let's propose that column A in sheet(1) and column C in Sheet(2) contain the
// numeric values you want to plot. We'll use two temp arrays to store the values.
ValSheet1=s1.value
plot(ValSheet1(:,1))
// or, to plot the sheet(2) values
// ValSheet2=s2.value
// plot(ValSheet2(:,3))

You can get a lot more specific and imaginative, but this should meet your basic requirement to view and plot the data.

Re: SciLab import excel question

Posted: Thu Nov 09, 2017 4:04 pm
by NanoSci
Thanks. I can't claim that I understand everything you are doing in this code, but I will look at it closely and try to understand. I did try it as is (with a small excel file and it worked).

Thank you again.