Reading an Excel workbook in GUI
Ältere Kommentare anzeigen
Hi all,
I am trying to develop a GUI application that reads variables and values. Basically that Excel sheet is Console Output of my Java application. My problem is that I'm not able to read the file which is generated by the java code.
I am able to read the same excel sheet if I save it in a different folder with the same name and format.
If i use this code
[~, txt] = xlsread('E:\test.xls','history','A10'); %where (K4) cell is wanted text
Cell_Type = txt{1};
set(handles.text2,'string',Cell_Type);
I am getting the following error
>> GUI
Error using xlsread (line 247)
File E:\test.xls not in Microsoft Excel Format.
Error in GUI>pushbutton1_Callback (line 83)
[~, txt] = xlsread('E:\test.xls','history','A10'); %where (K4) cell is wanted text
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I need some help to solve this.
Thanks!
9 Kommentare
Adam
am 16 Dez. 2016
Well, the error says the file is not in Excel format. I'm not sure what help you expect with that error?
José-Luis
am 16 Dez. 2016
Does the file even open in Excel?
Karthick Thirumurthy
am 16 Dez. 2016
José-Luis
am 16 Dez. 2016
Have you tried copying the file to the folder your script resides and getting rid of the path when you call xlsread ?
Karthick Thirumurthy
am 16 Dez. 2016
Karthick Thirumurthy
am 17 Dez. 2016
Jan
am 17 Dez. 2016
What about using csvread instead? Sounds too trivial to post this as an answer...
Karthick Thirumurthy
am 17 Dez. 2016
Image Analyst
am 17 Dez. 2016
Did you see my answer below???
Antworten (1)
Image Analyst
am 17 Dez. 2016
0 Stimmen
I think you meant export to a csv file rather than import. Yes, you can use csvread() as long as it's all numbers, or importdata() or readtable() if it has headers. If you still would rather have an Excel workbook, then attach the .xls file that your java code made with the paper clip icon.
Maybe you should save it in .xlsx format instead.
What is the folder name that you used when you were able to save it and read it back in properly? I don't really see why the folder name should matter as long as the entire filename is less than 218 characters, which is the maximum file name length that Excel can handle. And of course 'E:\test.xls' is much less than 218.
3 Kommentare
Karthick Thirumurthy
am 17 Dez. 2016
Image Analyst
am 17 Dez. 2016
OK, this is not a csv file that MATLAB can read. It's a horribly complicated mess with a mish mash mixture of numbers and text all over the place. I think we're better off using Excel. Please attach the workbook.
Karthick Thirumurthy
am 17 Dez. 2016
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!