Reading an Excel workbook in GUI

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 件のコメント

Adam
Adam 2016 年 12 月 16 日
Well, the error says the file is not in Excel format. I'm not sure what help you expect with that error?
José-Luis
José-Luis 2016 年 12 月 16 日
Does the file even open in Excel?
Karthick Thirumurthy
Karthick Thirumurthy 2016 年 12 月 16 日
Hi. Thanks for the reply,
when i open the file it opens in the excel sheet with read only option. i changed the permission setting and give full control to access the excel sheet still i have the problem.
José-Luis
José-Luis 2016 年 12 月 16 日
Have you tried copying the file to the folder your script resides and getting rid of the path when you call xlsread ?
Karthick Thirumurthy
Karthick Thirumurthy 2016 年 12 月 16 日
Hi Jose-Luis,
I have tried that still its the same!!
Karthick Thirumurthy
Karthick Thirumurthy 2016 年 12 月 17 日
Hi all,
I changed my java code to import the output console into .CSV file, so any one know's what code should i need to use to read a .CSV file in GUI application. As similar what i have used to read for .Xls file in the above post.
I need some help!!
Thanks
Jan
Jan 2016 年 12 月 17 日
What about using csvread instead? Sounds too trivial to post this as an answer...
Karthick Thirumurthy
Karthick Thirumurthy 2016 年 12 月 17 日
Hi Jan Simon,
I have tried That too!! This is the following code and error
if true
[~, txt] = csvread('E:\ts.csv','ts','A9');
Cell_Type = txt{1};
set(handles.text2,'string',Cell_Type);
And the error is
Error using csvread
Too many output arguments.
Error in GUI>pushbutton1_Callback (line 86)
[~, txt] = csvread('ts.csv','ts','A8');
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 corrections in the code that can read the value in A8 when i press the pushbutton
Image Analyst
Image Analyst 2016 年 12 月 17 日
Did you see my answer below???

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 12 月 17 日

0 投票

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 件のコメント

Karthick Thirumurthy
Karthick Thirumurthy 2016 年 12 月 17 日
Hi,
Sorry i dint see the post! I have attached the .csv file that is generated from my java program. Now i need to print the A5,and other rows and column if i press push button.
i need some help, as i am new to this i cant get the right way to proceed.!!! i have attached my .csv file that you have asked
1) as i am not able to access my .xls file in GUI, i changed to .csv, which i can access in GUI but i cant read the parameters in the row/column.As you said my csv has both numbers and Characters
2) I am saving my file in one of my local drive.
3) I will try with xlsx.
Image Analyst
Image Analyst 2016 年 12 月 17 日
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
Karthick Thirumurthy 2016 年 12 月 17 日
Hi, The same excel is read by Matlab GUI if i save in different folder!!!
What you mean by workbook??

サインインしてコメントする。

質問済み:

2016 年 12 月 16 日

コメント済み:

2016 年 12 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by