2012-04-13 3 views
4

나는 matlab에 코드가있다. 프로그램을 실행 한 후에 'example2.xlsx'파일이 생성되었습니다. 이제matlab 자동으로 엑셀 파일을 엑셀 인터페이스를 사용하여 저장

나는 아래의 코드를 가지고 있고 나는 (내가 그것을 대체 할 경우에 저를 묻지 않고 자동으로 저장) 새로운 'example2.xlsx'에서 현재 'example2.xlsx'을 대체하기 위해 MATLAB에 원하는 :

e = actxserver ('Excel.Application'); % # open Activex server 
filename = fullfile(pwd,'example2.xlsx'); % # full path required 
ewb = e.Workbooks.Open(filename); % # open the file 
esh = ewb.ActiveSheet; 


str = num2str(num_rows+1); 
esh.Range(strcat('J',str)).Interior.Color = clr; 

sheet1 = e.Worksheets.get('Item', 'Sheet1'); 
range1 = get(sheet1,'Range', strcat('A',str),strcat('I',str)); 
range1.Value = values{num_rows+1}; 

[num, txt, raw] = xlsread('example2.xlsx'); 
num_rows = length(num(:,1)); 


xlWorkbookDefault = 51; % # it's the Excel constant, not sure how to pass it other way 
ewb.SaveAs(fullfile(pwd,'example2'), xlWorkbookDefault) 
ewb.Close(false) 
e.Quit 
e.delete 

답변

6

Excel 응용 프로그램 개체의 DisplayAlerts 속성을 false로 설정하여 이러한 대화 상자가 나타나지 않도록 할 수 있습니다.

e = actxserver ('Excel.Application'); % # open Activex server 
filename = fullfile(pwd,'example2.xlsx'); % # full path required 
ewb = e.Workbooks.Open(filename); % # open the file 
esh = ewb.ActiveSheet; 

sheet1 = e.Worksheets.get('Item', 'Sheet1'); 
range1 = get(sheet1,'Range', 'A1'); 
range1.Value = 3; 

set(e, 'DisplayAlerts', 0); % # Stop dialog! 

xlWorkbookDefault = 51; % # it's the Excel constant, not sure how to pass it other way 
ewb.SaveAs(fullfile(pwd,'example2'), xlWorkbookDefault) 
ewb.Close(false) 
e.Quit 
e.delete 
+0

알렉스 감사합니다, 그것은 나에게 도움이 :

다음은 코드의 단순화 된 버전입니다! 좋은 하루 되세요, 고마워요! :]] –