Load txt data into Excel with QueryTables.Add
조회 수: 3 (최근 30일)
이전 댓글 표시
I try to load data from a txt file into Excel via Matlab code. I try to call the Excel text file import wizard from Matlab using COM objects. The following code runs without any errors, but the data is not importet to Excel. Does anybody has an idea where I made the mistake?
Matlab-Code:
% Get handle to Excel COM Server
Excel = actxserver('Excel.Application');
% Set Excel to invisible
set(Excel,'Visible',0);
% Open a Workbook
WB=Excel.Workbooks.Open('C:\xlsfile.xls');
% select Worksheet
WS = WB.Worksheets;
Sheet = get(WS,'item',1);
Sheet.Activate;
% Select range in Worksheet
Rng = get(Sheet,'Range','$A$1');
% Import txt file into xls file
Connection = ['TEXT;' 'C:\textfile.txt'];
QT = Sheet.QueryTables.Add(Connection,Rng);
QT.Name = 'C:\textfile.txt';
% Save Workbook
WB.Save();
% Quit Excel
Excel.Quit();
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!