赞
踩
查询条件:订单编号
输出内容:客户姓名、金额
输入内容:订单编号、客户姓名、金额
按钮内容:确定、重置、返回
输出内容:订单总额、大写金额(元)、订单交易数(个)
按钮内容:查询、重置、返回
2.1.1 模块Module
函数:
% --- 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) global num txt [num,txt] = xlsread('YH.xlsx'); numy = get(handles.edit1,'string'); num2 = {numy}; namey = get(handles.edit2,'string'); name2 = {namey}; money = get(handles.edit3,'string'); % money2 = {money}; money2 = str2num(money); len = size(txt,1)+1; range = num2str(len); if isempty(numy)==1 msgbox('订单编号为空,请重新输入'); end if isempty(namey)==1 msgbox('客户姓名为空,请重新输入'); end if isempty(money)==1 msgbox('金额为空,请重新输入'); end if isempty(numy)==0 && isempty(namey)==0 && isempty(money2)==0 xlswrite('YH.xlsx',num2,'sheet1',['B',range]); xlswrite('YH.xlsx',name2,'sheet1',['A',range]); xlswrite('YH.xlsx',money2,'sheet1',['C',range]); msgbox('插入成功'); end
完整代码(冗长可略过):
function varargout = Test(varargin) % TEST MATLAB code for Test.fig % TEST, by itself, creates a new TEST or raises the existing % singleton*. % % H = TEST returns the handle to a new TEST or the handle to % the existing singleton*. % % TEST('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TEST.M with the given input arguments. % % TEST('Property','Value',...) creates a new TEST or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Test_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Test_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 Test % Last Modified by GUIDE v2.5 22-Nov-2019 11:25:59 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Test_OpeningFcn, ... 'gui_OutputFcn', @Test_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 Test is made visible. function Test_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 Test (see VARARGIN) % Choose default command line output for Test handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes Test wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Test_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; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit 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 function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit 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 % --- 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) global num txt [num,txt] = xlsread('YH.xlsx'); numy = get(handles.edit1,'string'); num2 = {numy}; namey = get(handles.edit2,'string'); name2 = {namey}; money = get(handles.edit3,'string'); % money2 = {money}; money2 = str2num(money); len = size(txt,1)+1; range = num2str(len); if isempty(numy)==1 msgbox('订单编号为空,请重新输入'); end if isempty(namey)==1 msgbox('客户姓名为空,请重新输入'); end if isempty(money)==1 msgbox('金额为空,请重新输入'); end if isempty(numy)==0 && isempty(namey)==0 && isempty(money2)==0 xlswrite('YH.xlsx',num2,'sheet1',['B',range]); xlswrite('YH.xlsx',name2,'sheet1',['A',range]); xlswrite('YH.xlsx',money2,'sheet1',['C',range]); msgbox('插入成功'); end % --- 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) a1 = get(handles.edit1,'string'); set(handles.edit2,'string',strcat('def',a1)); function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double % --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit 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 % -------------------------------------------------------------------- function file_Callback(hObject, eventdata, handles) % hObject handle to file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function edit_Callback(hObject, eventdata, handles) % hObject handle to edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function tools_Callback(hObject, eventdata, handles) % hObject handle to tools (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function help_Callback(hObject, eventdata, handles) % hObject handle to help (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function new_Callback(hObject, eventdata, handles) % hObject handle to new (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function open_Callback(hObject, eventdata, handles) % hObject handle to open (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function save_Callback(hObject, eventdata, handles) % hObject handle to save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_8_Callback(hObject, eventdata, handles) % hObject handle to Untitled_8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function close_Callback(hObject, eventdata, handles) % hObject handle to close (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。