How to check the version of Excel through Matlab?
    조회 수: 1 (최근 30일)
  
       이전 댓글 표시
    
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.
채택된 답변
  Fangjun Jiang
      
      
 2017년 11월 15일
        ExcelApp=actxserver('excel.application');
str2double(get(ExcelApp,'Version'))
댓글 수: 0
추가 답변 (1개)
  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
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


