필터 지우기
필터 지우기

How to check the version of Excel through Matlab?

조회 수: 8 (최근 30일)
Eduardo Gaona Peña
Eduardo Gaona Peña 2017년 11월 15일
답변: Image Analyst 2017년 11월 15일
Currently I'm using activeX to plot some charts and write some data on excel, however, when I try my code in a different computer the VBA method that I used to create the charts doesn't work. In my personal laptop I use the following line:
Chart=h.ActiveSheet.Shapes.AddChart2;
But when I used the computer at my office it only works with:
Chart=h.ActiveSheet.Shapes.AddChart;
I would like to generalize my code so it can detect which version of Excel is being used or just to make a check before calling the method, so that it doesn't show an error on the code.
Thanks in advance.
  댓글 수: 1
Eduardo Gaona Peña
Eduardo Gaona Peña 2017년 11월 15일
Would you recommend me to use a simple Try/Catch block?

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2017년 11월 15일
ExcelApp=actxserver('excel.application');
str2double(get(ExcelApp,'Version'))

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 11월 15일
Use Excel.Version. See this snippet:
try
% See if there is an existing instance of Excel running.
% If Excel is NOT running, this will throw an error and send us to the catch block below.
Excel = actxGetRunningServer('Excel.Application');
% If there was no error, then we were able to connect to it.
catch
% No instance of Excel is currently running. Create a new one.
% Normally you'll get here (because Excel is not usually running when you run this).
Excel = actxserver('Excel.Application');
end
% Prepare proper filename extension.
% Get the Excel version because if it's version 11 (Excel 2003) the file extension should be .xls,
% but if later than version 12.0 (Excel 2007) then we'll need to use an extension of .xlsx to avoid nag messages.
excelVersion = str2double(Excel.Version);
if excelVersion < 12
excelExtension = '.xls';
else
excelExtension = '.xlsx';
end

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by