function varargout = table(varargin)
% TABLE MATLAB code for table.fig
%      TABLE, by itself, creates a new TABLE or raises the existing
%      singleton*.
%
%      H = TABLE returns the handle to a new TABLE or the handle to
%      the existing singleton*.
%
%      TABLE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TABLE.M with the given input arguments.
%
%      TABLE('Property','Value',...) creates a new TABLE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before table_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to table_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help table

% Last Modified by GUIDE v2.5 21-Oct-2011 14:06:03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @table_OpeningFcn, ...
                   'gui_OutputFcn',  @table_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before table is made visible.
function table_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to table (see VARARGIN)

% Choose default command line output for table
handles.output = hObject;


% Update handles structure
guidata(hObject, handles);

% UIWAIT makes table wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = table_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[handles.datei,handles.pfad]=uigetfile('*.OF','MultiSelect','on');

tableData = get(handles.uitable1,'Data');

[zeilen,spalten] = size(handles.datei) 


for x=1:spalten
tableData{x,1} = handles.datei{1,x};

end
set(handles.uitable1,'data',tableData);


[handles.FileName,handles.PathName] = uiputfile('*.xls');

o = 'Oberflaeche';
m = 'Motor';
b = 'Betriebspunkt';
p = 'Prueflauf';

d = {o,m,b,p};

xlswrite([handles.PathName, handles.FileName], d);
% xlswrite([PathName, FileName], {o,m,b,p}, 'A1');


e=actxserver('excel.application');
eW=e.Workbooks;
eF=eW.Open([handles.PathName, handles.FileName]); % your filename here
eS=eF.ActiveSheet;
eS.Range('A1:D4').EntireColumn.AutoFit; % autofit column A
eS.Range('A1:D4').EntireColumn.Font.Name = 'Times'; % changes font to Times
eF.Save;
eF.Close; % close the file
e.Quit; % close Excel entirely

% handles.file = regexprep(handles.datei,'\.(.)*','');

dateipfad = get(handles.listbox1,'String');
dateipfad{length(dateipfad)+1} = tableData;
display(dateipfad);
set(handles.listbox1,'String',tableData);
set(handles.listbox1,'Value',1);


guidata(hObject, handles);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


e=actxserver('excel.application');
eW=e.Workbooks;
eF=eW.Open([handles.PathName, handles.FileName]); % your filename here
eS=eF.ActiveSheet;
eS.Range('A1:D4').EntireColumn.AutoFit; % autofit column A
eS.Range('A1:D4').EntireColumn.Font.Name = 'Times'; % changes font to Times
eF.Save;
eF.Close; % close the file
e.Quit; % close Excel entirely

guidata(hObject, handles);




% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to uitable1 (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)

OF_daten = get(handles.uitable1,'data');
xlswrite([handles.PathName, handles.FileName],OF_daten,1,'A2');

e=actxserver('excel.application');
eW=e.Workbooks;
eF=eW.Open([handles.PathName, handles.FileName]); % your filename here
eS=eF.ActiveSheet;
eS.Range('A1:D4').EntireColumn.AutoFit; % autofit column A
eS.Range('A1:D4').EntireColumn.Font.Name = 'Times'; % changes font to Times
eF.Save;
eF.Close; % close the file
e.Quit; % close Excel entirely
display(OF_daten)
guidata(hObject, handles);


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
