Importing data in Excel using an ActiveX connection

5 visualizaciones (últimos 30 días)
Poul Reitzel
Poul Reitzel el 21 de Oct. de 2011
Greetings. I am having difficulties running an automated script that makes an Excel worksheet import data from an external source (a .dat file) using an activex connection from Matlab. Assuming Excel is my activex object, the following should (I think) make Excel import the designated file in cell A1:
% UI: Name the .xlsx file to write to
[xlfile, xlpath] = uiputfile('*.xlsx', 'Save Workspace as'); Inputsheet=1;
if isequal(xlfile,0) || isequal(xlpath,0)
disp('User pressed cancel')
else
disp(['User selected ', fullfile(xlpath, xlfile)])
end
filename = [xlpath xlfile]; % file directory
% Write a number to the file to make it physical
xlswrite(filename,1)
% Retrieve sheet names
[~, sheetNames] = xlsfinfo(filename);
% Open Excel as a COM Automation server
Excel = actxserver('Excel.Application');
% Open Excel Workbook
Workbook = Excel.Workbooks.Open(filename);
% Clear the content of the desired output sheet
cellfun(@(x) Excel.ActiveWorkBook.Sheets.Item(x).Cells.Clear, sheetNames(Inputsheet));
% Get a handle to the active sheet
Activesheet = Excel.Activesheet;
Excel.Activesheet.Connection.Add(Excel.Activesheet.get('Range', 'A1'), 'TEXT','C:\Users\isc.ISC1\Desktop\Matlab Programs\GTstrudl Output Postprocessing\WD-ULS-PUNCHING-JACKET-WEAK-LRFD.DAT')
% END
but the code gives me the error message:
Excel.ActiveSheet.Connection.Add(Excel.Activesheet.get('Range', 'A1'), 'TEXT','C:\Users\isc.ISC1\Desktop\Matlab Programs\GTstrudl Output Postprocessing\WD-ULS-PUNCHING-JACKET-WEAK-LRFD.DAT')
No appropriate method, property, or field Activesheet for class handle.handle.
Any help from knowledgeable souls is very welcome.
Thanks in advance, Poul Reitzel

Respuestas (1)

Image Analyst
Image Analyst el 21 de Oct. de 2011
Wouldn't it be Workbook.ActiveSheet? Just guessing - haven't tried - but try it and see.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by