Is it possible to say in xlsread to import the last workbook in a spreadsheet? I know its possible to define which workbook you want if you know the name of the workbook but if you dont, is there a statement that says to take the last workbook?
MATLAB: Xlsread
xlsread
Related Solutions
You can rename an Excel sheet using the "Name" property of a sheet object. For example the following renames the first sheet of an Excel file:
filename = 'C:\SomeExcelFile.xls';% Open Excel Automation server
Excel = actxserver('Excel.Application');% Make Excel visible
Excel.Visible=1;% Open Excel file
Workbook = Excel.Workbooks.Open(filename);% Get the list of sheets in the workbook
Sheets = Excel.ActiveWorkbook.Sheets;% Rename the first sheet
Sheets.Item(1).Name = 'This is sheet 1';
The following code then saves the Workbook, quits Excel and removes the COM server:
% Save the file
Workbook.Save();% Quit Excel, remove the COM server and delete the related objects
Excel.Quit();Excel.delete();clear Excel;clear Workbook;clear Sheets;
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
The following provides an example of opening an existing Excel file named example.xls and proceeding to write and read with it:
% Specify file name
file = 'D:\Applications\MATLAB701\work\example.xls'; % This must be full path name
% Open Excel Automation server
Excel = actxserver('Excel.Application');Workbooks = Excel.Workbooks;% Make Excel visible
Excel.Visible=1;% Open Excel file
Workbook=Workbooks.Open(file);% Specify sheet number, data, and range to write to
sheetnum=1;data=rand(4); % use a cell array if you want both numeric and text data
range = 'F10:I13';% Make the first sheet active
Sheets = Excel.ActiveWorkBook.Sheets;sheet1 = get(Sheets, 'Item', sheetnum);invoke(sheet1, 'Activate');Activesheet = Excel.Activesheet;% Put MATLAB data into Excel
ActivesheetRange = get(Activesheet,'Range',range);set(ActivesheetRange, 'Value', data);% Here you might manipulate the data in Excel
% Now read the data from the sheet; you could specify a new range here
Range = get(Activesheet,'Range',range);out = Range.value;% Save file
invoke(Workbook,'Save')% Close Excel and clean up
invoke(Excel,'Quit');delete(Excel);clear Excel;
Best Answer