www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/xregImportExcelDataWiz.m
function varargout = xregImportExcelDataWiz(action, varargin) % XREGLOADDATAWIZ import wizard from Excel used in Data Editor % Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. switch lower(action) case 'cardone' [varargout{1:nargout}] = i_createCardOne(varargin{:}); end function layout = i_createCardOne(fh, iFace, localData) if isa(fh, 'xregcontainer') layout = fh; layoutUD = get(layout, 'UserData'); else nextText = uicontrol('Parent', fh,... 'Style', 'text',... 'HorizontalAlignment','center',... 'String', 'Enter your data in Excel and click Next to import ...'); layout = xreggridbaglayout(fh,... 'dimension', [3 1],... 'elements', {[] nextText []},... 'rowsizes', [-1 60 -1],... 'colsizes', -1,... 'border', [30 0 30 0],... 'rowratios',[.5 0 .5]); layoutUD.mergeSweepset = []; layoutUD.figure = fh; layoutUD.nextFcn = @i_cardOneNext; end % Start the excel server layoutUD.excel = xregExcel('start'); % Prepare the data page xregExcel('prepare', layoutUD.excel) if nargin > 2 layoutUD.mergeSweepset = localData.mergeSweepset; end feval(iFace.setNextButton, 'on'); feval(iFace.setFinishButton, 'off'); set(layout, 'UserData', layoutUD); function [nextCardID, localData] = i_cardOneNext(layoutUD, ~) % Only set when sure that this has completed successfully nextCardID = []; localData = []; % Check that Excel is still open try worksheets=layoutUD.excel.dataBook.sheets; found = false; for i=1:double(worksheets.count) if strcmp(char(worksheets.Item(i).Name),'MBC Data') % find MBC Data worksheet sheet = worksheets.Item(i); found = true; break end end if ~found error('Worksheet ''MBC Data'' not found.') end catch % Excel is closed OR ''MBC Data'' worksheet not present waitfor(warndlg('Excel has closed or ''MBC Data'' worksheet not present. No data available for import', 'Excel Import Error', 'modal')); xregExcel('close', layoutUD.excel); return end % Indicate that this might take some time set(layoutUD.figure, 'Pointer', 'watch') % Read from the sheet [names, units, data] = xregExcel('read', layoutUD.excel,sheet); % Reset the pointer set(layoutUD.figure, 'Pointer', 'arrow') % Ensure that excel is closed xregExcel('close', layoutUD.excel); localData.filename = 'Excel Import'; localData.newSweepset = sweepset('Variable', 1:length(names), '', names, '', units, '', data); localData.mergeSweepset = layoutUD.mergeSweepset; nextCardID = @i_createCardTwo; function layout = i_createCardTwo(varargin) % Jump to the 3 final cards of the normal data loading wizard layout = xregLoadDataWiz('editvariables', varargin{:});